From a180215dd0f87963fc219c87e0bfafd3561665c2 Mon Sep 17 00:00:00 2001 From: Spythere Date: Thu, 30 May 2024 16:08:44 +0200 Subject: [PATCH] chore: order compatibility warnings --- src/mixins/orderStorageMixin.ts | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/mixins/orderStorageMixin.ts b/src/mixins/orderStorageMixin.ts index a956bb8..82386fe 100644 --- a/src/mixins/orderStorageMixin.ts +++ b/src/mixins/orderStorageMixin.ts @@ -2,6 +2,11 @@ import { defineComponent } from 'vue'; import { useStore } from '../store/store'; import { LocalStorageOrder } from '../types/orderTypes'; +function alertWrongOrderFormat() { + alert('Wystąpił błąd podczas przetwarzania rozkazu! Informacje mogą być niepoprawne!'); + console.warn('Zły format zapisanego rozkazu!'); +} + export default defineComponent({ setup() { return { @@ -98,17 +103,24 @@ export default defineComponent({ const currentOrder = this.store[localOrder.orderType]; if (localOrderBody.rows.length != currentOrder.rows.length) { - alert( - 'Zły format rozkazu! Może pochodzić z przestarzałej wersji lub został źle zapisany.' - ); - console.warn('Zły format zapisanego rozkazu!'); + alertWrongOrderFormat(); return; } for (let rowIndex = 0; rowIndex < currentOrder.rows.length; rowIndex++) { const row = currentOrder.rows[rowIndex]; + if (localOrderBody.rows[rowIndex] === undefined) { + alertWrongOrderFormat(); + continue; + } + for (const rowProp in row) { + if (localOrderBody.rows[rowIndex][rowProp] === undefined) { + alertWrongOrderFormat(); + continue; + } + (currentOrder.rows[rowIndex] as any)[rowProp] = localOrderBody.rows[rowIndex][rowProp]; } } @@ -120,7 +132,17 @@ export default defineComponent({ for (let rowIndex = 0; rowIndex < currentOrder.orderList.length; rowIndex++) { const row = currentOrder.orderList[rowIndex]; + if (localOrderBody.orderList[rowIndex] === undefined) { + alertWrongOrderFormat(); + continue; + } + for (const rowProp in row) { + if (localOrderBody.orderList[rowIndex][rowProp] === undefined) { + alertWrongOrderFormat(); + continue; + } + (currentOrder.orderList[rowIndex] as any)[rowProp] = localOrderBody.orderList[rowIndex][rowProp]; } @@ -133,6 +155,8 @@ export default defineComponent({ (this.store.orderFooter as any)[key] = localOrderFooter[key]; } + console.log('loading'); + this.store.chosenOrderType = localOrder.orderType; this.store.chosenLocalOrderId = localOrder.id; this.store.orderMode = 'OrderMessage';