@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
|
@@ -4,18 +4,44 @@ exports.FriendController = void 0;
|
|
|
4
4
|
const FriendEvents_1 = require("../../FriendEvents");
|
|
5
5
|
const uuid_1 = require("uuid");
|
|
6
6
|
const EventProcessorSDK_1 = require("../../EventProcessorSDK");
|
|
7
|
+
const BalanceUtil_1 = require("../../utils/BalanceUtil");
|
|
7
8
|
class FriendController {
|
|
8
9
|
get modelStore() {
|
|
9
10
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
10
11
|
.friendModelStore;
|
|
11
12
|
}
|
|
13
|
+
get transactionModelStore() {
|
|
14
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
15
|
+
.transactionModelStore;
|
|
16
|
+
}
|
|
17
|
+
get userModelStore() {
|
|
18
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().userModelStore;
|
|
19
|
+
}
|
|
20
|
+
get currencyStore() {
|
|
21
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().currencyStore;
|
|
22
|
+
}
|
|
12
23
|
get friendEventHandler() {
|
|
13
24
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getFriendEventHandler();
|
|
14
25
|
}
|
|
26
|
+
get balanceUtil() {
|
|
27
|
+
return new BalanceUtil_1.BalanceUtil(this.userModelStore, this.currencyStore);
|
|
28
|
+
}
|
|
15
29
|
async addFriend(userId, request) {
|
|
16
30
|
if (!request.email && !request.phoneNumber) {
|
|
17
31
|
throw new Error("Either email or phoneNumber must be provided");
|
|
18
32
|
}
|
|
33
|
+
if (request.email) {
|
|
34
|
+
const existingFriendByEmail = await this.modelStore.findByUserIdAndFriendEmailAndDeletedIsFalse(userId, request.email.trim());
|
|
35
|
+
if (existingFriendByEmail) {
|
|
36
|
+
throw new Error(`Friend with email ${request.email} already exists`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
if (request.phoneNumber) {
|
|
40
|
+
const existingFriendByPhone = await this.modelStore.findByUserIdAndFriendPhoneNumberAndDeletedIsFalse(userId, request.phoneNumber.trim());
|
|
41
|
+
if (existingFriendByPhone) {
|
|
42
|
+
throw new Error(`Friend with phone number ${request.phoneNumber} already exists`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
19
45
|
const streamId = (0, uuid_1.v4)();
|
|
20
46
|
const createdAt = new Date();
|
|
21
47
|
const event = new FriendEvents_1.FriendCreated({
|
|
@@ -36,10 +62,33 @@ class FriendController {
|
|
|
36
62
|
return streamId;
|
|
37
63
|
}
|
|
38
64
|
async updateFriend(userId, friendId, request) {
|
|
39
|
-
|
|
65
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
66
|
+
if (!friendModel) {
|
|
67
|
+
//fallback to find by streamId
|
|
68
|
+
friendModel =
|
|
69
|
+
await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
70
|
+
}
|
|
40
71
|
if (!friendModel) {
|
|
41
72
|
throw new Error(`Friend not found: ${friendId}`);
|
|
42
73
|
}
|
|
74
|
+
if (request.email !== undefined &&
|
|
75
|
+
request.email.trim() !== "" &&
|
|
76
|
+
request.email !== friendModel.friendEmail) {
|
|
77
|
+
const existingFriendByEmail = await this.modelStore.findByUserIdAndFriendEmailAndDeletedIsFalse(userId, request.email.trim());
|
|
78
|
+
if (existingFriendByEmail &&
|
|
79
|
+
existingFriendByEmail.streamId !== friendModel.streamId) {
|
|
80
|
+
throw new Error(`Another friend with email ${request.email} already exists`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (request.phoneNumber !== undefined &&
|
|
84
|
+
request.phoneNumber.trim() !== "" &&
|
|
85
|
+
request.phoneNumber !== friendModel.friendPhoneNumber) {
|
|
86
|
+
const existingFriendByPhone = await this.modelStore.findByUserIdAndFriendPhoneNumberAndDeletedIsFalse(userId, request.phoneNumber.trim());
|
|
87
|
+
if (existingFriendByPhone &&
|
|
88
|
+
existingFriendByPhone.streamId !== friendModel.streamId) {
|
|
89
|
+
throw new Error(`Another friend with phone number ${request.phoneNumber} already exists`);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
43
92
|
const hasChanges = (request.email !== undefined &&
|
|
44
93
|
request.email.trim() !== "" &&
|
|
45
94
|
request.email !== friendModel.friendEmail) ||
|
|
@@ -70,7 +119,12 @@ class FriendController {
|
|
|
70
119
|
await this.friendEventHandler.handleEvent(event);
|
|
71
120
|
}
|
|
72
121
|
async deleteFriend(userId, friendId) {
|
|
73
|
-
|
|
122
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
123
|
+
if (!friendModel) {
|
|
124
|
+
//fallback to find by streamId
|
|
125
|
+
friendModel =
|
|
126
|
+
await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
127
|
+
}
|
|
74
128
|
if (!friendModel) {
|
|
75
129
|
throw new Error(`Friend not found: ${friendId}`);
|
|
76
130
|
}
|
|
@@ -87,11 +141,19 @@ class FriendController {
|
|
|
87
141
|
await this.friendEventHandler.handleEvent(event);
|
|
88
142
|
}
|
|
89
143
|
async getFriend(userId, friendId) {
|
|
90
|
-
|
|
144
|
+
let friendModel = await this.modelStore.findByUserIdAndFriendIdAndDeletedIsFalse(userId, friendId);
|
|
145
|
+
if (!friendModel) {
|
|
146
|
+
//fallback to find by streamId
|
|
147
|
+
friendModel =
|
|
148
|
+
await this.modelStore.findByUserIdAndStreamIdAndDeletedIsFalse(userId, friendId);
|
|
149
|
+
}
|
|
91
150
|
if (!friendModel) {
|
|
92
151
|
throw new Error(`Friend not found: ${friendId}`);
|
|
93
152
|
}
|
|
94
|
-
|
|
153
|
+
const recipientUserId = friendModel.friendId ?? friendModel.streamId;
|
|
154
|
+
const transactions = await this.transactionModelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, recipientUserId);
|
|
155
|
+
const balance = await this.balanceUtil.calculateBalance(transactions, userId);
|
|
156
|
+
return this.toFriendResponse(friendModel, balance);
|
|
95
157
|
}
|
|
96
158
|
async getFriendByStreamId(streamId) {
|
|
97
159
|
const friendModel = await this.modelStore.getByStreamIdWhereDeletedIsFalse(streamId);
|
|
@@ -102,17 +164,22 @@ class FriendController {
|
|
|
102
164
|
}
|
|
103
165
|
async getAllFriends(userId) {
|
|
104
166
|
const friendModels = await this.modelStore.findAllByUserIdWhereDeletedIsFalse(userId);
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
167
|
+
const allTransactions = await this.transactionModelStore.findAllByUserIdWhereDeletedIsFalse(userId);
|
|
168
|
+
// todo: balance calculation should not use firestore it should always read from sqlite model store
|
|
169
|
+
const mainBalance = await this.balanceUtil.calculateBalance(allTransactions, userId);
|
|
170
|
+
const friendsWithBalance = await Promise.all(friendModels.map(async (friendModel) => {
|
|
171
|
+
const recipientUserId = friendModel.friendId ?? friendModel.streamId;
|
|
172
|
+
const friendTransactions = await this.transactionModelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, recipientUserId);
|
|
173
|
+
const friendBalance = await this.balanceUtil.calculateBalance(friendTransactions, userId);
|
|
174
|
+
return this.toFriendResponse(friendModel, friendBalance);
|
|
175
|
+
}));
|
|
110
176
|
return {
|
|
111
|
-
friends,
|
|
112
|
-
|
|
177
|
+
friends: friendsWithBalance.sort((a, b) => new Date(b.createdAt).getTime() -
|
|
178
|
+
new Date(a.createdAt).getTime()),
|
|
179
|
+
balance: mainBalance,
|
|
113
180
|
};
|
|
114
181
|
}
|
|
115
|
-
toFriendResponse(friendModel) {
|
|
182
|
+
toFriendResponse(friendModel, balance) {
|
|
116
183
|
const emptyBalance = {
|
|
117
184
|
main: undefined,
|
|
118
185
|
other: [],
|
|
@@ -124,9 +191,8 @@ class FriendController {
|
|
|
124
191
|
settled: false,
|
|
125
192
|
email: friendModel.friendEmail,
|
|
126
193
|
phone: friendModel.friendPhoneNumber,
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
balance: emptyBalance,
|
|
194
|
+
balance: balance ?? emptyBalance,
|
|
195
|
+
createdAt: friendModel.createdAt,
|
|
130
196
|
};
|
|
131
197
|
}
|
|
132
198
|
}
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
-
import { TransactionCreateRequest,
|
|
1
|
+
import { TransactionCreateRequest, Transaction, TransactionUpdateRequest, TransactionsResponse } from "../../contracts/transactions";
|
|
2
2
|
export declare class TransactionController {
|
|
3
3
|
private get modelStore();
|
|
4
4
|
private get transactionEventHandler();
|
|
5
|
+
private get userModelStore();
|
|
6
|
+
private get currencyStore();
|
|
7
|
+
private get balanceUtil();
|
|
8
|
+
private get friendModelStore();
|
|
5
9
|
private calculateAmount;
|
|
10
|
+
private buildUserNameMap;
|
|
6
11
|
addTransaction(userId: string, request: TransactionCreateRequest): Promise<string>;
|
|
7
12
|
updateTransaction(userId: string, transactionId: string, request: TransactionUpdateRequest): Promise<void>;
|
|
8
13
|
deleteTransaction(userId: string, transactionId: string): Promise<void>;
|
|
9
|
-
getTransaction(userId: string, transactionId: string): Promise<
|
|
14
|
+
getTransaction(userId: string, transactionId: string): Promise<Transaction>;
|
|
15
|
+
getTransactionsByMonth(userId: string, friendId: string, timeZone: string): Promise<TransactionsResponse>;
|
|
16
|
+
private groupTransactionsByMonth;
|
|
17
|
+
private startOfMonth;
|
|
10
18
|
private toTransactionResponse;
|
|
19
|
+
private getUserName;
|
|
20
|
+
private mapHistoryToResponse;
|
|
21
|
+
private mapChangeTypeToTransactionChangeType;
|
|
11
22
|
}
|
|
12
23
|
//# sourceMappingURL=TransactionController.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/TransactionController.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"TransactionController.d.ts","sourceRoot":"","sources":["../../../src/client/controllers/TransactionController.ts"],"names":[],"mappings":"AAaA,OAAO,EACH,wBAAwB,EACxB,WAAW,EACX,wBAAwB,EACxB,oBAAoB,EAMvB,MAAM,8BAA8B,CAAC;AAKtC,qBAAa,qBAAqB;IAC9B,OAAO,KAAK,UAAU,GAGrB;IAED,OAAO,KAAK,uBAAuB,GAElC;IAED,OAAO,KAAK,cAAc,GAEzB;IAED,OAAO,KAAK,aAAa,GAExB;IAED,OAAO,KAAK,WAAW,GAEtB;IAED,OAAO,KAAK,gBAAgB,GAG3B;IAED,OAAO,CAAC,eAAe;YAYT,gBAAgB;IAgBxB,cAAc,CAChB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,MAAM,CAAC;IAgCZ,iBAAiB,CACnB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,wBAAwB,GAClC,OAAO,CAAC,IAAI,CAAC;IAuHV,iBAAiB,CACnB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,IAAI,CAAC;IA6BV,cAAc,CAChB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,GACtB,OAAO,CAAC,WAAW,CAAC;IAgCjB,sBAAsB,CACxB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,MAAM,GACjB,OAAO,CAAC,oBAAoB,CAAC;IAiDhC,OAAO,CAAC,wBAAwB;IAwBhC,OAAO,CAAC,YAAY;IAapB,OAAO,CAAC,qBAAqB;IA8D7B,OAAO,CAAC,WAAW;IAWnB,OAAO,CAAC,oBAAoB;IAqC5B,OAAO,CAAC,oCAAoC;CAkB/C"}
|
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TransactionController = void 0;
|
|
4
4
|
const TransactionEvents_1 = require("../../TransactionEvents");
|
|
5
|
+
const transactions_1 = require("../../contracts/transactions");
|
|
5
6
|
const EventProcessorSDK_1 = require("../../EventProcessorSDK");
|
|
6
7
|
const uuid_1 = require("uuid");
|
|
8
|
+
const BalanceUtil_1 = require("../../utils/BalanceUtil");
|
|
7
9
|
class TransactionController {
|
|
8
10
|
get modelStore() {
|
|
9
11
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
@@ -12,15 +14,41 @@ class TransactionController {
|
|
|
12
14
|
get transactionEventHandler() {
|
|
13
15
|
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getTransactionEventHandler();
|
|
14
16
|
}
|
|
17
|
+
get userModelStore() {
|
|
18
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().userModelStore;
|
|
19
|
+
}
|
|
20
|
+
get currencyStore() {
|
|
21
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig().currencyStore;
|
|
22
|
+
}
|
|
23
|
+
get balanceUtil() {
|
|
24
|
+
return new BalanceUtil_1.BalanceUtil(this.userModelStore, this.currencyStore);
|
|
25
|
+
}
|
|
26
|
+
get friendModelStore() {
|
|
27
|
+
return EventProcessorSDK_1.EventProcessorSDK.getInstance().getStoreConfig()
|
|
28
|
+
.friendModelStore;
|
|
29
|
+
}
|
|
15
30
|
calculateAmount(splitType, totalAmount) {
|
|
16
|
-
if (splitType === TransactionEvents_1.
|
|
17
|
-
splitType === TransactionEvents_1.
|
|
18
|
-
splitType === TransactionEvents_1.
|
|
19
|
-
splitType === TransactionEvents_1.
|
|
31
|
+
if (splitType === TransactionEvents_1.SplitTypeEnum.TheyOweYouAll ||
|
|
32
|
+
splitType === TransactionEvents_1.SplitTypeEnum.YouOweThemAll ||
|
|
33
|
+
splitType === TransactionEvents_1.SplitTypeEnum.YouPaidToSettle ||
|
|
34
|
+
splitType === TransactionEvents_1.SplitTypeEnum.TheyPaidToSettle) {
|
|
20
35
|
return totalAmount;
|
|
21
36
|
}
|
|
22
37
|
return totalAmount / 2;
|
|
23
38
|
}
|
|
39
|
+
async buildUserNameMap(userId) {
|
|
40
|
+
const friends = await this.friendModelStore.findAllByUserIdWhereDeletedIsFalse(userId);
|
|
41
|
+
const nameMap = new Map();
|
|
42
|
+
for (const friend of friends) {
|
|
43
|
+
// Map friendId (registered user) to display name
|
|
44
|
+
if (friend.friendId) {
|
|
45
|
+
nameMap.set(friend.friendId, friend.friendDisplayName);
|
|
46
|
+
}
|
|
47
|
+
// Also map streamId (for placeholder friends) to display name
|
|
48
|
+
nameMap.set(friend.streamId, friend.friendDisplayName);
|
|
49
|
+
}
|
|
50
|
+
return nameMap;
|
|
51
|
+
}
|
|
24
52
|
async addTransaction(userId, request) {
|
|
25
53
|
const streamId = (0, uuid_1.v4)();
|
|
26
54
|
const createdAt = new Date();
|
|
@@ -171,9 +199,72 @@ class TransactionController {
|
|
|
171
199
|
if (transactionModel.userId !== userId) {
|
|
172
200
|
throw new Error(`Unauthorized to view transaction: ${transactionId}`);
|
|
173
201
|
}
|
|
174
|
-
|
|
202
|
+
// Fetch user, currency rates, and friend names once
|
|
203
|
+
const user = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(userId);
|
|
204
|
+
const toCurrency = user?.currency ?? "USD";
|
|
205
|
+
const currencyRates = (await this.currencyStore.getCurrencyRates())?.rates ?? {};
|
|
206
|
+
const userNameMap = await this.buildUserNameMap(userId);
|
|
207
|
+
return this.toTransactionResponse(transactionModel, userId, toCurrency, currencyRates, userNameMap);
|
|
175
208
|
}
|
|
176
|
-
|
|
209
|
+
async getTransactionsByMonth(userId, friendId, timeZone) {
|
|
210
|
+
if (!timeZone || timeZone.trim() === "") {
|
|
211
|
+
throw new Error("Invalid timezone");
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
new Date().toLocaleString("en-US", { timeZone });
|
|
215
|
+
}
|
|
216
|
+
catch (error) {
|
|
217
|
+
throw new Error("Invalid timezone");
|
|
218
|
+
}
|
|
219
|
+
const transactions = await this.modelStore.findByUserIdAndRecipientUserIdWhereDeletedIsFalse(userId, friendId);
|
|
220
|
+
const balance = await this.balanceUtil.calculateBalance(transactions, userId);
|
|
221
|
+
// Fetch user, currency rates, and friend names once for all conversions
|
|
222
|
+
const user = await this.userModelStore.getByStreamIdWhereDeletedIsFalse(userId);
|
|
223
|
+
const toCurrency = user?.currency ?? "USD";
|
|
224
|
+
const currencyRates = (await this.currencyStore.getCurrencyRates())?.rates ?? {};
|
|
225
|
+
const userNameMap = await this.buildUserNameMap(userId);
|
|
226
|
+
const sortedTransactions = transactions
|
|
227
|
+
.sort((a, b) => new Date(b.transactionDate).getTime() -
|
|
228
|
+
new Date(a.transactionDate).getTime())
|
|
229
|
+
.map((t) => this.toTransactionResponse(t, userId, toCurrency, currencyRates, userNameMap));
|
|
230
|
+
const groupedByMonth = this.groupTransactionsByMonth(sortedTransactions, timeZone);
|
|
231
|
+
return {
|
|
232
|
+
balance,
|
|
233
|
+
perMonth: groupedByMonth,
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
groupTransactionsByMonth(transactions, timeZone) {
|
|
237
|
+
const grouped = new Map();
|
|
238
|
+
for (const transaction of transactions) {
|
|
239
|
+
const monthStart = this.startOfMonth(transaction.date, timeZone);
|
|
240
|
+
const key = monthStart;
|
|
241
|
+
if (!grouped.has(key)) {
|
|
242
|
+
grouped.set(key, []);
|
|
243
|
+
}
|
|
244
|
+
grouped.get(key).push(transaction);
|
|
245
|
+
}
|
|
246
|
+
return Array.from(grouped.entries())
|
|
247
|
+
.sort((a, b) => new Date(b[0]).getTime() - new Date(a[0]).getTime())
|
|
248
|
+
.map(([date, transactions]) => ({
|
|
249
|
+
date,
|
|
250
|
+
transactions,
|
|
251
|
+
}));
|
|
252
|
+
}
|
|
253
|
+
startOfMonth(dateString, timeZone) {
|
|
254
|
+
const date = new Date(dateString);
|
|
255
|
+
const year = date.toLocaleString("en-US", {
|
|
256
|
+
year: "numeric",
|
|
257
|
+
timeZone,
|
|
258
|
+
});
|
|
259
|
+
const month = date.toLocaleString("en-US", {
|
|
260
|
+
month: "2-digit",
|
|
261
|
+
timeZone,
|
|
262
|
+
});
|
|
263
|
+
return new Date(`${year}-${month}-01T00:00:00.000Z`).toISOString();
|
|
264
|
+
}
|
|
265
|
+
toTransactionResponse(transactionModel, currentUserId, toCurrency, rates, userNameMap) {
|
|
266
|
+
const convertedAmount = this.balanceUtil.convertAmount(transactionModel.amount, transactionModel.currency, toCurrency, rates);
|
|
267
|
+
const history = this.mapHistoryToResponse(transactionModel.history, currentUserId, userNameMap);
|
|
177
268
|
return {
|
|
178
269
|
date: transactionModel.transactionDate.toISOString(),
|
|
179
270
|
description: transactionModel.description,
|
|
@@ -188,27 +279,70 @@ class TransactionController {
|
|
|
188
279
|
currency: transactionModel.currency,
|
|
189
280
|
isOwed: transactionModel.isOwed,
|
|
190
281
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
photoUrl: undefined,
|
|
196
|
-
name: undefined,
|
|
282
|
+
defaultCurrencyAmount: {
|
|
283
|
+
amount: convertedAmount.amount,
|
|
284
|
+
currency: convertedAmount.currency,
|
|
285
|
+
isOwed: transactionModel.isOwed,
|
|
197
286
|
},
|
|
198
|
-
|
|
199
|
-
history: [],
|
|
287
|
+
history,
|
|
200
288
|
createdAt: transactionModel.createdAt.toISOString(),
|
|
201
289
|
updatedAt: transactionModel.updatedAt.toISOString(),
|
|
202
290
|
createdBy: {
|
|
203
291
|
id: transactionModel.createdBy,
|
|
204
|
-
name:
|
|
292
|
+
name: this.getUserName(transactionModel.createdBy, currentUserId, userNameMap),
|
|
205
293
|
},
|
|
206
294
|
updatedBy: {
|
|
207
295
|
id: transactionModel.updatedBy,
|
|
208
|
-
name:
|
|
296
|
+
name: this.getUserName(transactionModel.updatedBy, currentUserId, userNameMap),
|
|
209
297
|
},
|
|
210
298
|
deleted: transactionModel.deleted,
|
|
211
299
|
};
|
|
212
300
|
}
|
|
301
|
+
getUserName(userId, currentUserId, userNameMap) {
|
|
302
|
+
if (userId === currentUserId) {
|
|
303
|
+
return "You";
|
|
304
|
+
}
|
|
305
|
+
return userNameMap.get(userId) ?? "User";
|
|
306
|
+
}
|
|
307
|
+
mapHistoryToResponse(history, currentUserId, userNameMap) {
|
|
308
|
+
const grouped = new Map();
|
|
309
|
+
for (const change of history.changes) {
|
|
310
|
+
const changedByName = this.getUserName(change.changedBy, currentUserId, userNameMap);
|
|
311
|
+
const dto = {
|
|
312
|
+
date: change.changedAt.toISOString(),
|
|
313
|
+
changedBy: change.changedBy,
|
|
314
|
+
changedByName,
|
|
315
|
+
oldValue: String(change.oldValue),
|
|
316
|
+
newValue: String(change.newValue),
|
|
317
|
+
type: this.mapChangeTypeToTransactionChangeType(change.type),
|
|
318
|
+
};
|
|
319
|
+
const key = `${change.changedBy}_${change.changedAt.toISOString()}`;
|
|
320
|
+
if (!grouped.has(key)) {
|
|
321
|
+
grouped.set(key, []);
|
|
322
|
+
}
|
|
323
|
+
grouped.get(key).push(dto);
|
|
324
|
+
}
|
|
325
|
+
return Array.from(grouped.entries()).map(([key, changes]) => ({
|
|
326
|
+
changedBy: changes[0].changedBy,
|
|
327
|
+
changedByName: changes[0].changedByName,
|
|
328
|
+
changes,
|
|
329
|
+
}));
|
|
330
|
+
}
|
|
331
|
+
mapChangeTypeToTransactionChangeType(type) {
|
|
332
|
+
switch (type) {
|
|
333
|
+
case "DESCRIPTION_UPDATED":
|
|
334
|
+
return transactions_1.TransactionChangeTypeEnum.DESCRIPTION;
|
|
335
|
+
case "AMOUNT_UPDATED":
|
|
336
|
+
return transactions_1.TransactionChangeTypeEnum.AMOUNT;
|
|
337
|
+
case "CURRENCY_UPDATED":
|
|
338
|
+
return transactions_1.TransactionChangeTypeEnum.CURRENCY;
|
|
339
|
+
case "SPLIT_TYPE_UPDATED":
|
|
340
|
+
return transactions_1.TransactionChangeTypeEnum.SPLIT_TYPE;
|
|
341
|
+
case "TRANSACTION_DATE_UPDATED":
|
|
342
|
+
return transactions_1.TransactionChangeTypeEnum.TRANSACTION_DATE;
|
|
343
|
+
default:
|
|
344
|
+
return transactions_1.TransactionChangeTypeEnum.DESCRIPTION;
|
|
345
|
+
}
|
|
346
|
+
}
|
|
213
347
|
}
|
|
214
348
|
exports.TransactionController = TransactionController;
|
|
@@ -2,5 +2,8 @@ import { Event } from "../../index";
|
|
|
2
2
|
export declare class UIEventHandler {
|
|
3
3
|
constructor();
|
|
4
4
|
handleFirestoreEvent(event: Event): Promise<void>;
|
|
5
|
+
handleFirestoreEvents(events: Event[]): Promise<void>;
|
|
6
|
+
handleSystemSettingUpdate(settingType: string, payload: unknown): Promise<void>;
|
|
7
|
+
private groupEventsByType;
|
|
5
8
|
}
|
|
6
9
|
//# sourceMappingURL=UIEventHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UIEventHandler.d.ts","sourceRoot":"","sources":["../../../src/client/handlers/UIEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAyB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"UIEventHandler.d.ts","sourceRoot":"","sources":["../../../src/client/handlers/UIEventHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAyB,MAAM,aAAa,CAAC;AAI3D,qBAAa,cAAc;;IAGjB,oBAAoB,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC;IAMjD,qBAAqB,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IA6BrD,yBAAyB,CAC3B,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,GACjB,OAAO,CAAC,IAAI,CAAC;IAQhB,OAAO,CAAC,iBAAiB;CAa5B"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UIEventHandler = void 0;
|
|
4
4
|
const index_1 = require("../../index");
|
|
5
|
+
const EventProcessorSDK_1 = require("../../EventProcessorSDK");
|
|
5
6
|
class UIEventHandler {
|
|
6
7
|
constructor() { }
|
|
7
8
|
async handleFirestoreEvent(event) {
|
|
@@ -9,5 +10,40 @@ class UIEventHandler {
|
|
|
9
10
|
.getEventHandler()
|
|
10
11
|
.handleClientEventFromRemoteListener(event);
|
|
11
12
|
}
|
|
13
|
+
async handleFirestoreEvents(events) {
|
|
14
|
+
if (events.length === 0) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
const eventsByType = this.groupEventsByType(events);
|
|
18
|
+
for (const [eventType, eventsOfType] of eventsByType.entries()) {
|
|
19
|
+
const handler = index_1.EventConverterFactory.getConverter(eventType).getEventHandler();
|
|
20
|
+
const latestModel = await handler
|
|
21
|
+
.getModelStore()
|
|
22
|
+
.getLatestByUpdatedAt();
|
|
23
|
+
const filteredEvents = latestModel
|
|
24
|
+
? eventsOfType.filter((event) => event.createdAt >= latestModel.updatedAt)
|
|
25
|
+
: eventsOfType;
|
|
26
|
+
if (filteredEvents.length > 0) {
|
|
27
|
+
await handler.handleClientEventsFromRemoteListenerBulk(filteredEvents);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
async handleSystemSettingUpdate(settingType, payload) {
|
|
32
|
+
if (settingType === "currencyRates") {
|
|
33
|
+
const currencyStore = EventProcessorSDK_1.EventProcessorSDK.getInstance().getCurrencyStore();
|
|
34
|
+
await currencyStore.saveCurrencyRates(payload);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
groupEventsByType(events) {
|
|
38
|
+
const eventsByType = new Map();
|
|
39
|
+
for (const event of events) {
|
|
40
|
+
const eventType = event.constructor.name;
|
|
41
|
+
if (!eventsByType.has(eventType)) {
|
|
42
|
+
eventsByType.set(eventType, []);
|
|
43
|
+
}
|
|
44
|
+
eventsByType.get(eventType).push(event);
|
|
45
|
+
}
|
|
46
|
+
return eventsByType;
|
|
47
|
+
}
|
|
12
48
|
}
|
|
13
49
|
exports.UIEventHandler = UIEventHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CurrencyRate.d.ts","sourceRoot":"","sources":["../../src/common/CurrencyRate.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,WAAW,EAAE,IAAI,CAAC;IAClB,MAAM,EAAE,MAAM,CAAC;CAClB"}
|
package/dist/common/Model.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/common/Model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"Model.d.ts","sourceRoot":"","sources":["../../src/common/Model.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,IAAI,CAAC;CACnB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AmountDto,
|
|
1
|
+
import { AmountDto, BalanceResponse } from "../shared";
|
|
2
2
|
export interface FriendRequest {
|
|
3
3
|
email?: string;
|
|
4
4
|
phoneNumber?: string;
|
|
@@ -65,15 +65,8 @@ export interface FriendResponse {
|
|
|
65
65
|
settled: boolean;
|
|
66
66
|
email?: string;
|
|
67
67
|
phone?: string;
|
|
68
|
-
/**
|
|
69
|
-
* @deprecated Should not use this property anymore, use balance.main instead
|
|
70
|
-
*/
|
|
71
|
-
mainBalance?: AmountResponse;
|
|
72
|
-
/**
|
|
73
|
-
* @deprecated Should not use this property anymore, use balance.other instead
|
|
74
|
-
*/
|
|
75
|
-
otherBalances: OtherBalanceResponse[];
|
|
76
68
|
balance: BalanceResponse;
|
|
69
|
+
createdAt: Date;
|
|
77
70
|
}
|
|
78
71
|
export interface FriendsResponse {
|
|
79
72
|
friends: FriendResponse[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/friends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/friends/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,SAAS,EAET,eAAe,EAElB,MAAM,WAAW,CAAC;AAEnB,MAAM,WAAW,aAAa;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACr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f,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CACjC;AAED,MAAM,WAAW,6BAA6B;IAC1C,OAAO,EAAE,SAAS,EAAE,CAAC;IACrB,OAAO,EAAE,iBAAiB,CAAC;CAC9B;AAED,MAAM,WAAW,cAAc;IAC3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,eAAe,CAAC;IACzB,SAAS,EAAE,IAAI,CAAC;CACnB;AAED,MAAM,WAAW,eAAe;IAC5B,OAAO,EAAE,cAAc,EAAE,CAAC;IAC1B,OAAO,EAAE,eAAe,CAAC;CAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/groups/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/contracts/groups/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,MAAM,WAAW,kBAAkB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,yBAAyB;IACtC,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AAED,MAAM,WAAW,sBAAsB;IACnC,SAAS,EAAE,MAAM,EAA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,WAAW,oBAAoB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,uBAAuB,EAAE,MAAM,CAAC;CACnC;AAED,MAAM,WAAW,2BAA2B;IACxC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,uBAAuB,EAAE,MAAM,CAAC;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,SAAS,EAAE,oBAAoB,EAAE,CAAC;IAClC,SAAS,EAAE,oBAAoB,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,wBAAwB;IACrC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,SAAS,CAAC;IACrB,SAAS,EAAE,2BAA2B,CAAC;IACvC,mBAAmB,EAAE,2BAA2B,CAAC;IACjD,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,yBAAyB;IACtC,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,wBAAwB,EAAE,CAAC;CAC5C;AAED,MAAM,WAAW,gCAAgC;IAC7C,QAAQ,EAAE,yBAAyB,EAAE,CAAC;IACtC,OAAO,EAAE,eAAe,CAAC;CAC5B;AAED,MAAM,WAAW,uBAAuB;IACpC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,OAAO,CAAC;IAChB,OAAO,EAAE,aAAa,EAAE,CAAC;CAC5B"}
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { FriendSummaryDto } from "../friends";
|
|
2
2
|
import { AmountDto, AmountResponse, BalanceResponse } from "../shared";
|
|
3
|
-
import { SplitType
|
|
4
|
-
export
|
|
5
|
-
export { EventSplitType as SplitTypeEnum };
|
|
3
|
+
import { SplitType, SplitTypeEnum } from "../../TransactionEvents";
|
|
4
|
+
export { SplitType, SplitTypeEnum } from "../../TransactionEvents";
|
|
6
5
|
export declare enum ActivityType {
|
|
7
6
|
CREATED = "CREATED",
|
|
8
7
|
UPDATED = "UPDATED",
|
|
9
8
|
DELETED = "DELETED"
|
|
10
9
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export type TransactionChangeType = (typeof TransactionChangeTypeEnum)[keyof typeof TransactionChangeTypeEnum];
|
|
11
|
+
export declare const TransactionChangeTypeEnum: {
|
|
12
|
+
readonly DESCRIPTION: "DESCRIPTION";
|
|
13
|
+
readonly AMOUNT: "AMOUNT";
|
|
14
|
+
readonly CURRENCY: "CURRENCY";
|
|
15
|
+
readonly SPLIT_TYPE: "SPLIT_TYPE";
|
|
16
|
+
readonly DATE: "DATE";
|
|
17
|
+
readonly DELETED: "DELETED";
|
|
18
|
+
readonly TRANSACTION_DATE: "TRANSACTION_DATE";
|
|
19
|
+
};
|
|
18
20
|
export interface UserAmount {
|
|
19
21
|
userId: string;
|
|
20
22
|
paidAmount: number;
|
|
@@ -78,28 +80,36 @@ export interface ChangeSummaryResponse {
|
|
|
78
80
|
changedByPhoto?: string;
|
|
79
81
|
changes: ChangeSummaryDto[];
|
|
80
82
|
}
|
|
81
|
-
|
|
83
|
+
interface BaseTransaction {
|
|
82
84
|
date: string;
|
|
85
|
+
createdAt: string;
|
|
86
|
+
updatedAt: string;
|
|
87
|
+
createdBy: TransactionUserResponse;
|
|
88
|
+
updatedBy?: TransactionUserResponse;
|
|
83
89
|
description: string;
|
|
84
90
|
transactionId: string;
|
|
85
|
-
groupTransactionId?: string;
|
|
86
|
-
groupId?: string;
|
|
87
|
-
groupName?: string;
|
|
88
91
|
totalAmount: number;
|
|
89
|
-
splitType: SplitType;
|
|
90
92
|
amount: AmountResponse;
|
|
91
|
-
|
|
92
|
-
defaultCurrencyAmount?: AmountResponse;
|
|
93
|
+
defaultCurrencyAmount: AmountResponse;
|
|
93
94
|
history: ChangeSummaryResponse[];
|
|
94
|
-
createdAt: string;
|
|
95
|
-
updatedAt?: string;
|
|
96
|
-
createdBy: TransactionUserResponse;
|
|
97
|
-
updatedBy?: TransactionUserResponse;
|
|
98
95
|
deleted: boolean;
|
|
99
96
|
}
|
|
97
|
+
export interface FriendTransaction extends BaseTransaction {
|
|
98
|
+
splitType: SplitType;
|
|
99
|
+
groupId?: string;
|
|
100
|
+
groupTransactionId?: string;
|
|
101
|
+
groupName?: string;
|
|
102
|
+
}
|
|
103
|
+
export interface GroupTransaction extends BaseTransaction {
|
|
104
|
+
groupId: string;
|
|
105
|
+
groupTransactionId: string;
|
|
106
|
+
groupName: string;
|
|
107
|
+
splitType: (typeof SplitTypeEnum)["SpecificAmounts"];
|
|
108
|
+
}
|
|
109
|
+
export type Transaction = FriendTransaction | GroupTransaction;
|
|
100
110
|
export interface TransactionsPerMonth {
|
|
101
111
|
date: string;
|
|
102
|
-
transactions:
|
|
112
|
+
transactions: Transaction[];
|
|
103
113
|
}
|
|
104
114
|
export interface TransactionsResponse {
|
|
105
115
|
balance: BalanceResponse;
|
|
@@ -149,6 +159,6 @@ export interface ActivityLogResponse {
|
|
|
149
159
|
currency: string;
|
|
150
160
|
isOwed: boolean;
|
|
151
161
|
date: string;
|
|
152
|
-
transactionResponse:
|
|
162
|
+
transactionResponse: Transaction;
|
|
153
163
|
}
|
|
154
164
|
//# sourceMappingURL=index.d.ts.map
|