Browse Source

Update data to work with new classes.

Lee Morgan 11 tháng trước cách đây
mục cha
commit
1930a5f1d9

+ 6 - 6
src/views/js/data/Account.js

@@ -12,9 +12,9 @@ export default class Account{
         this._iv = iv;
         this._name = data.name;
         this._balance = data.balance;
-        this._income = data.income;
-        this._bills = data.bills;
-        this._allowances = data.allowances;
+        this._income = data.income.map(Income.fromObject);
+        this._bills = data.bills.map(Bill.fromObject);
+        this._allowances = data.allowances.map(Allowance.fromObject);
         this._transactions = [];
         this._populated = false;
     }
@@ -141,9 +141,9 @@ export default class Account{
         const data = {
             name: this._name,
             balance: this._balance,
-            income: this._income,
-            bills: this._bills,
-            allowances: this._allowances
+            income: this._income.map(i => i.serialize()),
+            bills: this._bills.map(b => b.serialize()),
+            allowances: this._allowances.map(a => a.serialize())
         };
         const encryptedData = await encryptionHandler.encrypt(data, this._iv);
 

+ 18 - 0
src/views/js/data/Allowance.js

@@ -14,4 +14,22 @@ export default class Allowance{
             isPercent
         );
     }
+
+    static fromObject(data){
+        return new Allowance(
+            data.id,
+            data.name,
+            data.amount,
+            data.isPercent
+        );
+    }
+
+    serialize(){
+        return {
+            id: this._id,
+            name: this._name,
+            amount: this._amount,
+            isPercent: this._isPercent
+        };
+    }
 }

+ 16 - 0
src/views/js/data/Bill.js

@@ -12,4 +12,20 @@ export default class Bill{
             amount
         );
     }
+
+    static fromObject(data){
+        return new Bill(
+            data.id,
+            data.name,
+            data.amount
+        );
+    }
+
+    serialize(){
+        return {
+            id: this._id,
+            name: this._name,
+            amount: this._amount
+        };
+    }
 }

+ 16 - 0
src/views/js/data/Income.js

@@ -12,4 +12,20 @@ export default class Income{
             amount
         );
     }
+
+    static fromObject(data){
+        return new Income(
+            data.id,
+            data.name,
+            data.amount
+        );
+    }
+
+    serialize(){
+        return {
+            id: this._id,
+            name: this._name,
+            amount: this._amount
+        };
+    }
 }