-
-
Notifications
You must be signed in to change notification settings - Fork 350
/
Copy pathaccount-repository.js
45 lines (40 loc) · 1.06 KB
/
account-repository.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
class AccountNumber {
constructor(num) {
this.id = num;
}
}
class Account {
constructor(id, version, name, referenceId, accountNumber, created, updated) {
this.id = id;
this.version = version;
this.name = name;
this.referenceId = referenceId;
this.accountNumber = accountNumber;
this.created = created;
this.updated = updated;
}
}
const accounts = [];
const accountRepository = {
save: (account) => {
// This simulates a save to the DB where the IDs get allocated
let id = Math.floor(Math.random() * Math.floor(100000));
let accountNumber = Math.floor(Math.random() * Math.floor(100000));
let version = Math.floor(Math.random() * Math.floor(10));
account.id = id;
account.version = version;
account.accountNumber.id = accountNumber;
accounts.push(account);
return account;
},
findByAccountNumber: async (accountNumber) => {
return accounts.find(
(account) => account.accountNumber.id == accountNumber
);
},
};
module.exports = {
Account,
AccountNumber,
accountRepository,
};