-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathretributionCommission.js
60 lines (50 loc) · 1.87 KB
/
retributionCommission.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const Event = require('./event');
const {
UNVALIDATED_INVOICE,
VALIDATED_INVOICE,
GENERATED_SEPA,
INVOICE_SENT
} = require('./constant');
const invoiceProjection = require('./invoicesProjection');
module.exports = class RetributionCommission {
hasPendingInvoice;
unvalidateInvoice() {
return new Event(UNVALIDATED_INVOICE);
}
generateSepa() {
return new Event(GENERATED_SEPA);
}
static apply(EventsList) {
const decisionProjection = new invoiceProjection();
EventsList.forEach(event => {
decisionProjection.When(event);
});
return decisionProjection;
}
static sendInvoice(sendInvoiceCommand, EventsList) {
const decisionProjection = this.apply(EventsList);
if (decisionProjection.invoiceToValidate) {
throw new Error('Invoice sent error');
}
return [
new Event(INVOICE_SENT, {
invoiceId: sendInvoiceCommand.invoiceId,
amount: sendInvoiceCommand.amount,
})
];
}
static validateInvoice(EventsList) {
const projection = this.apply(EventsList);
return new Event(VALIDATED_INVOICE, {
invoiceId: 123456,
amount: 12,
create
});
}
// créer méthod apply "statique", param list event, retourne objet qui contient la projection des propriétés pour la prise de décision
// --> va contenir haspendinginvoice true / false
// dépile et construis un objet avec les infos pour la prise de décision
// méthodes / command a passé en statique, param list event + param nécessaire à la command
// les méthodes vont appeler apply avec en param les events reçus de l'ext --> va renvoyer un obj qui aide à la prise de décision
// --> la méthode prend la décision, return event / la décision prise
}