@zeeshan60/event-processor 1.0.15 → 1.0.16
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 +3 -3
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +3 -8
- package/dist/BaseEventHandler.d.ts +5 -3
- package/dist/BaseEventHandler.d.ts.map +1 -1
- package/dist/BaseEventHandler.js +11 -0
- package/dist/EventProcessorSDK.d.ts +4 -0
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +7 -0
- package/dist/FriendEventHandler.d.ts +4 -2
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +50 -36
- package/dist/GroupEventHandler.d.ts +2 -2
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +235 -186
- package/dist/GroupTransactionEventHandler.d.ts +1 -2
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +4 -9
- package/dist/TransactionEventHandler.d.ts +1 -2
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +4 -9
- package/dist/UserEventHandler.d.ts +1 -2
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +4 -9
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts +8 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.d.ts.map +1 -0
- package/dist/__tests__/test-helpers/IMCurrencyStore.js +16 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +2 -0
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.js +20 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +3 -0
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.js +10 -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 +45 -15
- package/dist/client/controllers/TransactionController.d.ts +7 -1
- package/dist/client/controllers/TransactionController.d.ts.map +1 -1
- package/dist/client/controllers/TransactionController.js +61 -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/contracts/friends/index.d.ts +1 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/environment.d.ts +12 -0
- package/dist/environment.d.ts.map +1 -0
- package/dist/environment.js +50 -0
- 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 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -1
- package/dist/store/CurrencyStore.d.ts +5 -0
- package/dist/store/CurrencyStore.d.ts.map +1 -0
- package/dist/store/CurrencyStore.js +6 -0
- 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 +13 -0
- package/dist/utils/BalanceUtil.d.ts.map +1 -0
- package/dist/utils/BalanceUtil.js +97 -0
- 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
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
5
6
|
const uuid_1 = require("uuid");
|
|
6
7
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
7
|
-
class GroupEventHandler {
|
|
8
|
+
class GroupEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
8
9
|
constructor(modelStore, friendModelStore, userModelStore, groupEventStore, friendEventStore, activityEventHandler) {
|
|
10
|
+
super();
|
|
9
11
|
this.modelStore = modelStore;
|
|
10
12
|
this.friendModelStore = friendModelStore;
|
|
11
13
|
this.userModelStore = userModelStore;
|
|
@@ -13,15 +15,8 @@ class GroupEventHandler {
|
|
|
13
15
|
this.friendEventStore = friendEventStore;
|
|
14
16
|
this.activityEventHandler = activityEventHandler;
|
|
15
17
|
}
|
|
16
|
-
shouldSkipSave(existingModel, updatedModel) {
|
|
17
|
-
if (!existingModel) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
21
|
-
existingModel.version === updatedModel.version);
|
|
22
|
-
}
|
|
23
18
|
async handleClientEventFromRemoteListener(event) {
|
|
24
|
-
const existingModel = await this.modelStore.
|
|
19
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
25
20
|
const updatedModel = event.apply(existingModel);
|
|
26
21
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
27
22
|
await this.modelStore.save(updatedModel);
|
|
@@ -32,6 +27,10 @@ class GroupEventHandler {
|
|
|
32
27
|
}
|
|
33
28
|
async handleEvent(event) {
|
|
34
29
|
const eventType = event.constructor.name;
|
|
30
|
+
if (_1.residence.isClient) {
|
|
31
|
+
const user = await this.userModelStore.appUser();
|
|
32
|
+
this.currentUserId = user.userId;
|
|
33
|
+
}
|
|
35
34
|
switch (eventType) {
|
|
36
35
|
case "GroupCreated":
|
|
37
36
|
return await this.handleGroupCreated(event);
|
|
@@ -75,9 +74,7 @@ class GroupEventHandler {
|
|
|
75
74
|
});
|
|
76
75
|
await this.friendEventStore.addEvent(friendCreatedEvent);
|
|
77
76
|
const friendModel = friendCreatedEvent.apply(undefined);
|
|
78
|
-
|
|
79
|
-
await this.friendModelStore.save(friendModel);
|
|
80
|
-
}
|
|
77
|
+
await this.friendModelStore.save(friendModel);
|
|
81
78
|
}
|
|
82
79
|
const existingFriend2to1 = await this.friendModelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId2, userId1);
|
|
83
80
|
if (!existingFriend2to1) {
|
|
@@ -106,125 +103,131 @@ class GroupEventHandler {
|
|
|
106
103
|
async handleGroupCreated(event) {
|
|
107
104
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
108
105
|
const updatedModel = event.apply(existingModel);
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
112
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
113
|
-
}
|
|
106
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
107
|
+
return existingModel;
|
|
114
108
|
}
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (
|
|
120
|
-
|
|
121
|
-
continue;
|
|
109
|
+
await this.modelStore.save(updatedModel);
|
|
110
|
+
if (_1.residence.isClient) {
|
|
111
|
+
await this.groupEventStore.addEvent(event);
|
|
112
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
113
|
+
if (this.activityEventHandler) {
|
|
114
|
+
await this.activityEventHandler.createActivityLog(event, undefined, updatedModel);
|
|
122
115
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
const allMemberIds = event.members ?? [];
|
|
119
|
+
const otherMembers = allMemberIds.filter((id) => id !== event.userId);
|
|
120
|
+
for (const memberId of otherMembers) {
|
|
121
|
+
const memberUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(memberId);
|
|
122
|
+
if (!memberUser) {
|
|
123
|
+
console.log(`Member ${memberId} not found, skipping`);
|
|
124
|
+
continue;
|
|
126
125
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
126
|
+
for (const otherMemberId of allMemberIds) {
|
|
127
|
+
if (memberId !== otherMemberId) {
|
|
128
|
+
await this.ensureBidirectionalFriendship(memberId, otherMemberId, event.groupId);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
const perspectiveGroupStreamId = (0, uuid_1.v4)();
|
|
132
|
+
const perspectiveGroupCreated = new _1.GroupCreated({
|
|
133
|
+
eventId: (0, uuid_1.v4)(),
|
|
134
|
+
userId: memberId,
|
|
135
|
+
groupId: event.groupId,
|
|
136
|
+
name: event.name,
|
|
137
|
+
description: event.description,
|
|
138
|
+
members: event.members,
|
|
139
|
+
createdAt: new Date(),
|
|
140
|
+
createdBy: memberId,
|
|
141
|
+
streamId: perspectiveGroupStreamId,
|
|
142
|
+
version: 1,
|
|
143
|
+
systemGenerated: true,
|
|
144
|
+
});
|
|
145
|
+
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
146
|
+
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
145
147
|
await this.modelStore.save(perspectiveModel);
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
+
if (this.activityEventHandler) {
|
|
149
|
+
await this.activityEventHandler.createActivityLog(perspectiveGroupCreated, undefined, perspectiveModel);
|
|
148
150
|
}
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
|
-
if (this.activityEventHandler) {
|
|
152
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
153
|
-
}
|
|
154
153
|
return updatedModel;
|
|
155
154
|
}
|
|
156
155
|
async handleGroupNameChanged(event) {
|
|
157
156
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
158
157
|
const updatedModel = event.apply(existingModel);
|
|
159
|
-
if (
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
158
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
159
|
+
return existingModel;
|
|
160
|
+
}
|
|
161
|
+
await this.modelStore.save(updatedModel);
|
|
162
|
+
if (_1.residence.isClient) {
|
|
163
|
+
await this.groupEventStore.addEvent(event);
|
|
164
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
165
|
+
if (this.activityEventHandler) {
|
|
166
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
163
167
|
}
|
|
164
168
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
169
|
+
else {
|
|
170
|
+
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
171
|
+
for (const perspective of allPerspectives) {
|
|
172
|
+
if (perspective.streamId !== event.streamId) {
|
|
173
|
+
const perspectiveEvent = new _1.GroupNameChanged({
|
|
174
|
+
eventId: (0, uuid_1.v4)(),
|
|
175
|
+
userId: perspective.userId,
|
|
176
|
+
name: event.name,
|
|
177
|
+
createdAt: new Date(),
|
|
178
|
+
createdBy: event.createdBy,
|
|
179
|
+
streamId: perspective.streamId,
|
|
180
|
+
version: perspective.version + 1,
|
|
181
|
+
systemGenerated: true,
|
|
182
|
+
});
|
|
183
|
+
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
184
|
+
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
181
185
|
await this.modelStore.save(updatedPerspective);
|
|
182
|
-
if (
|
|
183
|
-
|
|
186
|
+
if (this.activityEventHandler) {
|
|
187
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
184
188
|
}
|
|
185
189
|
}
|
|
186
190
|
}
|
|
187
191
|
}
|
|
188
|
-
if (this.activityEventHandler) {
|
|
189
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
190
|
-
}
|
|
191
192
|
return updatedModel;
|
|
192
193
|
}
|
|
193
194
|
async handleGroupDescriptionChanged(event) {
|
|
194
195
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
195
196
|
const updatedModel = event.apply(existingModel);
|
|
196
|
-
if (
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
197
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
198
|
+
return existingModel;
|
|
199
|
+
}
|
|
200
|
+
await this.modelStore.save(updatedModel);
|
|
201
|
+
if (_1.residence.isClient) {
|
|
202
|
+
await this.groupEventStore.addEvent(event);
|
|
203
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
204
|
+
if (this.activityEventHandler) {
|
|
205
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
200
206
|
}
|
|
201
207
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
208
|
+
else {
|
|
209
|
+
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
210
|
+
for (const perspective of allPerspectives) {
|
|
211
|
+
if (perspective.streamId !== event.streamId) {
|
|
212
|
+
const perspectiveEvent = new _1.GroupDescriptionChanged({
|
|
213
|
+
eventId: (0, uuid_1.v4)(),
|
|
214
|
+
userId: perspective.userId,
|
|
215
|
+
description: event.description,
|
|
216
|
+
createdAt: new Date(),
|
|
217
|
+
createdBy: event.createdBy,
|
|
218
|
+
streamId: perspective.streamId,
|
|
219
|
+
version: perspective.version + 1,
|
|
220
|
+
systemGenerated: true,
|
|
221
|
+
});
|
|
222
|
+
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
223
|
+
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
218
224
|
await this.modelStore.save(updatedPerspective);
|
|
219
|
-
if (
|
|
220
|
-
|
|
225
|
+
if (this.activityEventHandler) {
|
|
226
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
221
227
|
}
|
|
222
228
|
}
|
|
223
229
|
}
|
|
224
230
|
}
|
|
225
|
-
if (this.activityEventHandler) {
|
|
226
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
227
|
-
}
|
|
228
231
|
return updatedModel;
|
|
229
232
|
}
|
|
230
233
|
async handleGroupMembersAdded(event) {
|
|
@@ -233,124 +236,170 @@ class GroupEventHandler {
|
|
|
233
236
|
throw new Error(`Group model not found for streamId ${event.streamId}`);
|
|
234
237
|
}
|
|
235
238
|
const updatedModel = event.apply(existingModel);
|
|
236
|
-
if (
|
|
237
|
-
|
|
238
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
239
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
240
|
-
}
|
|
239
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
240
|
+
return existingModel;
|
|
241
241
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
242
|
+
await this.modelStore.save(updatedModel);
|
|
243
|
+
if (_1.residence.isClient) {
|
|
244
|
+
await this.groupEventStore.addEvent(event);
|
|
245
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
246
|
+
if (this.activityEventHandler) {
|
|
247
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
248
248
|
}
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
const allMemberIds = updatedModel.members ?? [];
|
|
252
|
+
for (const memberId of event.members) {
|
|
253
|
+
const memberUser = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(memberId);
|
|
254
|
+
if (!memberUser) {
|
|
255
|
+
console.log(`Member ${memberId} not found, skipping`);
|
|
256
|
+
continue;
|
|
252
257
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
userId: memberId,
|
|
258
|
-
groupId: existingModel.groupId,
|
|
259
|
-
name: existingModel.name,
|
|
260
|
-
description: existingModel.description,
|
|
261
|
-
members: updatedModel.members,
|
|
262
|
-
createdAt: new Date(),
|
|
263
|
-
createdBy: memberId,
|
|
264
|
-
streamId: perspectiveGroupStreamId,
|
|
265
|
-
version: 1,
|
|
266
|
-
systemGenerated: true,
|
|
267
|
-
});
|
|
268
|
-
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
269
|
-
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
270
|
-
if (!this.shouldSkipSave(undefined, perspectiveModel)) {
|
|
271
|
-
await this.modelStore.save(perspectiveModel);
|
|
272
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
273
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", perspectiveModel);
|
|
258
|
+
for (const otherMemberId of allMemberIds) {
|
|
259
|
+
if (memberId !== otherMemberId) {
|
|
260
|
+
await this.ensureBidirectionalFriendship(memberId, otherMemberId, existingModel.groupId);
|
|
261
|
+
}
|
|
274
262
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
278
|
-
for (const perspective of allPerspectives) {
|
|
279
|
-
if (perspective.streamId !== event.streamId &&
|
|
280
|
-
!event.members.includes(perspective.userId)) {
|
|
281
|
-
const perspectiveEvent = new _1.GroupMembersAdded({
|
|
263
|
+
const perspectiveGroupStreamId = (0, uuid_1.v4)();
|
|
264
|
+
const perspectiveGroupCreated = new _1.GroupCreated({
|
|
282
265
|
eventId: (0, uuid_1.v4)(),
|
|
283
|
-
userId:
|
|
284
|
-
|
|
266
|
+
userId: memberId,
|
|
267
|
+
groupId: existingModel.groupId,
|
|
268
|
+
name: existingModel.name,
|
|
269
|
+
description: existingModel.description,
|
|
270
|
+
members: updatedModel.members,
|
|
285
271
|
createdAt: new Date(),
|
|
286
|
-
createdBy:
|
|
287
|
-
streamId:
|
|
288
|
-
version:
|
|
272
|
+
createdBy: memberId,
|
|
273
|
+
streamId: perspectiveGroupStreamId,
|
|
274
|
+
version: 1,
|
|
289
275
|
systemGenerated: true,
|
|
290
276
|
});
|
|
291
|
-
await this.groupEventStore.addEvent(
|
|
292
|
-
const
|
|
293
|
-
|
|
277
|
+
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
278
|
+
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
279
|
+
await this.modelStore.save(perspectiveModel);
|
|
280
|
+
if (this.activityEventHandler) {
|
|
281
|
+
await this.activityEventHandler.createActivityLog(perspectiveGroupCreated, undefined, perspectiveModel);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
285
|
+
for (const perspective of allPerspectives) {
|
|
286
|
+
if (perspective.streamId !== event.streamId &&
|
|
287
|
+
!event.members.includes(perspective.userId)) {
|
|
288
|
+
const perspectiveEvent = new _1.GroupMembersAdded({
|
|
289
|
+
eventId: (0, uuid_1.v4)(),
|
|
290
|
+
userId: perspective.userId,
|
|
291
|
+
members: event.members,
|
|
292
|
+
createdAt: new Date(),
|
|
293
|
+
createdBy: event.createdBy,
|
|
294
|
+
streamId: perspective.streamId,
|
|
295
|
+
version: perspective.version + 1,
|
|
296
|
+
systemGenerated: true,
|
|
297
|
+
});
|
|
298
|
+
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
299
|
+
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
294
300
|
await this.modelStore.save(updatedPerspective);
|
|
295
|
-
if (
|
|
296
|
-
|
|
301
|
+
if (this.activityEventHandler) {
|
|
302
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
297
303
|
}
|
|
298
304
|
}
|
|
299
305
|
}
|
|
300
306
|
}
|
|
301
|
-
if (this.activityEventHandler) {
|
|
302
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
303
|
-
}
|
|
304
307
|
return updatedModel;
|
|
305
308
|
}
|
|
306
309
|
async handleGroupMembersRemoved(event) {
|
|
307
310
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
308
311
|
const updatedModel = event.apply(existingModel);
|
|
309
|
-
if (
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
312
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
313
|
+
return existingModel;
|
|
314
|
+
}
|
|
315
|
+
await this.modelStore.save(updatedModel);
|
|
316
|
+
if (_1.residence.isClient) {
|
|
317
|
+
await this.groupEventStore.addEvent(event);
|
|
318
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
319
|
+
if (this.activityEventHandler) {
|
|
320
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
313
321
|
}
|
|
314
322
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
323
|
+
else {
|
|
324
|
+
for (const removedMemberId of event.members) {
|
|
325
|
+
const removedMemberPerspective = await this.modelStore.findByUserIdAndGroupIdAndDeletedIsFalse(removedMemberId, updatedModel.groupId);
|
|
326
|
+
if (removedMemberPerspective) {
|
|
327
|
+
const deleteEvent = new _1.GroupDeleted({
|
|
328
|
+
eventId: (0, uuid_1.v4)(),
|
|
329
|
+
userId: removedMemberId,
|
|
330
|
+
createdAt: new Date(),
|
|
331
|
+
createdBy: event.createdBy,
|
|
332
|
+
streamId: removedMemberPerspective.streamId,
|
|
333
|
+
version: removedMemberPerspective.version + 1,
|
|
334
|
+
systemGenerated: true,
|
|
335
|
+
});
|
|
336
|
+
const deletedPerspective = deleteEvent.apply(removedMemberPerspective);
|
|
337
|
+
await this.groupEventStore.addEvent(deleteEvent);
|
|
338
|
+
await this.modelStore.save(deletedPerspective);
|
|
339
|
+
if (this.activityEventHandler) {
|
|
340
|
+
await this.activityEventHandler.createActivityLog(deleteEvent, removedMemberPerspective, deletedPerspective);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
345
|
+
for (const perspective of allPerspectives) {
|
|
346
|
+
if (perspective.streamId !== event.streamId) {
|
|
347
|
+
const perspectiveEvent = new _1.GroupMembersRemoved({
|
|
348
|
+
eventId: (0, uuid_1.v4)(),
|
|
349
|
+
userId: perspective.userId,
|
|
350
|
+
members: event.members,
|
|
351
|
+
createdAt: new Date(),
|
|
352
|
+
createdBy: event.createdBy,
|
|
353
|
+
streamId: perspective.streamId,
|
|
354
|
+
version: perspective.version + 1,
|
|
355
|
+
systemGenerated: true,
|
|
356
|
+
});
|
|
357
|
+
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
358
|
+
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
331
359
|
await this.modelStore.save(updatedPerspective);
|
|
332
|
-
if (
|
|
333
|
-
|
|
360
|
+
if (this.activityEventHandler) {
|
|
361
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
334
362
|
}
|
|
335
363
|
}
|
|
336
364
|
}
|
|
337
365
|
}
|
|
338
|
-
if (this.activityEventHandler) {
|
|
339
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
340
|
-
}
|
|
341
366
|
return updatedModel;
|
|
342
367
|
}
|
|
343
368
|
async handleGroupDeleted(event) {
|
|
344
369
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
345
370
|
const updatedModel = event.apply(existingModel);
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
371
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
372
|
+
return existingModel;
|
|
373
|
+
}
|
|
374
|
+
await this.modelStore.save(updatedModel);
|
|
375
|
+
if (_1.residence.isClient) {
|
|
376
|
+
await this.groupEventStore.addEvent(event);
|
|
377
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
378
|
+
if (this.activityEventHandler) {
|
|
379
|
+
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
350
380
|
}
|
|
351
381
|
}
|
|
352
|
-
|
|
353
|
-
await this.
|
|
382
|
+
else {
|
|
383
|
+
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
384
|
+
for (const perspective of allPerspectives) {
|
|
385
|
+
if (perspective.streamId !== event.streamId) {
|
|
386
|
+
const perspectiveEvent = new _1.GroupDeleted({
|
|
387
|
+
eventId: (0, uuid_1.v4)(),
|
|
388
|
+
userId: perspective.userId,
|
|
389
|
+
createdAt: new Date(),
|
|
390
|
+
createdBy: event.createdBy,
|
|
391
|
+
streamId: perspective.streamId,
|
|
392
|
+
version: perspective.version + 1,
|
|
393
|
+
systemGenerated: true,
|
|
394
|
+
});
|
|
395
|
+
const updatedPerspective = perspectiveEvent.apply(perspective);
|
|
396
|
+
await this.groupEventStore.addEvent(perspectiveEvent);
|
|
397
|
+
await this.modelStore.save(updatedPerspective);
|
|
398
|
+
if (this.activityEventHandler) {
|
|
399
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
}
|
|
354
403
|
}
|
|
355
404
|
return updatedModel;
|
|
356
405
|
}
|
|
@@ -6,7 +6,7 @@ import { TransactionEventStore } from ".";
|
|
|
6
6
|
import { TransactionModelStore } from ".";
|
|
7
7
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
8
8
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
9
|
-
export declare class GroupTransactionEventHandler
|
|
9
|
+
export declare class GroupTransactionEventHandler extends BaseEventHandler<GroupTransactionEvent> {
|
|
10
10
|
private modelStore;
|
|
11
11
|
private eventStore;
|
|
12
12
|
private groupModelStore;
|
|
@@ -14,7 +14,6 @@ export declare class GroupTransactionEventHandler implements BaseEventHandler<Gr
|
|
|
14
14
|
private transactionModelStore;
|
|
15
15
|
private activityEventHandler?;
|
|
16
16
|
constructor(modelStore: GroupTransactionModelStore, eventStore: GroupTransactionEventStore, groupModelStore: GroupModelStore, transactionEventStore: TransactionEventStore, transactionModelStore: TransactionModelStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
17
|
-
private shouldSkipSave;
|
|
18
17
|
handleClientEventFromRemoteListener(event: GroupTransactionEvent): Promise<void>;
|
|
19
18
|
handleEvent(event: GroupTransactionEvent): Promise<GroupTransactionModel>;
|
|
20
19
|
private calculateNetBalances;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupTransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupTransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EAIrB,qBAAqB,EAKxB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,qBAAa,
|
|
1
|
+
{"version":3,"file":"GroupTransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/GroupTransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,uBAAuB,EACvB,mCAAmC,EACnC,qBAAqB,EAIrB,qBAAqB,EAKxB,MAAM,GAAG,CAAC;AACX,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,GAAG,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,GAAG,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,GAAG,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAK9D,qBAAa,4BAA6B,SAAQ,gBAAgB,CAAC,qBAAqB,CAAC;IAEjF,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,eAAe;IACvB,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,qBAAqB;IAC7B,OAAO,CAAC,oBAAoB,CAAC;gBALrB,UAAU,EAAE,0BAA0B,EACtC,UAAU,EAAE,0BAA0B,EACtC,eAAe,EAAE,eAAe,EAChC,qBAAqB,EAAE,qBAAqB,EAC5C,qBAAqB,EAAE,qBAAqB,EAC5C,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAK1C,mCAAmC,CAC5C,KAAK,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC;IAkBV,WAAW,CACb,KAAK,EAAE,qBAAqB,GAC7B,OAAO,CAAC,qBAAqB,CAAC;IAsBjC,OAAO,CAAC,oBAAoB;YAad,wBAAwB;YA8FxB,wBAAwB;IAatC,OAAO,CAAC,6BAA6B;YAsDvB,gCAAgC;IAqGxC,6BAA6B,CAC/B,KAAK,EAAE,uBAAuB,GAC/B,OAAO,CAAC,qBAAqB,CAAC;IAkF3B,yCAAyC,CAC3C,KAAK,EAAE,mCAAmC,GAC3C,OAAO,CAAC,qBAAqB,CAAC;CAsGpC"}
|
|
@@ -2,11 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupTransactionEventHandler = 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
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
8
|
-
class GroupTransactionEventHandler {
|
|
9
|
+
class GroupTransactionEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
10
|
constructor(modelStore, eventStore, groupModelStore, transactionEventStore, transactionModelStore, activityEventHandler) {
|
|
11
|
+
super();
|
|
10
12
|
this.modelStore = modelStore;
|
|
11
13
|
this.eventStore = eventStore;
|
|
12
14
|
this.groupModelStore = groupModelStore;
|
|
@@ -14,15 +16,8 @@ class GroupTransactionEventHandler {
|
|
|
14
16
|
this.transactionModelStore = transactionModelStore;
|
|
15
17
|
this.activityEventHandler = activityEventHandler;
|
|
16
18
|
}
|
|
17
|
-
shouldSkipSave(existingModel, updatedModel) {
|
|
18
|
-
if (!existingModel) {
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
22
|
-
existingModel.version === updatedModel.version);
|
|
23
|
-
}
|
|
24
19
|
async handleClientEventFromRemoteListener(event) {
|
|
25
|
-
const existingModel = await this.modelStore.
|
|
20
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
26
21
|
const updatedModel = event.apply(existingModel);
|
|
27
22
|
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
28
23
|
await this.modelStore.save(updatedModel);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { TransactionEvent, TransactionEventStore, TransactionModel, TransactionModelStore } from ".";
|
|
2
2
|
import { BaseEventHandler } from "./BaseEventHandler";
|
|
3
3
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
4
|
-
export declare class TransactionEventHandler
|
|
4
|
+
export declare class TransactionEventHandler extends BaseEventHandler<TransactionEvent> {
|
|
5
5
|
private modelStore;
|
|
6
6
|
private eventStore;
|
|
7
7
|
private activityEventHandler?;
|
|
8
8
|
constructor(modelStore: TransactionModelStore, eventStore: TransactionEventStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
9
|
-
private shouldSkipSave;
|
|
10
9
|
handleClientEventFromRemoteListener(event: TransactionEvent): Promise<void>;
|
|
11
10
|
handleEvent(event: TransactionEvent): Promise<TransactionModel>;
|
|
12
11
|
private createMirrorEvent;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/TransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAUH,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;AAQ9D,qBAAa,
|
|
1
|
+
{"version":3,"file":"TransactionEventHandler.d.ts","sourceRoot":"","sources":["../src/TransactionEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAUH,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;AAQ9D,qBAAa,uBAAwB,SAAQ,gBAAgB,CAAC,gBAAgB,CAAC;IAEvE,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,oBAAoB,CAAC;gBAFrB,UAAU,EAAE,qBAAqB,EACjC,UAAU,EAAE,qBAAqB,EACjC,oBAAoB,CAAC,EAAE,oBAAoB,YAAA;IAK1C,mCAAmC,CAC5C,KAAK,EAAE,gBAAgB,GACxB,OAAO,CAAC,IAAI,CAAC;IAcV,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;YA6BvD,iBAAiB;CA6KlC"}
|