-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathwriter.js
More file actions
38 lines (32 loc) · 922 Bytes
/
writer.js
File metadata and controls
38 lines (32 loc) · 922 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
'use strict';
const { Bank } = require('./bank.js');
class AccountCommand {
constructor(account, operation, amount = 0) {
this.operation = operation;
this.account = account;
this.amount = amount;
}
}
class BankWrite {
constructor(eventBus) {
this.bank = new Bank();
this.commands = [];
this.eventBus = eventBus;
}
createAccount(account) {
const operation = 'create';
const command = new AccountCommand(account, operation);
this.commands.push(command);
this.eventBus.emit('command', command);
this.bank.execute(command);
}
operation(account, value) {
const operation = value < 0 ? 'withdraw' : 'income';
const amount = Math.abs(value);
const command = new AccountCommand(account, operation, amount);
this.commands.push(command);
this.eventBus.emit('command', command);
this.bank.execute(command);
}
}
module.exports = { BankWrite };