@zeeshan60/event-processor 1.0.15 → 1.0.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +29 -22
- package/dist/ActivityEventHandler.d.ts +7 -4
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +24 -13
- package/dist/ActivityLogEvents.d.ts.map +1 -1
- package/dist/ActivityLogEvents.js +1 -0
- package/dist/BaseEventHandler.d.ts +12 -3
- package/dist/BaseEventHandler.d.ts.map +1 -1
- package/dist/BaseEventHandler.js +15 -0
- package/dist/EventProcessorSDK.d.ts +8 -0
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +20 -6
- package/dist/FriendEventHandler.d.ts +8 -3
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +65 -39
- package/dist/GroupEventHandler.d.ts +6 -3
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +254 -189
- package/dist/GroupTransactionEventHandler.d.ts +5 -8
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +26 -298
- package/dist/TransactionEventHandler.d.ts +5 -3
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +26 -13
- package/dist/TransactionEvents.d.ts +10 -9
- package/dist/TransactionEvents.d.ts.map +1 -1
- package/dist/TransactionEvents.js +10 -12
- package/dist/UserEventHandler.d.ts +5 -3
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +27 -14
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.js +3 -0
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.js +10 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts +9 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.js +19 -0
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.js +18 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts +1 -0
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.js +7 -0
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.js +6 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +3 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +27 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +4 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +17 -0
- package/dist/client/controllers/FriendController.d.ts +4 -0
- package/dist/client/controllers/FriendController.d.ts.map +1 -1
- package/dist/client/controllers/FriendController.js +81 -15
- package/dist/client/controllers/TransactionController.d.ts +13 -2
- package/dist/client/controllers/TransactionController.d.ts.map +1 -1
- package/dist/client/controllers/TransactionController.js +150 -16
- package/dist/client/handlers/UIEventHandler.d.ts +3 -0
- package/dist/client/handlers/UIEventHandler.d.ts.map +1 -1
- package/dist/client/handlers/UIEventHandler.js +36 -0
- package/dist/common/CurrencyRate.d.ts +7 -0
- package/dist/common/CurrencyRate.d.ts.map +1 -0
- package/dist/common/CurrencyRate.js +2 -0
- package/dist/common/Model.d.ts +1 -0
- package/dist/common/Model.d.ts.map +1 -1
- package/dist/contracts/friends/index.d.ts +2 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/contracts/groups/index.d.ts +1 -1
- package/dist/contracts/groups/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.d.ts +33 -23
- package/dist/contracts/transactions/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.js +14 -11
- package/dist/converters/ActivityLogConverters.d.ts.map +1 -1
- package/dist/converters/ActivityLogConverters.js +3 -1
- package/dist/events.d.ts +2 -0
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +7 -1
- package/dist/index.d.ts +3 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -5
- package/dist/store/CurrencyStore.d.ts +6 -0
- package/dist/store/CurrencyStore.d.ts.map +1 -0
- package/dist/store/CurrencyStore.js +6 -0
- package/dist/store/ModelStore.d.ts +1 -0
- package/dist/store/ModelStore.d.ts.map +1 -1
- package/dist/store/TransactionModelStore.d.ts +2 -0
- package/dist/store/TransactionModelStore.d.ts.map +1 -1
- package/dist/store/UserModelStore.d.ts +1 -0
- package/dist/store/UserModelStore.d.ts.map +1 -1
- package/dist/utils/BalanceUtil.d.ts +17 -0
- package/dist/utils/BalanceUtil.d.ts.map +1 -0
- package/dist/utils/BalanceUtil.js +105 -0
- package/dist/utils/splitTypeUtils.d.ts.map +1 -1
- package/dist/utils/splitTypeUtils.js +21 -21
- package/package.json +1 -1
- package/dist/client/handlers/UIFriendEventHandler.d.ts +0 -16
- package/dist/client/handlers/UIFriendEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIFriendEventHandler.js +0 -27
- package/dist/client/handlers/UIGroupEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupEventHandler.js +0 -28
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts +0 -18
- package/dist/client/handlers/UIGroupTransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIGroupTransactionEventHandler.js +0 -28
- package/dist/client/handlers/UITransactionEventHandler.d.ts +0 -14
- package/dist/client/handlers/UITransactionEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UITransactionEventHandler.js +0 -26
- package/dist/client/handlers/UIUserEventHandler.d.ts +0 -12
- package/dist/client/handlers/UIUserEventHandler.d.ts.map +0 -1
- package/dist/client/handlers/UIUserEventHandler.js +0 -29
- package/dist/utils/userPathUtils.d.ts +0 -6
- package/dist/utils/userPathUtils.d.ts.map +0 -1
- package/dist/utils/userPathUtils.js +0 -16
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupTransactionEventHandler = void 0;
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class GroupTransactionEventHandler {
|
|
9
|
-
constructor(modelStore, eventStore, groupModelStore, transactionEventStore, transactionModelStore, activityEventHandler) {
|
|
4
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
|
+
class GroupTransactionEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
6
|
+
constructor(modelStore, eventStore, groupModelStore, transactionEventStore, transactionModelStore, isClient, modelChangeEmitter, activityEventHandler) {
|
|
7
|
+
super(isClient, modelChangeEmitter);
|
|
10
8
|
this.modelStore = modelStore;
|
|
11
9
|
this.eventStore = eventStore;
|
|
12
10
|
this.groupModelStore = groupModelStore;
|
|
@@ -14,25 +12,35 @@ class GroupTransactionEventHandler {
|
|
|
14
12
|
this.transactionModelStore = transactionModelStore;
|
|
15
13
|
this.activityEventHandler = activityEventHandler;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
22
|
-
existingModel.version === updatedModel.version);
|
|
15
|
+
getModelStore() {
|
|
16
|
+
return this.modelStore;
|
|
23
17
|
}
|
|
24
18
|
async handleClientEventFromRemoteListener(event) {
|
|
25
|
-
const existingModel = await this.modelStore.
|
|
19
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
26
20
|
const updatedModel = event.apply(existingModel);
|
|
27
21
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
28
22
|
await this.modelStore.save(updatedModel);
|
|
29
|
-
|
|
30
|
-
|
|
23
|
+
this.modelChangeEmitter?.emit("GroupTransactionModel", updatedModel);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async handleClientEventsFromRemoteListenerBulk(events) {
|
|
27
|
+
const updatedModels = [];
|
|
28
|
+
for (const event of events) {
|
|
29
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
30
|
+
const updatedModel = event.apply(existingModel);
|
|
31
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
32
|
+
await this.modelStore.save(updatedModel);
|
|
33
|
+
updatedModels.push(updatedModel);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (this.modelChangeEmitter && updatedModels.length > 0) {
|
|
37
|
+
for (const model of updatedModels) {
|
|
38
|
+
this.modelChangeEmitter.emit("GroupTransactionModel", model);
|
|
31
39
|
}
|
|
32
40
|
}
|
|
33
41
|
}
|
|
34
42
|
async handleEvent(event) {
|
|
35
|
-
if (
|
|
43
|
+
if (this.isClient) {
|
|
36
44
|
await this.eventStore.addEvent(event);
|
|
37
45
|
}
|
|
38
46
|
const eventType = event.constructor.name;
|
|
@@ -45,258 +53,16 @@ class GroupTransactionEventHandler {
|
|
|
45
53
|
throw new Error(`Unknown group transaction event type: ${eventType}`);
|
|
46
54
|
}
|
|
47
55
|
}
|
|
48
|
-
calculateNetBalances(members) {
|
|
49
|
-
const netBalances = new Map();
|
|
50
|
-
for (const member of members) {
|
|
51
|
-
const net = member.paid - member.owed;
|
|
52
|
-
netBalances.set(member.memberId, net);
|
|
53
|
-
}
|
|
54
|
-
return netBalances;
|
|
55
|
-
}
|
|
56
|
-
async createFriendTransactions(groupTransactionEvent) {
|
|
57
|
-
const netBalances = this.calculateNetBalances(groupTransactionEvent.originalTransaction.members);
|
|
58
|
-
const creditors = [];
|
|
59
|
-
const debtors = [];
|
|
60
|
-
for (const [memberId, net] of netBalances.entries()) {
|
|
61
|
-
if (net > 0) {
|
|
62
|
-
creditors.push({ memberId, amount: net });
|
|
63
|
-
}
|
|
64
|
-
else if (net < 0) {
|
|
65
|
-
debtors.push({ memberId, amount: Math.abs(net) });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (const creditor of creditors) {
|
|
69
|
-
for (const debtor of debtors) {
|
|
70
|
-
if (creditor.amount > 0 && debtor.amount > 0) {
|
|
71
|
-
const transactionAmount = Math.min(creditor.amount, debtor.amount);
|
|
72
|
-
const creditorStreamId = (0, uuid_1.v4)();
|
|
73
|
-
const creditorTransactionEvent = new _1.TransactionCreated({
|
|
74
|
-
eventId: (0, uuid_1.v4)(),
|
|
75
|
-
userId: creditor.memberId,
|
|
76
|
-
recipientUserId: debtor.memberId,
|
|
77
|
-
logicalTransactionId: groupTransactionEvent.transactionId,
|
|
78
|
-
description: groupTransactionEvent.description ?? "",
|
|
79
|
-
currency: groupTransactionEvent.currency,
|
|
80
|
-
splitType: _1.SplitType.SpecificAmounts,
|
|
81
|
-
totalAmount: transactionAmount,
|
|
82
|
-
amount: transactionAmount,
|
|
83
|
-
isOwed: false,
|
|
84
|
-
transactionDate: groupTransactionEvent.transactionDate,
|
|
85
|
-
groupId: groupTransactionEvent.groupId,
|
|
86
|
-
groupTransactionId: groupTransactionEvent.transactionId,
|
|
87
|
-
createdAt: new Date(),
|
|
88
|
-
createdBy: groupTransactionEvent.createdBy,
|
|
89
|
-
streamId: creditorStreamId,
|
|
90
|
-
version: 1,
|
|
91
|
-
systemGenerated: true,
|
|
92
|
-
});
|
|
93
|
-
await this.transactionEventStore.addEvent(creditorTransactionEvent);
|
|
94
|
-
const creditorModel = creditorTransactionEvent.apply(undefined);
|
|
95
|
-
if (!this.shouldSkipSave(undefined, creditorModel)) {
|
|
96
|
-
await this.transactionModelStore.save(creditorModel);
|
|
97
|
-
}
|
|
98
|
-
const debtorStreamId = (0, uuid_1.v4)();
|
|
99
|
-
const debtorTransactionEvent = new _1.TransactionCreated({
|
|
100
|
-
eventId: (0, uuid_1.v4)(),
|
|
101
|
-
userId: debtor.memberId,
|
|
102
|
-
recipientUserId: creditor.memberId,
|
|
103
|
-
logicalTransactionId: groupTransactionEvent.transactionId,
|
|
104
|
-
description: groupTransactionEvent.description ?? "",
|
|
105
|
-
currency: groupTransactionEvent.currency,
|
|
106
|
-
splitType: _1.SplitType.SpecificAmounts,
|
|
107
|
-
totalAmount: transactionAmount,
|
|
108
|
-
amount: transactionAmount,
|
|
109
|
-
isOwed: true,
|
|
110
|
-
transactionDate: groupTransactionEvent.transactionDate,
|
|
111
|
-
groupId: groupTransactionEvent.groupId,
|
|
112
|
-
groupTransactionId: groupTransactionEvent.transactionId,
|
|
113
|
-
createdAt: new Date(),
|
|
114
|
-
createdBy: groupTransactionEvent.createdBy,
|
|
115
|
-
streamId: debtorStreamId,
|
|
116
|
-
version: 1,
|
|
117
|
-
systemGenerated: true,
|
|
118
|
-
});
|
|
119
|
-
await this.transactionEventStore.addEvent(debtorTransactionEvent);
|
|
120
|
-
const debtorModel = debtorTransactionEvent.apply(undefined);
|
|
121
|
-
if (!this.shouldSkipSave(undefined, debtorModel)) {
|
|
122
|
-
await this.transactionModelStore.save(debtorModel);
|
|
123
|
-
}
|
|
124
|
-
creditor.amount -= transactionAmount;
|
|
125
|
-
debtor.amount -= transactionAmount;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
async updateFriendTransactions(event, existingModel, _oldMembers, newMembers) {
|
|
131
|
-
await this.updateExistingFriendTransactions(event, existingModel, newMembers);
|
|
132
|
-
}
|
|
133
|
-
calculateRequiredTransactions(newMembers) {
|
|
134
|
-
const newNetBalances = this.calculateNetBalances(newMembers);
|
|
135
|
-
const requiredTransactions = new Map();
|
|
136
|
-
const creditors = [];
|
|
137
|
-
const debtors = [];
|
|
138
|
-
for (const [memberId, net] of newNetBalances.entries()) {
|
|
139
|
-
if (net > 0) {
|
|
140
|
-
creditors.push({ memberId, amount: net });
|
|
141
|
-
}
|
|
142
|
-
else if (net < 0) {
|
|
143
|
-
debtors.push({ memberId, amount: Math.abs(net) });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
for (const creditor of creditors) {
|
|
147
|
-
for (const debtor of debtors) {
|
|
148
|
-
if (creditor.amount > 0 && debtor.amount > 0) {
|
|
149
|
-
const transactionAmount = Math.min(creditor.amount, debtor.amount);
|
|
150
|
-
const creditorKey = `${creditor.memberId}-${debtor.memberId}`;
|
|
151
|
-
requiredTransactions.set(creditorKey, {
|
|
152
|
-
recipientUserId: debtor.memberId,
|
|
153
|
-
amount: transactionAmount,
|
|
154
|
-
isOwed: false,
|
|
155
|
-
});
|
|
156
|
-
const debtorKey = `${debtor.memberId}-${creditor.memberId}`;
|
|
157
|
-
requiredTransactions.set(debtorKey, {
|
|
158
|
-
recipientUserId: creditor.memberId,
|
|
159
|
-
amount: transactionAmount,
|
|
160
|
-
isOwed: true,
|
|
161
|
-
});
|
|
162
|
-
creditor.amount -= transactionAmount;
|
|
163
|
-
debtor.amount -= transactionAmount;
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return requiredTransactions;
|
|
168
|
-
}
|
|
169
|
-
async updateExistingFriendTransactions(event, existingModel, newMembers) {
|
|
170
|
-
const requiredTransactions = this.calculateRequiredTransactions(newMembers);
|
|
171
|
-
const oldMemberIds = new Set(existingModel.originalTransaction.members.map((m) => m.memberId));
|
|
172
|
-
const newMemberIds = new Set(newMembers.map((m) => m.memberId));
|
|
173
|
-
const allMemberIds = new Set([...oldMemberIds, ...newMemberIds]);
|
|
174
|
-
for (const memberId of allMemberIds) {
|
|
175
|
-
const existingTransactions = await this.transactionModelStore.findByGroupTransactionId(memberId, existingModel.transactionId);
|
|
176
|
-
for (const existingTx of existingTransactions) {
|
|
177
|
-
const key = `${existingTx.userId}-${existingTx.recipientUserId}`;
|
|
178
|
-
const requiredTx = requiredTransactions.get(key);
|
|
179
|
-
if (requiredTx) {
|
|
180
|
-
if (existingTx.amount !== requiredTx.amount ||
|
|
181
|
-
existingTx.totalAmount !== requiredTx.amount ||
|
|
182
|
-
existingTx.isOwed !== requiredTx.isOwed) {
|
|
183
|
-
const updateEvent = new _1.TransactionDetailsChanged({
|
|
184
|
-
eventId: (0, uuid_1.v4)(),
|
|
185
|
-
userId: existingTx.userId,
|
|
186
|
-
totalAmount: requiredTx.amount,
|
|
187
|
-
amount: requiredTx.amount,
|
|
188
|
-
isOwed: requiredTx.isOwed,
|
|
189
|
-
streamId: existingTx.streamId,
|
|
190
|
-
version: existingTx.version + 1,
|
|
191
|
-
createdAt: new Date(),
|
|
192
|
-
createdBy: event.createdBy,
|
|
193
|
-
systemGenerated: true,
|
|
194
|
-
});
|
|
195
|
-
await this.transactionEventStore.addEvent(updateEvent);
|
|
196
|
-
const updatedModel = updateEvent.apply(existingTx);
|
|
197
|
-
if (!this.shouldSkipSave(existingTx, updatedModel)) {
|
|
198
|
-
await this.transactionModelStore.save(updatedModel);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
requiredTransactions.delete(key);
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
const deleteEvent = new _1.TransactionDeleted({
|
|
205
|
-
eventId: (0, uuid_1.v4)(),
|
|
206
|
-
userId: existingTx.userId,
|
|
207
|
-
createdAt: new Date(),
|
|
208
|
-
createdBy: event.createdBy,
|
|
209
|
-
streamId: existingTx.streamId,
|
|
210
|
-
version: existingTx.version + 1,
|
|
211
|
-
systemGenerated: true,
|
|
212
|
-
});
|
|
213
|
-
await this.transactionEventStore.addEvent(deleteEvent);
|
|
214
|
-
const deletedModel = deleteEvent.apply(existingTx);
|
|
215
|
-
if (!this.shouldSkipSave(existingTx, deletedModel)) {
|
|
216
|
-
await this.transactionModelStore.save(deletedModel);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
for (const [key, txDetails] of requiredTransactions.entries()) {
|
|
222
|
-
const [userId, recipientUserId] = key.split("-");
|
|
223
|
-
const streamId = (0, uuid_1.v4)();
|
|
224
|
-
const createEvent = new _1.TransactionCreated({
|
|
225
|
-
eventId: (0, uuid_1.v4)(),
|
|
226
|
-
userId: userId,
|
|
227
|
-
recipientUserId: recipientUserId,
|
|
228
|
-
logicalTransactionId: existingModel.transactionId,
|
|
229
|
-
description: existingModel.description ?? "",
|
|
230
|
-
currency: existingModel.currency,
|
|
231
|
-
splitType: _1.SplitType.SpecificAmounts,
|
|
232
|
-
totalAmount: txDetails.amount,
|
|
233
|
-
amount: txDetails.amount,
|
|
234
|
-
isOwed: txDetails.isOwed,
|
|
235
|
-
transactionDate: existingModel.transactionDate,
|
|
236
|
-
groupId: existingModel.groupId,
|
|
237
|
-
groupTransactionId: existingModel.transactionId,
|
|
238
|
-
createdAt: new Date(),
|
|
239
|
-
createdBy: event.createdBy,
|
|
240
|
-
streamId: streamId,
|
|
241
|
-
version: 1,
|
|
242
|
-
systemGenerated: true,
|
|
243
|
-
});
|
|
244
|
-
await this.transactionEventStore.addEvent(createEvent);
|
|
245
|
-
const model = createEvent.apply(undefined);
|
|
246
|
-
if (!this.shouldSkipSave(undefined, model)) {
|
|
247
|
-
await this.transactionModelStore.save(model);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
56
|
async handleGroupTransactionCreated(event) {
|
|
252
57
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
253
58
|
const updatedModel = event.apply(existingModel);
|
|
254
59
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
255
60
|
await this.modelStore.save(updatedModel);
|
|
256
|
-
|
|
257
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupTransactionModel", updatedModel);
|
|
258
|
-
}
|
|
61
|
+
this.modelChangeEmitter?.emit("GroupTransactionModel", updatedModel);
|
|
259
62
|
}
|
|
260
63
|
if (this.activityEventHandler) {
|
|
261
64
|
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
262
65
|
}
|
|
263
|
-
const allGroupPerspectives = await this.groupModelStore.findAllByGroupIdAndDeletedIsFalse(event.groupId);
|
|
264
|
-
for (const groupPerspective of allGroupPerspectives) {
|
|
265
|
-
if (groupPerspective.userId !== event.userId) {
|
|
266
|
-
const perspectiveStreamId = (0, uuid_1.v4)();
|
|
267
|
-
const perspectiveSplitType = (0, splitTypeUtils_1.reverseSplitType)(event.splitType);
|
|
268
|
-
const perspectiveEvent = new _1.GroupTransactionCreated({
|
|
269
|
-
eventId: (0, uuid_1.v4)(),
|
|
270
|
-
userId: groupPerspective.userId,
|
|
271
|
-
groupId: event.groupId,
|
|
272
|
-
transactionId: event.transactionId,
|
|
273
|
-
description: event.description,
|
|
274
|
-
notes: event.notes,
|
|
275
|
-
totalAmount: event.totalAmount,
|
|
276
|
-
currency: event.currency,
|
|
277
|
-
splitType: perspectiveSplitType,
|
|
278
|
-
transactionDate: event.transactionDate,
|
|
279
|
-
originalTransaction: event.originalTransaction,
|
|
280
|
-
createdAt: new Date(),
|
|
281
|
-
createdBy: event.createdBy,
|
|
282
|
-
streamId: perspectiveStreamId,
|
|
283
|
-
version: 1,
|
|
284
|
-
systemGenerated: true,
|
|
285
|
-
});
|
|
286
|
-
await this.eventStore.addEvent(perspectiveEvent);
|
|
287
|
-
const perspectiveModel = perspectiveEvent.apply(undefined);
|
|
288
|
-
if (!this.shouldSkipSave(undefined, perspectiveModel)) {
|
|
289
|
-
await this.modelStore.save(perspectiveModel);
|
|
290
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
291
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupTransactionModel", perspectiveModel);
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (this.activityEventHandler) {
|
|
295
|
-
await this.activityEventHandler.createActivityLog(perspectiveEvent, undefined, perspectiveModel);
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
await this.createFriendTransactions(event);
|
|
300
66
|
return updatedModel;
|
|
301
67
|
}
|
|
302
68
|
async handleGroupTransactionSplitDetailsChanged(event) {
|
|
@@ -304,52 +70,14 @@ class GroupTransactionEventHandler {
|
|
|
304
70
|
if (!existingModel) {
|
|
305
71
|
throw new Error("GroupTransaction must exist to change split details");
|
|
306
72
|
}
|
|
307
|
-
const oldMembers = existingModel.originalTransaction.members;
|
|
308
|
-
const newMembers = event.originalTransaction.members;
|
|
309
73
|
const updatedModel = event.apply(existingModel);
|
|
310
74
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
311
75
|
await this.modelStore.save(updatedModel);
|
|
312
|
-
|
|
313
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupTransactionModel", updatedModel);
|
|
314
|
-
}
|
|
76
|
+
this.modelChangeEmitter?.emit("GroupTransactionModel", updatedModel);
|
|
315
77
|
}
|
|
316
78
|
if (this.activityEventHandler) {
|
|
317
79
|
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
318
80
|
}
|
|
319
|
-
const allGroupPerspectives = await this.groupModelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
320
|
-
for (const groupPerspective of allGroupPerspectives) {
|
|
321
|
-
if (groupPerspective.userId !== event.userId) {
|
|
322
|
-
const perspectiveStreamId = updatedModel.streamId;
|
|
323
|
-
const perspectiveSplitType = (0, splitTypeUtils_1.reverseSplitType)(event.splitType);
|
|
324
|
-
const perspectiveEvent = new _1.GroupTransactionSplitDetailsChanged({
|
|
325
|
-
eventId: (0, uuid_1.v4)(),
|
|
326
|
-
userId: groupPerspective.userId,
|
|
327
|
-
totalAmount: event.totalAmount,
|
|
328
|
-
splitType: perspectiveSplitType,
|
|
329
|
-
originalTransaction: event.originalTransaction,
|
|
330
|
-
createdAt: new Date(),
|
|
331
|
-
createdBy: event.createdBy,
|
|
332
|
-
streamId: perspectiveStreamId,
|
|
333
|
-
version: updatedModel.version,
|
|
334
|
-
systemGenerated: true,
|
|
335
|
-
});
|
|
336
|
-
await this.eventStore.addEvent(perspectiveEvent);
|
|
337
|
-
const existingPerspectiveModel = await this.modelStore.findByUserIdAndTransactionId(groupPerspective.userId, updatedModel.transactionId);
|
|
338
|
-
if (existingPerspectiveModel) {
|
|
339
|
-
const perspectiveModel = perspectiveEvent.apply(existingPerspectiveModel);
|
|
340
|
-
if (!this.shouldSkipSave(existingPerspectiveModel, perspectiveModel)) {
|
|
341
|
-
await this.modelStore.save(perspectiveModel);
|
|
342
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
343
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupTransactionModel", perspectiveModel);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
if (this.activityEventHandler) {
|
|
347
|
-
await this.activityEventHandler.createActivityLog(perspectiveEvent, existingPerspectiveModel, perspectiveModel);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
}
|
|
352
|
-
await this.updateFriendTransactions(event, existingModel, oldMembers, newMembers);
|
|
353
81
|
return updatedModel;
|
|
354
82
|
}
|
|
355
83
|
}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { TransactionEvent, TransactionEventStore, TransactionModel, TransactionModelStore } from ".";
|
|
2
2
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
4
|
-
|
|
4
|
+
import { ModelChangeEmitter } from "./ModelChangeEmitter";
|
|
5
|
+
export declare class TransactionEventHandler extends BaseEventHandler<TransactionEvent> {
|
|
5
6
|
private modelStore;
|
|
6
7
|
private eventStore;
|
|
7
8
|
private activityEventHandler?;
|
|
8
|
-
constructor(modelStore: TransactionModelStore, eventStore: TransactionEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
9
|
-
|
|
9
|
+
constructor(modelStore: TransactionModelStore, eventStore: TransactionEventStore, isClient: boolean, modelChangeEmitter?: ModelChangeEmitter, activityEventHandler?: ActivityEventHandler | undefined);
|
|
10
|
+
getModelStore(): TransactionModelStore;
|
|
10
11
|
handleClientEventFromRemoteListener(event: TransactionEvent): Promise<void>;
|
|
12
|
+
handleClientEventsFromRemoteListenerBulk(events: TransactionEvent[]): Promise<void>;
|
|
11
13
|
handleEvent(event: TransactionEvent): Promise<TransactionModel>;
|
|
12
14
|
private createMirrorEvent;
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/TransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"TransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/TransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EASH,gBAAgB,EAChB,qBAAqB,EACrB,gBAAgB,EAChB,qBAAqB,EACxB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAM9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,gBAAgB,CAAC;IAEvE,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,oBAAoB,CAAC;gBAJrB,UAAU,EAAE,qBAAqB,EACjC,UAAU,EAAE,qBAAqB,EACzC,QAAQ,EAAE,OAAO,EACjB,kBAAkB,CAAC,EAAE,kBAAkB,EAC/B,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAKhD,aAAa,IAAI,qBAAqB;IAIhC,mCAAmC,CAC5C,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC;IAWH,wCAAwC,CACjD,MAAM,EAAE,gBAAgB,EAAE,GAC3B,OAAO,CAAC,IAAI,CAAC;IAqBV,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YA0BvD,iBAAiB;CA6KlC"}
|
|
@@ -2,28 +2,41 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const splitTypeUtils_1 = require("./utils/splitTypeUtils");
|
|
6
7
|
const uuid_1 = require("uuid");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
class TransactionEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
|
+
constructor(modelStore, eventStore, isClient, modelChangeEmitter, activityEventHandler) {
|
|
10
|
+
super(isClient, modelChangeEmitter);
|
|
10
11
|
this.modelStore = modelStore;
|
|
11
12
|
this.eventStore = eventStore;
|
|
12
13
|
this.activityEventHandler = activityEventHandler;
|
|
13
14
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
19
|
-
existingModel.version === updatedModel.version);
|
|
15
|
+
getModelStore() {
|
|
16
|
+
return this.modelStore;
|
|
20
17
|
}
|
|
21
18
|
async handleClientEventFromRemoteListener(event) {
|
|
22
|
-
const existingModel = await this.modelStore.
|
|
19
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
23
20
|
const model = event.apply(existingModel);
|
|
24
21
|
if (!this.shouldSkipSave(existingModel, model)) {
|
|
25
22
|
await this.modelStore.save(model);
|
|
26
|
-
|
|
23
|
+
this.modelChangeEmitter?.emit("TransactionModel", model);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
async handleClientEventsFromRemoteListenerBulk(events) {
|
|
27
|
+
const updatedModels = [];
|
|
28
|
+
for (const event of events) {
|
|
29
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
30
|
+
const model = event.apply(existingModel);
|
|
31
|
+
if (!this.shouldSkipSave(existingModel, model)) {
|
|
32
|
+
await this.modelStore.save(model);
|
|
33
|
+
updatedModels.push(model);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (this.modelChangeEmitter && updatedModels.length > 0) {
|
|
37
|
+
for (const model of updatedModels) {
|
|
38
|
+
this.modelChangeEmitter.emit("TransactionModel", model);
|
|
39
|
+
}
|
|
27
40
|
}
|
|
28
41
|
}
|
|
29
42
|
async handleEvent(event) {
|
|
@@ -31,9 +44,9 @@ class TransactionEventHandler {
|
|
|
31
44
|
const model = event.apply(existingModel);
|
|
32
45
|
if (!this.shouldSkipSave(existingModel, model)) {
|
|
33
46
|
await this.modelStore.save(model);
|
|
34
|
-
if (
|
|
47
|
+
if (this.isClient) {
|
|
35
48
|
await this.eventStore.addEvent(event);
|
|
36
|
-
|
|
49
|
+
this.modelChangeEmitter?.emit("TransactionModel", model);
|
|
37
50
|
if (this.activityEventHandler) {
|
|
38
51
|
await this.activityEventHandler.createActivityLog(event, existingModel, model);
|
|
39
52
|
}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { TransactionEvent } from "./common/DomainEvents";
|
|
2
2
|
import { Model } from "./common/Model";
|
|
3
3
|
import { ActivityLogCreatedProps } from "./ActivityLogEvents";
|
|
4
|
-
export
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
export type SplitType = (typeof SplitTypeEnum)[keyof typeof SplitTypeEnum];
|
|
5
|
+
export declare const SplitTypeEnum: {
|
|
6
|
+
readonly YouPaidSplitEqually: "YouPaidSplitEqually";
|
|
7
|
+
readonly TheyPaidSplitEqually: "TheyPaidSplitEqually";
|
|
8
|
+
readonly TheyOweYouAll: "TheyOweYouAll";
|
|
9
|
+
readonly YouOweThemAll: "YouOweThemAll";
|
|
10
|
+
readonly TheyPaidToSettle: "TheyPaidToSettle";
|
|
11
|
+
readonly YouPaidToSettle: "YouPaidToSettle";
|
|
12
|
+
readonly SpecificAmounts: "SpecificAmounts";
|
|
13
|
+
};
|
|
13
14
|
export interface AmountDto {
|
|
14
15
|
amount: number;
|
|
15
16
|
currency: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionEvents.d.ts","sourceRoot":"","sources":["../src/TransactionEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,uBAAuB,EAAc,MAAM,qBAAqB,CAAC;AAI1E,
|
|
1
|
+
{"version":3,"file":"TransactionEvents.d.ts","sourceRoot":"","sources":["../src/TransactionEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,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AAC,QAAQ,CAAC,EAAE,KAAK,GAAG,gBAAgB;IA4CzC,WAAW,CACP,QAAQ,CAAC,EAAE,KAAK,EAChB,SAAS,CAAC,EAAE,MAAM,GACnB,uBAAuB,GAAG,SAAS;CAwBzC"}
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TransactionDetailsChanged = exports.TransactionDateChanged = exports.CurrencyChanged = exports.SplitTypeChanged = exports.TotalAmountChanged = exports.DescriptionChanged = exports.TransactionDeleted = exports.TransactionCreated = exports.ChangeHistory = exports.
|
|
3
|
+
exports.TransactionDetailsChanged = exports.TransactionDateChanged = exports.CurrencyChanged = exports.SplitTypeChanged = exports.TotalAmountChanged = exports.DescriptionChanged = exports.TransactionDeleted = exports.TransactionCreated = exports.ChangeHistory = exports.SplitTypeEnum = void 0;
|
|
4
4
|
const ActivityLogEvents_1 = require("./ActivityLogEvents");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
SplitType["SpecificAmounts"] = "SpecificAmounts";
|
|
16
|
-
})(SplitType || (exports.SplitType = SplitType = {}));
|
|
6
|
+
exports.SplitTypeEnum = {
|
|
7
|
+
YouPaidSplitEqually: "YouPaidSplitEqually",
|
|
8
|
+
TheyPaidSplitEqually: "TheyPaidSplitEqually",
|
|
9
|
+
TheyOweYouAll: "TheyOweYouAll",
|
|
10
|
+
YouOweThemAll: "YouOweThemAll",
|
|
11
|
+
TheyPaidToSettle: "TheyPaidToSettle",
|
|
12
|
+
YouPaidToSettle: "YouPaidToSettle",
|
|
13
|
+
SpecificAmounts: "SpecificAmounts",
|
|
14
|
+
};
|
|
17
15
|
var ChangeHistory;
|
|
18
16
|
(function (ChangeHistory) {
|
|
19
17
|
function empty() {
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { UserCreated, UserEvent, UserEventStore, UserModel, UserModelStore } from ".";
|
|
2
2
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
4
|
-
|
|
4
|
+
import { ModelChangeEmitter } from "./ModelChangeEmitter";
|
|
5
|
+
export declare class UserEventHandler extends BaseEventHandler<UserEvent> {
|
|
5
6
|
private modelStore;
|
|
6
7
|
private eventStore;
|
|
7
8
|
private activityEventHandler?;
|
|
8
|
-
constructor(modelStore: UserModelStore, eventStore: UserEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
9
|
-
|
|
9
|
+
constructor(modelStore: UserModelStore, eventStore: UserEventStore, isClient: boolean, modelChangeEmitter?: ModelChangeEmitter, activityEventHandler?: ActivityEventHandler | undefined);
|
|
10
|
+
getModelStore(): UserModelStore;
|
|
10
11
|
handleClientEventFromRemoteListener(event: UserEvent): Promise<void>;
|
|
12
|
+
handleClientEventsFromRemoteListenerBulk(events: UserEvent[]): Promise<void>;
|
|
11
13
|
handleEvent(event: UserEvent): Promise<UserModel>;
|
|
12
14
|
handleUserCreatedBackend(event: UserCreated): Promise<UserModel>;
|
|
13
15
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"UserEventHandler.d.ts","sourceRoot":"","sources":["../src/UserEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAGH,WAAW,EACX,SAAS,EACT,cAAc,EACd,SAAS,EACT,cAAc,EACjB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,qBAAa,gBAAiB,SAAQ,gBAAgB,CAAC,SAAS,CAAC;IAEzD,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAGlB,OAAO,CAAC,oBAAoB,CAAC;gBAJrB,UAAU,EAAE,cAAc,EAC1B,UAAU,EAAE,cAAc,EAClC,QAAQ,EAAE,OAAO,EACjB,kBAAkB,CAAC,EAAE,kBAAkB,EAC/B,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAKhD,aAAa,IAAI,cAAc;IAIzB,mCAAmC,CAC5C,KAAK,EAAE,SAAS,GACjB,OAAO,CAAC,IAAI,CAAC;IAWH,wCAAwC,CACjD,MAAM,EAAE,SAAS,EAAE,GACpB,OAAO,CAAC,IAAI,CAAC;IAqBV,WAAW,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC;IA6BjD,wBAAwB,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC;CAuDzE"}
|