Skip to content

Open source personal finance application

fix(trns): normalize transaction data structure in setTrns function

Ilya Komichevf0343557512e
diff --git a/app/components/trns/useTrnsStore.ts b/app/components/trns/useTrnsStore.ts
index 282392ba..463e83ed 100644
--- a/app/components/trns/useTrnsStore.ts
+++ b/app/components/trns/useTrnsStore.ts
@@ -77,8 +77,9 @@ export const useTrnsStore = defineStore('trns', () => {
}
function setTrns(values: Trns | null) {
- items.value = values
- localforage.setItem('finapp.trns', deepUnref(values))
+ const trns = normalizeTrns(values || {})
+ items.value = trns
+ localforage.setItem('finapp.trns', deepUnref(trns))
}
function addTrn({ id, values }: { id: TrnId, values: TrnItem }) {
@@ -234,6 +235,23 @@ export const useTrnsStore = defineStore('trns', () => {
return 'Trn type not found'
}
+ function normalizeTrns(trns: Trns) {
+ const normTrns: Trns = {}
+
+ for (const trnId in trns) {
+ const trn = trns[trnId]!
+ const desc = trn.desc || trn.description || ''
+ delete trn.description
+
+ normTrns[trnId] = {
+ ...trn,
+ desc,
+ }
+ }
+
+ return normTrns
+ }
+
return {
addTrn,
computeTrnItem,