Przeglądaj źródła

Create Bill class.

Lee Morgan 11 miesięcy temu
rodzic
commit
b1abd44464
2 zmienionych plików z 17 dodań i 5 usunięć
  1. 2 5
      src/views/js/data/Account.js
  2. 15 0
      src/views/js/data/Bill.js

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

@@ -3,6 +3,7 @@ import Notifier from "../Notifier.js";
 import Format from "../Format.js";
 import Transaction from "./Transaction.js";
 import Income from "./Income.js";
+import Bill from "./Bill.js";
 
 export default class Account{
     constructor(id, iv, data){
@@ -71,11 +72,7 @@ export default class Account{
     }
 
     async addBill(name, amount){
-        this._bills.push({
-            id: crypto.randomUUID(),
-            name: name,
-            amount: this.toCents(amount)
-        });
+        this._bills.push(Bill.create(name, this.toCents(amount)));
 
         await this.save();
     }

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

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