@zeeshan60/event-processor 1.0.1 → 1.0.3
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/dist/ActivityLogEvents.d.ts +43 -0
- package/dist/ActivityLogEvents.d.ts.map +1 -0
- package/dist/ActivityLogEvents.js +39 -0
- package/dist/FriendEvents.d.ts +122 -0
- package/dist/FriendEvents.d.ts.map +1 -0
- package/dist/FriendEvents.js +213 -0
- package/dist/GroupEvents.d.ts +140 -0
- package/dist/GroupEvents.d.ts.map +1 -0
- package/dist/GroupEvents.js +289 -0
- package/dist/GroupTransactionEvents.d.ts +228 -0
- package/dist/GroupTransactionEvents.d.ts.map +1 -0
- package/dist/GroupTransactionEvents.js +438 -0
- package/dist/TransactionEvents.d.ts +98 -56
- package/dist/TransactionEvents.d.ts.map +1 -1
- package/dist/TransactionEvents.js +345 -26
- package/dist/UserEvents.d.ts +54 -49
- package/dist/UserEvents.d.ts.map +1 -1
- package/dist/UserEvents.js +108 -8
- package/dist/common/Event.d.ts +3 -2
- package/dist/common/Event.d.ts.map +1 -1
- package/dist/common/Model.d.ts +0 -1
- package/dist/common/Model.d.ts.map +1 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -3
- package/package.json +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionEvents.d.ts","sourceRoot":"","sources":["../src/TransactionEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"TransactionEvents.d.ts","sourceRoot":"","sources":["../src/TransactionEvents.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,uB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EAAE,KAAK,GAAG,gBAAgB;IA4CzC,WAAW,CAAC,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,uBAAuB,GAAG,SAAS;CAsBvF"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.TransactionDetailsChanged = exports.TransactionDateChanged = exports.CurrencyChanged = exports.SplitTypeChanged = exports.TotalAmountChanged = exports.DescriptionChanged = exports.TransactionDeleted = exports.TransactionCreated = exports.ChangeHistory = exports.TransactionEventType = exports.SplitType = void 0;
|
|
4
|
+
const ActivityLogEvents_1 = require("./ActivityLogEvents");
|
|
5
|
+
const uuid_1 = require("uuid");
|
|
4
6
|
// Enums
|
|
5
7
|
var SplitType;
|
|
6
8
|
(function (SplitType) {
|
|
@@ -36,6 +38,7 @@ class TransactionCreated {
|
|
|
36
38
|
this.splitType = props.splitType;
|
|
37
39
|
this.totalAmount = props.totalAmount;
|
|
38
40
|
this.amount = props.amount;
|
|
41
|
+
this.isOwed = props.isOwed;
|
|
39
42
|
this.transactionDate = props.transactionDate;
|
|
40
43
|
this.groupId = props.groupId;
|
|
41
44
|
this.groupTransactionId = props.groupTransactionId;
|
|
@@ -45,8 +48,10 @@ class TransactionCreated {
|
|
|
45
48
|
this.version = props.version;
|
|
46
49
|
}
|
|
47
50
|
apply(_existing) {
|
|
51
|
+
if (!this.userId) {
|
|
52
|
+
throw new Error('userId is required for TransactionModel');
|
|
53
|
+
}
|
|
48
54
|
return {
|
|
49
|
-
id: null,
|
|
50
55
|
streamId: this.streamId,
|
|
51
56
|
logicalTransactionId: this.logicalTransactionId,
|
|
52
57
|
userId: this.userId,
|
|
@@ -56,6 +61,7 @@ class TransactionCreated {
|
|
|
56
61
|
splitType: this.splitType,
|
|
57
62
|
totalAmount: this.totalAmount,
|
|
58
63
|
amount: this.amount,
|
|
64
|
+
isOwed: this.isOwed,
|
|
59
65
|
transactionDate: this.transactionDate,
|
|
60
66
|
createdAt: this.createdAt,
|
|
61
67
|
updatedAt: this.createdAt,
|
|
@@ -68,27 +74,29 @@ class TransactionCreated {
|
|
|
68
74
|
history: ChangeHistory.empty(),
|
|
69
75
|
};
|
|
70
76
|
}
|
|
77
|
+
activityLog(_existing, actorName) {
|
|
78
|
+
if (!this.userId) {
|
|
79
|
+
return undefined;
|
|
80
|
+
}
|
|
81
|
+
const actor = actorName ?? 'You';
|
|
82
|
+
const logMessage = `${actor} created transaction "${this.description}" for ${this.totalAmount} ${this.currency}`;
|
|
83
|
+
return {
|
|
84
|
+
userId: this.userId,
|
|
85
|
+
activityByUid: this.createdBy,
|
|
86
|
+
sourceStreamId: this.streamId,
|
|
87
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
88
|
+
logMessage,
|
|
89
|
+
date: this.transactionDate,
|
|
90
|
+
createdAt: this.createdAt,
|
|
91
|
+
createdBy: this.createdBy,
|
|
92
|
+
streamId: (0, uuid_1.v4)(),
|
|
93
|
+
version: 1,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
71
96
|
}
|
|
72
97
|
exports.TransactionCreated = TransactionCreated;
|
|
73
|
-
var TransactionChangeType;
|
|
74
|
-
(function (TransactionChangeType) {
|
|
75
|
-
TransactionChangeType["TRANSACTION_DATE"] = "TRANSACTION_DATE";
|
|
76
|
-
TransactionChangeType["DESCRIPTION"] = "DESCRIPTION";
|
|
77
|
-
TransactionChangeType["TOTAL_AMOUNT"] = "TOTAL_AMOUNT";
|
|
78
|
-
TransactionChangeType["CURRENCY"] = "CURRENCY";
|
|
79
|
-
TransactionChangeType["SPLIT_TYPE"] = "SPLIT_TYPE";
|
|
80
|
-
TransactionChangeType["DELETED"] = "DELETED";
|
|
81
|
-
})(TransactionChangeType || (exports.TransactionChangeType = TransactionChangeType = {}));
|
|
82
|
-
var ActivityType;
|
|
83
|
-
(function (ActivityType) {
|
|
84
|
-
ActivityType["CREATED"] = "CREATED";
|
|
85
|
-
ActivityType["UPDATED"] = "UPDATED";
|
|
86
|
-
ActivityType["DELETED"] = "DELETED";
|
|
87
|
-
})(ActivityType || (exports.ActivityType = ActivityType = {}));
|
|
88
98
|
class TransactionDeleted {
|
|
89
99
|
constructor(props) {
|
|
90
|
-
this.userId = props.userId;
|
|
91
|
-
this.recipientUserId = props.recipientUserId;
|
|
92
100
|
this.streamId = props.streamId;
|
|
93
101
|
this.version = props.version;
|
|
94
102
|
this.createdAt = props.createdAt;
|
|
@@ -96,7 +104,7 @@ class TransactionDeleted {
|
|
|
96
104
|
}
|
|
97
105
|
apply(existing) {
|
|
98
106
|
if (!existing) {
|
|
99
|
-
throw new Error('TransactionModel
|
|
107
|
+
throw new Error('TransactionModel is required for deletion');
|
|
100
108
|
}
|
|
101
109
|
const existingTx = existing;
|
|
102
110
|
return {
|
|
@@ -107,12 +115,30 @@ class TransactionDeleted {
|
|
|
107
115
|
updatedAt: this.createdAt,
|
|
108
116
|
};
|
|
109
117
|
}
|
|
118
|
+
activityLog(existing, actorName) {
|
|
119
|
+
if (!existing) {
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
const existingTx = existing;
|
|
123
|
+
const actor = actorName ?? 'You';
|
|
124
|
+
const logMessage = `${actor} deleted transaction "${existingTx.description}"`;
|
|
125
|
+
return {
|
|
126
|
+
userId: existingTx.userId,
|
|
127
|
+
activityByUid: this.createdBy,
|
|
128
|
+
sourceStreamId: this.streamId,
|
|
129
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
130
|
+
logMessage,
|
|
131
|
+
date: this.createdAt,
|
|
132
|
+
createdAt: this.createdAt,
|
|
133
|
+
createdBy: this.createdBy,
|
|
134
|
+
streamId: (0, uuid_1.v4)(),
|
|
135
|
+
version: 1,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
110
138
|
}
|
|
111
139
|
exports.TransactionDeleted = TransactionDeleted;
|
|
112
140
|
class DescriptionChanged {
|
|
113
141
|
constructor(props) {
|
|
114
|
-
this.userId = props.userId;
|
|
115
|
-
this.recipientUserId = props.recipientUserId;
|
|
116
142
|
this.description = props.description;
|
|
117
143
|
this.streamId = props.streamId;
|
|
118
144
|
this.version = props.version;
|
|
@@ -121,23 +147,51 @@ class DescriptionChanged {
|
|
|
121
147
|
}
|
|
122
148
|
apply(existing) {
|
|
123
149
|
if (!existing) {
|
|
124
|
-
throw new Error('TransactionModel
|
|
150
|
+
throw new Error('TransactionModel is required');
|
|
125
151
|
}
|
|
126
152
|
const existingTx = existing;
|
|
153
|
+
const descriptionChange = {
|
|
154
|
+
type: 'DESCRIPTION_UPDATED',
|
|
155
|
+
changedAt: this.createdAt,
|
|
156
|
+
changedBy: this.createdBy,
|
|
157
|
+
oldValue: existingTx.description,
|
|
158
|
+
newValue: this.description,
|
|
159
|
+
};
|
|
127
160
|
return {
|
|
128
161
|
...existingTx,
|
|
129
162
|
description: this.description,
|
|
130
163
|
version: this.version,
|
|
131
164
|
updatedBy: this.createdBy,
|
|
132
165
|
updatedAt: this.createdAt,
|
|
166
|
+
history: {
|
|
167
|
+
changes: [descriptionChange, ...existingTx.history.changes],
|
|
168
|
+
},
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
activityLog(existing, actorName) {
|
|
172
|
+
if (!existing) {
|
|
173
|
+
return undefined;
|
|
174
|
+
}
|
|
175
|
+
const existingTx = existing;
|
|
176
|
+
const actor = actorName ?? 'You';
|
|
177
|
+
const logMessage = `${actor} changed description from "${existingTx.description}" to "${this.description}"`;
|
|
178
|
+
return {
|
|
179
|
+
userId: existingTx.userId,
|
|
180
|
+
activityByUid: this.createdBy,
|
|
181
|
+
sourceStreamId: this.streamId,
|
|
182
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
183
|
+
logMessage,
|
|
184
|
+
date: this.createdAt,
|
|
185
|
+
createdAt: this.createdAt,
|
|
186
|
+
createdBy: this.createdBy,
|
|
187
|
+
streamId: (0, uuid_1.v4)(),
|
|
188
|
+
version: 1,
|
|
133
189
|
};
|
|
134
190
|
}
|
|
135
191
|
}
|
|
136
192
|
exports.DescriptionChanged = DescriptionChanged;
|
|
137
193
|
class TotalAmountChanged {
|
|
138
194
|
constructor(props) {
|
|
139
|
-
this.userId = props.userId;
|
|
140
|
-
this.recipientUserId = props.recipientUserId;
|
|
141
195
|
this.totalAmount = props.totalAmount;
|
|
142
196
|
this.streamId = props.streamId;
|
|
143
197
|
this.version = props.version;
|
|
@@ -146,16 +200,281 @@ class TotalAmountChanged {
|
|
|
146
200
|
}
|
|
147
201
|
apply(existing) {
|
|
148
202
|
if (!existing) {
|
|
149
|
-
throw new Error('TransactionModel
|
|
203
|
+
throw new Error('TransactionModel is required');
|
|
150
204
|
}
|
|
151
205
|
const existingTx = existing;
|
|
206
|
+
const amountChange = {
|
|
207
|
+
type: 'AMOUNT_UPDATED',
|
|
208
|
+
changedAt: this.createdAt,
|
|
209
|
+
changedBy: this.createdBy,
|
|
210
|
+
oldValue: existingTx.totalAmount,
|
|
211
|
+
newValue: this.totalAmount,
|
|
212
|
+
};
|
|
152
213
|
return {
|
|
153
214
|
...existingTx,
|
|
154
215
|
totalAmount: this.totalAmount,
|
|
155
216
|
version: this.version,
|
|
156
217
|
updatedBy: this.createdBy,
|
|
157
218
|
updatedAt: this.createdAt,
|
|
219
|
+
history: {
|
|
220
|
+
changes: [amountChange, ...existingTx.history.changes],
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
activityLog(existing, actorName) {
|
|
225
|
+
if (!existing) {
|
|
226
|
+
return undefined;
|
|
227
|
+
}
|
|
228
|
+
const existingTx = existing;
|
|
229
|
+
const actor = actorName ?? 'You';
|
|
230
|
+
const logMessage = `${actor} changed amount from ${existingTx.totalAmount} ${existingTx.currency} to ${this.totalAmount} ${existingTx.currency}`;
|
|
231
|
+
return {
|
|
232
|
+
userId: existingTx.userId,
|
|
233
|
+
activityByUid: this.createdBy,
|
|
234
|
+
sourceStreamId: this.streamId,
|
|
235
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
236
|
+
logMessage,
|
|
237
|
+
date: this.createdAt,
|
|
238
|
+
createdAt: this.createdAt,
|
|
239
|
+
createdBy: this.createdBy,
|
|
240
|
+
streamId: (0, uuid_1.v4)(),
|
|
241
|
+
version: 1,
|
|
158
242
|
};
|
|
159
243
|
}
|
|
160
244
|
}
|
|
161
245
|
exports.TotalAmountChanged = TotalAmountChanged;
|
|
246
|
+
class SplitTypeChanged {
|
|
247
|
+
constructor(props) {
|
|
248
|
+
this.splitType = props.splitType;
|
|
249
|
+
this.totalAmount = props.totalAmount;
|
|
250
|
+
this.amount = props.amount;
|
|
251
|
+
this.isOwed = props.isOwed;
|
|
252
|
+
this.streamId = props.streamId;
|
|
253
|
+
this.version = props.version;
|
|
254
|
+
this.createdAt = props.createdAt;
|
|
255
|
+
this.createdBy = props.createdBy;
|
|
256
|
+
}
|
|
257
|
+
apply(existing) {
|
|
258
|
+
if (!existing) {
|
|
259
|
+
throw new Error('TransactionModel is required');
|
|
260
|
+
}
|
|
261
|
+
const existingTx = existing;
|
|
262
|
+
const splitTypeChange = {
|
|
263
|
+
type: 'SPLIT_TYPE_UPDATED',
|
|
264
|
+
changedAt: this.createdAt,
|
|
265
|
+
changedBy: this.createdBy,
|
|
266
|
+
oldValue: existingTx.splitType,
|
|
267
|
+
newValue: this.splitType,
|
|
268
|
+
};
|
|
269
|
+
return {
|
|
270
|
+
...existingTx,
|
|
271
|
+
splitType: this.splitType,
|
|
272
|
+
amount: this.amount,
|
|
273
|
+
isOwed: this.isOwed,
|
|
274
|
+
version: this.version,
|
|
275
|
+
updatedBy: this.createdBy,
|
|
276
|
+
updatedAt: this.createdAt,
|
|
277
|
+
history: {
|
|
278
|
+
changes: [splitTypeChange, ...existingTx.history.changes],
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
activityLog(existing, actorName) {
|
|
283
|
+
if (!existing) {
|
|
284
|
+
return undefined;
|
|
285
|
+
}
|
|
286
|
+
const existingTx = existing;
|
|
287
|
+
const actor = actorName ?? 'You';
|
|
288
|
+
const logMessage = `${actor} changed split type from ${existingTx.splitType} to ${this.splitType}`;
|
|
289
|
+
return {
|
|
290
|
+
userId: existingTx.userId,
|
|
291
|
+
activityByUid: this.createdBy,
|
|
292
|
+
sourceStreamId: this.streamId,
|
|
293
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
294
|
+
logMessage,
|
|
295
|
+
date: this.createdAt,
|
|
296
|
+
createdAt: this.createdAt,
|
|
297
|
+
createdBy: this.createdBy,
|
|
298
|
+
streamId: (0, uuid_1.v4)(),
|
|
299
|
+
version: 1,
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
exports.SplitTypeChanged = SplitTypeChanged;
|
|
304
|
+
class CurrencyChanged {
|
|
305
|
+
constructor(props) {
|
|
306
|
+
this.currency = props.currency;
|
|
307
|
+
this.streamId = props.streamId;
|
|
308
|
+
this.version = props.version;
|
|
309
|
+
this.createdAt = props.createdAt;
|
|
310
|
+
this.createdBy = props.createdBy;
|
|
311
|
+
}
|
|
312
|
+
apply(existing) {
|
|
313
|
+
if (!existing) {
|
|
314
|
+
throw new Error('TransactionModel is required');
|
|
315
|
+
}
|
|
316
|
+
const existingTx = existing;
|
|
317
|
+
const currencyChange = {
|
|
318
|
+
type: 'CURRENCY_UPDATED',
|
|
319
|
+
changedAt: this.createdAt,
|
|
320
|
+
changedBy: this.createdBy,
|
|
321
|
+
oldValue: existingTx.currency,
|
|
322
|
+
newValue: this.currency,
|
|
323
|
+
};
|
|
324
|
+
return {
|
|
325
|
+
...existingTx,
|
|
326
|
+
currency: this.currency,
|
|
327
|
+
version: this.version,
|
|
328
|
+
updatedBy: this.createdBy,
|
|
329
|
+
updatedAt: this.createdAt,
|
|
330
|
+
history: {
|
|
331
|
+
changes: [currencyChange, ...existingTx.history.changes],
|
|
332
|
+
},
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
activityLog(existing, actorName) {
|
|
336
|
+
if (!existing) {
|
|
337
|
+
return undefined;
|
|
338
|
+
}
|
|
339
|
+
const existingTx = existing;
|
|
340
|
+
const actor = actorName ?? 'You';
|
|
341
|
+
const logMessage = `${actor} changed currency from ${existingTx.currency} to ${this.currency}`;
|
|
342
|
+
return {
|
|
343
|
+
userId: existingTx.userId,
|
|
344
|
+
activityByUid: this.createdBy,
|
|
345
|
+
sourceStreamId: this.streamId,
|
|
346
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
347
|
+
logMessage,
|
|
348
|
+
date: this.createdAt,
|
|
349
|
+
createdAt: this.createdAt,
|
|
350
|
+
createdBy: this.createdBy,
|
|
351
|
+
streamId: (0, uuid_1.v4)(),
|
|
352
|
+
version: 1,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
exports.CurrencyChanged = CurrencyChanged;
|
|
357
|
+
class TransactionDateChanged {
|
|
358
|
+
constructor(props) {
|
|
359
|
+
this.transactionDate = props.transactionDate;
|
|
360
|
+
this.streamId = props.streamId;
|
|
361
|
+
this.version = props.version;
|
|
362
|
+
this.createdAt = props.createdAt;
|
|
363
|
+
this.createdBy = props.createdBy;
|
|
364
|
+
}
|
|
365
|
+
apply(existing) {
|
|
366
|
+
if (!existing) {
|
|
367
|
+
throw new Error('TransactionModel is required');
|
|
368
|
+
}
|
|
369
|
+
const existingTx = existing;
|
|
370
|
+
const dateChange = {
|
|
371
|
+
type: 'TRANSACTION_DATE_UPDATED',
|
|
372
|
+
changedAt: this.createdAt,
|
|
373
|
+
changedBy: this.createdBy,
|
|
374
|
+
oldValue: existingTx.transactionDate,
|
|
375
|
+
newValue: this.transactionDate,
|
|
376
|
+
};
|
|
377
|
+
return {
|
|
378
|
+
...existingTx,
|
|
379
|
+
transactionDate: this.transactionDate,
|
|
380
|
+
version: this.version,
|
|
381
|
+
updatedBy: this.createdBy,
|
|
382
|
+
updatedAt: this.createdAt,
|
|
383
|
+
history: {
|
|
384
|
+
changes: [dateChange, ...existingTx.history.changes],
|
|
385
|
+
},
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
activityLog(existing, actorName) {
|
|
389
|
+
if (!existing) {
|
|
390
|
+
return undefined;
|
|
391
|
+
}
|
|
392
|
+
const existingTx = existing;
|
|
393
|
+
const actor = actorName ?? 'You';
|
|
394
|
+
const logMessage = `${actor} changed transaction date from ${existingTx.transactionDate.toLocaleDateString()} to ${this.transactionDate.toLocaleDateString()}`;
|
|
395
|
+
return {
|
|
396
|
+
userId: existingTx.userId,
|
|
397
|
+
activityByUid: this.createdBy,
|
|
398
|
+
sourceStreamId: this.streamId,
|
|
399
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
400
|
+
logMessage,
|
|
401
|
+
date: this.createdAt,
|
|
402
|
+
createdAt: this.createdAt,
|
|
403
|
+
createdBy: this.createdBy,
|
|
404
|
+
streamId: (0, uuid_1.v4)(),
|
|
405
|
+
version: 1,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
exports.TransactionDateChanged = TransactionDateChanged;
|
|
410
|
+
class TransactionDetailsChanged {
|
|
411
|
+
constructor(props) {
|
|
412
|
+
this.totalAmount = props.totalAmount;
|
|
413
|
+
this.amount = props.amount;
|
|
414
|
+
this.isOwed = props.isOwed;
|
|
415
|
+
this.streamId = props.streamId;
|
|
416
|
+
this.version = props.version;
|
|
417
|
+
this.createdAt = props.createdAt;
|
|
418
|
+
this.createdBy = props.createdBy;
|
|
419
|
+
}
|
|
420
|
+
apply(existing) {
|
|
421
|
+
if (!existing) {
|
|
422
|
+
throw new Error('TransactionModel is required');
|
|
423
|
+
}
|
|
424
|
+
const existingTx = existing;
|
|
425
|
+
const changes = [];
|
|
426
|
+
if (existingTx.totalAmount !== this.totalAmount) {
|
|
427
|
+
const totalAmountChange = {
|
|
428
|
+
type: 'AMOUNT_UPDATED',
|
|
429
|
+
changedAt: this.createdAt,
|
|
430
|
+
changedBy: this.createdBy,
|
|
431
|
+
oldValue: existingTx.totalAmount,
|
|
432
|
+
newValue: this.totalAmount,
|
|
433
|
+
};
|
|
434
|
+
changes.push(totalAmountChange);
|
|
435
|
+
}
|
|
436
|
+
if (existingTx.amount !== this.amount) {
|
|
437
|
+
const amountChange = {
|
|
438
|
+
type: 'AMOUNT_UPDATED',
|
|
439
|
+
changedAt: this.createdAt,
|
|
440
|
+
changedBy: this.createdBy,
|
|
441
|
+
oldValue: existingTx.amount,
|
|
442
|
+
newValue: this.amount,
|
|
443
|
+
};
|
|
444
|
+
changes.push(amountChange);
|
|
445
|
+
}
|
|
446
|
+
return {
|
|
447
|
+
...existingTx,
|
|
448
|
+
totalAmount: this.totalAmount,
|
|
449
|
+
amount: this.amount,
|
|
450
|
+
isOwed: this.isOwed,
|
|
451
|
+
version: this.version,
|
|
452
|
+
updatedBy: this.createdBy,
|
|
453
|
+
updatedAt: this.createdAt,
|
|
454
|
+
history: {
|
|
455
|
+
changes: [...changes, ...existingTx.history.changes],
|
|
456
|
+
},
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
activityLog(existing, actorName) {
|
|
460
|
+
if (!existing) {
|
|
461
|
+
return undefined;
|
|
462
|
+
}
|
|
463
|
+
const existingTx = existing;
|
|
464
|
+
const actor = actorName ?? 'You';
|
|
465
|
+
const logMessage = `${actor} updated transaction details`;
|
|
466
|
+
return {
|
|
467
|
+
userId: existingTx.userId,
|
|
468
|
+
activityByUid: this.createdBy,
|
|
469
|
+
sourceStreamId: this.streamId,
|
|
470
|
+
sourceType: ActivityLogEvents_1.SourceType.Transaction,
|
|
471
|
+
logMessage,
|
|
472
|
+
date: this.createdAt,
|
|
473
|
+
createdAt: this.createdAt,
|
|
474
|
+
createdBy: this.createdBy,
|
|
475
|
+
streamId: (0, uuid_1.v4)(),
|
|
476
|
+
version: 1,
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
exports.TransactionDetailsChanged = TransactionDetailsChanged;
|