@zeeshan60/event-processor 1.0.14 → 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 +5 -6
- package/dist/ActivityEventHandler.d.ts.map +1 -1
- package/dist/ActivityEventHandler.js +16 -8
- package/dist/ActivityLogEvents.d.ts.map +1 -1
- package/dist/BaseEventHandler.d.ts +8 -0
- package/dist/BaseEventHandler.d.ts.map +1 -0
- package/dist/BaseEventHandler.js +13 -0
- package/dist/EventProcessorSDK.d.ts +10 -2
- package/dist/EventProcessorSDK.d.ts.map +1 -1
- package/dist/EventProcessorSDK.js +21 -5
- package/dist/FriendEventHandler.d.ts +6 -2
- package/dist/FriendEventHandler.d.ts.map +1 -1
- package/dist/FriendEventHandler.js +50 -45
- package/dist/GroupEventHandler.d.ts +5 -8
- package/dist/GroupEventHandler.d.ts.map +1 -1
- package/dist/GroupEventHandler.js +241 -186
- package/dist/GroupEvents.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.d.ts +3 -2
- package/dist/GroupTransactionEventHandler.d.ts.map +1 -1
- package/dist/GroupTransactionEventHandler.js +11 -10
- package/dist/GroupTransactionEvents.d.ts.map +1 -1
- package/dist/ModelChangeEmitter.d.ts +1 -1
- package/dist/ModelChangeEmitter.d.ts.map +1 -1
- package/dist/TransactionEventHandler.d.ts +5 -5
- package/dist/TransactionEventHandler.d.ts.map +1 -1
- package/dist/TransactionEventHandler.js +19 -30
- package/dist/TransactionEvents.d.ts.map +1 -1
- package/dist/UserEventHandler.d.ts +4 -3
- package/dist/UserEventHandler.d.ts.map +1 -1
- package/dist/UserEventHandler.js +16 -40
- package/dist/UserEvents.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMActivityLogEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMActivityLogModelStore.d.ts.map +1 -1
- 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/IMFriendEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMFriendEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMFriendModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMGroupTransactionModelStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMTransactionEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMTransactionModelStore.d.ts +3 -2
- 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/IMUserEventStore.d.ts +1 -2
- package/dist/__tests__/test-helpers/IMUserEventStore.d.ts.map +1 -1
- package/dist/__tests__/test-helpers/IMUserModelStore.d.ts +4 -2
- 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 +18 -0
- package/dist/client/controllers/TransactionController.d.ts.map +1 -0
- package/dist/client/controllers/TransactionController.js +275 -0
- package/dist/client/handlers/UIEventHandler.d.ts +0 -1
- package/dist/client/handlers/UIEventHandler.d.ts.map +1 -1
- package/dist/client/handlers/UIEventHandler.js +4 -62
- 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/DomainEvents.d.ts +0 -70
- package/dist/common/DomainEvents.d.ts.map +1 -1
- package/dist/common/DomainEvents.js +0 -89
- package/dist/contracts/expenses/index.d.ts.map +1 -1
- package/dist/contracts/friends/index.d.ts +1 -9
- package/dist/contracts/friends/index.d.ts.map +1 -1
- package/dist/contracts/groups/index.d.ts.map +1 -1
- package/dist/contracts/transactions/index.d.ts +1 -1
- package/dist/contracts/transactions/index.d.ts.map +1 -1
- package/dist/converters/ActivityLogConverters.d.ts +9 -0
- package/dist/converters/ActivityLogConverters.d.ts.map +1 -0
- package/dist/converters/ActivityLogConverters.js +39 -0
- package/dist/converters/EventConverterCore.d.ts +67 -0
- package/dist/converters/EventConverterCore.d.ts.map +1 -0
- package/dist/converters/EventConverterCore.js +59 -0
- package/dist/converters/FriendConverters.d.ts +33 -0
- package/dist/converters/FriendConverters.d.ts.map +1 -0
- package/dist/converters/FriendConverters.js +142 -0
- package/dist/converters/GroupConverters.d.ts +39 -0
- package/dist/converters/GroupConverters.d.ts.map +1 -0
- package/dist/converters/GroupConverters.js +160 -0
- package/dist/converters/GroupTransactionConverters.d.ts +57 -0
- package/dist/converters/GroupTransactionConverters.d.ts.map +1 -0
- package/dist/converters/GroupTransactionConverters.js +249 -0
- package/dist/converters/TransactionConverters.d.ts +51 -0
- package/dist/converters/TransactionConverters.d.ts.map +1 -0
- package/dist/converters/TransactionConverters.js +234 -0
- package/dist/converters/UserConverters.d.ts +51 -0
- package/dist/converters/UserConverters.d.ts.map +1 -0
- package/dist/converters/UserConverters.js +226 -0
- package/dist/converters/eventConverter.d.ts +10 -15
- package/dist/converters/eventConverter.d.ts.map +1 -1
- package/dist/converters/eventConverter.js +96 -377
- 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 -1
- package/dist/events.d.ts.map +1 -1
- package/dist/events.js +7 -3
- package/dist/index.d.ts +7 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -31
- package/dist/store/ActivityLogModelStore.d.ts.map +1 -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/FriendModelStore.d.ts.map +1 -1
- package/dist/store/GroupModelStore.d.ts.map +1 -1
- package/dist/store/GroupTransactionModelStore.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 +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,11 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
-
const
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
6
6
|
const uuid_1 = require("uuid");
|
|
7
7
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
8
|
-
class GroupEventHandler {
|
|
8
|
+
class GroupEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
9
9
|
constructor(modelStore, friendModelStore, userModelStore, groupEventStore, friendEventStore, activityEventHandler) {
|
|
10
|
+
super();
|
|
10
11
|
this.modelStore = modelStore;
|
|
11
12
|
this.friendModelStore = friendModelStore;
|
|
12
13
|
this.userModelStore = userModelStore;
|
|
@@ -14,17 +15,21 @@ class GroupEventHandler {
|
|
|
14
15
|
this.friendEventStore = friendEventStore;
|
|
15
16
|
this.activityEventHandler = activityEventHandler;
|
|
16
17
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
async handleClientEventFromRemoteListener(event) {
|
|
19
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
20
|
+
const updatedModel = event.apply(existingModel);
|
|
21
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
22
|
+
await this.modelStore.save(updatedModel);
|
|
23
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
24
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
25
|
+
}
|
|
20
26
|
}
|
|
21
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
22
|
-
existingModel.version === updatedModel.version);
|
|
23
27
|
}
|
|
24
28
|
async handleEvent(event) {
|
|
25
29
|
const eventType = event.constructor.name;
|
|
26
|
-
if (
|
|
27
|
-
|
|
30
|
+
if (_1.residence.isClient) {
|
|
31
|
+
const user = await this.userModelStore.appUser();
|
|
32
|
+
this.currentUserId = user.userId;
|
|
28
33
|
}
|
|
29
34
|
switch (eventType) {
|
|
30
35
|
case "GroupCreated":
|
|
@@ -69,9 +74,7 @@ class GroupEventHandler {
|
|
|
69
74
|
});
|
|
70
75
|
await this.friendEventStore.addEvent(friendCreatedEvent);
|
|
71
76
|
const friendModel = friendCreatedEvent.apply(undefined);
|
|
72
|
-
|
|
73
|
-
await this.friendModelStore.save(friendModel);
|
|
74
|
-
}
|
|
77
|
+
await this.friendModelStore.save(friendModel);
|
|
75
78
|
}
|
|
76
79
|
const existingFriend2to1 = await this.friendModelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId2, userId1);
|
|
77
80
|
if (!existingFriend2to1) {
|
|
@@ -100,125 +103,131 @@ class GroupEventHandler {
|
|
|
100
103
|
async handleGroupCreated(event) {
|
|
101
104
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
102
105
|
const updatedModel = event.apply(existingModel);
|
|
103
|
-
if (
|
|
104
|
-
|
|
105
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
106
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
107
|
-
}
|
|
106
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
107
|
+
return existingModel;
|
|
108
108
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (
|
|
114
|
-
|
|
115
|
-
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);
|
|
116
115
|
}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
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;
|
|
120
125
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
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);
|
|
139
147
|
await this.modelStore.save(perspectiveModel);
|
|
140
|
-
if (
|
|
141
|
-
|
|
148
|
+
if (this.activityEventHandler) {
|
|
149
|
+
await this.activityEventHandler.createActivityLog(perspectiveGroupCreated, undefined, perspectiveModel);
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
}
|
|
145
|
-
if (this.activityEventHandler) {
|
|
146
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
147
|
-
}
|
|
148
153
|
return updatedModel;
|
|
149
154
|
}
|
|
150
155
|
async handleGroupNameChanged(event) {
|
|
151
156
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
152
157
|
const updatedModel = event.apply(existingModel);
|
|
153
|
-
if (
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
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);
|
|
157
167
|
}
|
|
158
168
|
}
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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);
|
|
175
185
|
await this.modelStore.save(updatedPerspective);
|
|
176
|
-
if (
|
|
177
|
-
|
|
186
|
+
if (this.activityEventHandler) {
|
|
187
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
178
188
|
}
|
|
179
189
|
}
|
|
180
190
|
}
|
|
181
191
|
}
|
|
182
|
-
if (this.activityEventHandler) {
|
|
183
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
184
|
-
}
|
|
185
192
|
return updatedModel;
|
|
186
193
|
}
|
|
187
194
|
async handleGroupDescriptionChanged(event) {
|
|
188
195
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
189
196
|
const updatedModel = event.apply(existingModel);
|
|
190
|
-
if (
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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);
|
|
194
206
|
}
|
|
195
207
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
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);
|
|
212
224
|
await this.modelStore.save(updatedPerspective);
|
|
213
|
-
if (
|
|
214
|
-
|
|
225
|
+
if (this.activityEventHandler) {
|
|
226
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
215
227
|
}
|
|
216
228
|
}
|
|
217
229
|
}
|
|
218
230
|
}
|
|
219
|
-
if (this.activityEventHandler) {
|
|
220
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
221
|
-
}
|
|
222
231
|
return updatedModel;
|
|
223
232
|
}
|
|
224
233
|
async handleGroupMembersAdded(event) {
|
|
@@ -227,124 +236,170 @@ class GroupEventHandler {
|
|
|
227
236
|
throw new Error(`Group model not found for streamId ${event.streamId}`);
|
|
228
237
|
}
|
|
229
238
|
const updatedModel = event.apply(existingModel);
|
|
230
|
-
if (
|
|
231
|
-
|
|
232
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
233
|
-
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupModel", updatedModel);
|
|
234
|
-
}
|
|
239
|
+
if (this.shouldSkipSave(existingModel, updatedModel)) {
|
|
240
|
+
return existingModel;
|
|
235
241
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
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);
|
|
242
248
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
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;
|
|
246
257
|
}
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
userId: memberId,
|
|
252
|
-
groupId: existingModel.groupId,
|
|
253
|
-
name: existingModel.name,
|
|
254
|
-
description: existingModel.description,
|
|
255
|
-
members: updatedModel.members,
|
|
256
|
-
createdAt: new Date(),
|
|
257
|
-
createdBy: memberId,
|
|
258
|
-
streamId: perspectiveGroupStreamId,
|
|
259
|
-
version: 1,
|
|
260
|
-
systemGenerated: true,
|
|
261
|
-
});
|
|
262
|
-
await this.groupEventStore.addEvent(perspectiveGroupCreated);
|
|
263
|
-
const perspectiveModel = perspectiveGroupCreated.apply(undefined);
|
|
264
|
-
if (!this.shouldSkipSave(undefined, perspectiveModel)) {
|
|
265
|
-
await this.modelStore.save(perspectiveModel);
|
|
266
|
-
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
267
|
-
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
|
+
}
|
|
268
262
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
const allPerspectives = await this.modelStore.findAllByGroupIdAndDeletedIsFalse(updatedModel.groupId);
|
|
272
|
-
for (const perspective of allPerspectives) {
|
|
273
|
-
if (perspective.streamId !== event.streamId &&
|
|
274
|
-
!event.members.includes(perspective.userId)) {
|
|
275
|
-
const perspectiveEvent = new _1.GroupMembersAdded({
|
|
263
|
+
const perspectiveGroupStreamId = (0, uuid_1.v4)();
|
|
264
|
+
const perspectiveGroupCreated = new _1.GroupCreated({
|
|
276
265
|
eventId: (0, uuid_1.v4)(),
|
|
277
|
-
userId:
|
|
278
|
-
|
|
266
|
+
userId: memberId,
|
|
267
|
+
groupId: existingModel.groupId,
|
|
268
|
+
name: existingModel.name,
|
|
269
|
+
description: existingModel.description,
|
|
270
|
+
members: updatedModel.members,
|
|
279
271
|
createdAt: new Date(),
|
|
280
|
-
createdBy:
|
|
281
|
-
streamId:
|
|
282
|
-
version:
|
|
272
|
+
createdBy: memberId,
|
|
273
|
+
streamId: perspectiveGroupStreamId,
|
|
274
|
+
version: 1,
|
|
283
275
|
systemGenerated: true,
|
|
284
276
|
});
|
|
285
|
-
await this.groupEventStore.addEvent(
|
|
286
|
-
const
|
|
287
|
-
|
|
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);
|
|
288
300
|
await this.modelStore.save(updatedPerspective);
|
|
289
|
-
if (
|
|
290
|
-
|
|
301
|
+
if (this.activityEventHandler) {
|
|
302
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
291
303
|
}
|
|
292
304
|
}
|
|
293
305
|
}
|
|
294
306
|
}
|
|
295
|
-
if (this.activityEventHandler) {
|
|
296
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
297
|
-
}
|
|
298
307
|
return updatedModel;
|
|
299
308
|
}
|
|
300
309
|
async handleGroupMembersRemoved(event) {
|
|
301
310
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
302
311
|
const updatedModel = event.apply(existingModel);
|
|
303
|
-
if (
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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);
|
|
307
321
|
}
|
|
308
322
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
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);
|
|
325
359
|
await this.modelStore.save(updatedPerspective);
|
|
326
|
-
if (
|
|
327
|
-
|
|
360
|
+
if (this.activityEventHandler) {
|
|
361
|
+
await this.activityEventHandler.createActivityLog(perspectiveEvent, perspective, updatedPerspective);
|
|
328
362
|
}
|
|
329
363
|
}
|
|
330
364
|
}
|
|
331
365
|
}
|
|
332
|
-
if (this.activityEventHandler) {
|
|
333
|
-
await this.activityEventHandler.createActivityLog(event, existingModel, updatedModel);
|
|
334
|
-
}
|
|
335
366
|
return updatedModel;
|
|
336
367
|
}
|
|
337
368
|
async handleGroupDeleted(event) {
|
|
338
369
|
const existingModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(event.streamId);
|
|
339
370
|
const updatedModel = event.apply(existingModel);
|
|
340
|
-
if (
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
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);
|
|
344
380
|
}
|
|
345
381
|
}
|
|
346
|
-
|
|
347
|
-
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
|
+
}
|
|
348
403
|
}
|
|
349
404
|
return updatedModel;
|
|
350
405
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GroupEvents.d.ts","sourceRoot":"","sources":["../src/GroupEvents.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GroupEvents.d.ts","sourceRoot":"","sources":["../src/GroupEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,g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AK,EAChB,SAAS,CAAC,EAAE,MAAM,GACnB,uBAAuB,GAAG,SAAS;CAwBzC"}
|
|
@@ -4,8 +4,9 @@ import { GroupTransactionEventStore } from ".";
|
|
|
4
4
|
import { GroupModelStore } from ".";
|
|
5
5
|
import { TransactionEventStore } from ".";
|
|
6
6
|
import { TransactionModelStore } from ".";
|
|
7
|
+
import { BaseEventHandler } from "./BaseEventHandler";
|
|
7
8
|
import { ActivityEventHandler } from "./ActivityEventHandler";
|
|
8
|
-
export declare class GroupTransactionEventHandler {
|
|
9
|
+
export declare class GroupTransactionEventHandler extends BaseEventHandler<GroupTransactionEvent> {
|
|
9
10
|
private modelStore;
|
|
10
11
|
private eventStore;
|
|
11
12
|
private groupModelStore;
|
|
@@ -13,7 +14,7 @@ export declare class GroupTransactionEventHandler {
|
|
|
13
14
|
private transactionModelStore;
|
|
14
15
|
private activityEventHandler?;
|
|
15
16
|
constructor(modelStore: GroupTransactionModelStore, eventStore: GroupTransactionEventStore, groupModelStore: GroupModelStore, transactionEventStore: TransactionEventStore, transactionModelStore: TransactionModelStore, activityEventHandler?: ActivityEventHandler | undefined);
|
|
16
|
-
|
|
17
|
+
handleClientEventFromRemoteListener(event: GroupTransactionEvent): Promise<void>;
|
|
17
18
|
handleEvent(event: GroupTransactionEvent): Promise<GroupTransactionModel>;
|
|
18
19
|
private calculateNetBalances;
|
|
19
20
|
private createFriendTransactions;
|
|
@@ -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,CA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B,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,12 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GroupTransactionEventHandler = void 0;
|
|
4
4
|
const _1 = require(".");
|
|
5
|
-
const
|
|
5
|
+
const BaseEventHandler_1 = require("./BaseEventHandler");
|
|
6
6
|
const splitTypeUtils_1 = require("./utils/splitTypeUtils");
|
|
7
7
|
const uuid_1 = require("uuid");
|
|
8
8
|
const EventProcessorSDK_1 = require("./EventProcessorSDK");
|
|
9
|
-
class GroupTransactionEventHandler {
|
|
9
|
+
class GroupTransactionEventHandler extends BaseEventHandler_1.BaseEventHandler {
|
|
10
10
|
constructor(modelStore, eventStore, groupModelStore, transactionEventStore, transactionModelStore, activityEventHandler) {
|
|
11
|
+
super();
|
|
11
12
|
this.modelStore = modelStore;
|
|
12
13
|
this.eventStore = eventStore;
|
|
13
14
|
this.groupModelStore = groupModelStore;
|
|
@@ -15,21 +16,21 @@ class GroupTransactionEventHandler {
|
|
|
15
16
|
this.transactionModelStore = transactionModelStore;
|
|
16
17
|
this.activityEventHandler = activityEventHandler;
|
|
17
18
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
async handleClientEventFromRemoteListener(event) {
|
|
20
|
+
const existingModel = await this.modelStore.getByStreamId(event.streamId);
|
|
21
|
+
const updatedModel = event.apply(existingModel);
|
|
22
|
+
if (!this.shouldSkipSave(existingModel, updatedModel)) {
|
|
23
|
+
await this.modelStore.save(updatedModel);
|
|
24
|
+
if ((0, EventProcessorSDK_1.isSDKInitialized)()) {
|
|
25
|
+
EventProcessorSDK_1.EventProcessorSDK.getInstance().emitModelChange("GroupTransactionModel", updatedModel);
|
|
26
|
+
}
|
|
21
27
|
}
|
|
22
|
-
return (existingModel.streamId === updatedModel.streamId &&
|
|
23
|
-
existingModel.version === updatedModel.version);
|
|
24
28
|
}
|
|
25
29
|
async handleEvent(event) {
|
|
26
30
|
if (_1.residence.isClient) {
|
|
27
31
|
await this.eventStore.addEvent(event);
|
|
28
32
|
}
|
|
29
33
|
const eventType = event.constructor.name;
|
|
30
|
-
if (!(0, DomainEvents_1.isValidGroupTransactionEventType)(eventType)) {
|
|
31
|
-
throw new Error(`Unknown group transaction event type: ${eventType}`);
|
|
32
|
-
}
|
|
33
34
|
switch (eventType) {
|
|
34
35
|
case "GroupTransactionCreated":
|
|
35
36
|
return await this.handleGroupTransactionCreated(event);
|