Browse Source

Create the allowance class.

Lee Morgan 11 months ago
parent
commit
32ad9db061
2 changed files with 19 additions and 6 deletions
  1. 2 6
      src/views/js/data/Account.js
  2. 17 0
      src/views/js/data/Allowance.js

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

@@ -4,6 +4,7 @@ import Format from "../Format.js";
 import Transaction from "./Transaction.js";
 import Income from "./Income.js";
 import Bill from "./Bill.js";
+import Allowance from "./Allowance.js";
 
 export default class Account{
     constructor(id, iv, data){
@@ -84,12 +85,7 @@ export default class Account{
             amount = this.toCents(amount);
         }
 
-        this._allowances.push({
-            id: crypto.randomUUID(),
-            name: name,
-            amount: amount,
-            isPercent: isPercent
-        });
+        this._allowances.push(Allowance.create(name, amount, isPercent));
 
         await this.save();
     }

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

@@ -0,0 +1,17 @@
+export default class Allowance{
+    constructor(id, name, amount, isPercent){
+        this._id = id;
+        this._name = name;
+        this._amount = amount;
+        this._isPercent = isPercent;
+    }
+
+    static create(name, amount, isPercent){
+        return new Allowance(
+            crypto.randomUUID(),
+            name,
+            amount,
+            isPercent
+        );
+    }
+}