-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathreader.js
More file actions
44 lines (38 loc) · 1015 Bytes
/
reader.js
File metadata and controls
44 lines (38 loc) · 1015 Bytes
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
'use strict';
const { Bank } = require('./bank.js');
class AccountQuery {
constructor(account, operation) {
this.account = account;
this.operation = operation;
this.rows = 0;
}
}
class BankRead {
constructor(eventBus) {
this.bank = new Bank();
this.commands = [];
this.queries = [];
eventBus.on('command', (command) => {
this.commands.push(command);
this.bank.execute(command);
});
}
select({ account, operation }) {
const query = new AccountQuery(account, operation);
this.queries.push(query);
const result = [];
for (const command of this.commands) {
let condition = true;
if (account) condition = command.account === account;
if (operation) condition = condition && command.operation === operation;
if (condition) result.push(command);
}
query.rows = result.length;
console.dir(query);
return result;
}
getAccount(name) {
return this.bank.find(name);
}
}
module.exports = { BankRead };