@mody-park-cha-raja/finance_common 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/index.d.mts +488 -0
- package/dist/index.d.ts +488 -0
- package/dist/index.js +789 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +733 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,789 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BadRequestException: () => BadRequestException,
|
|
24
|
+
BaseEntityModel: () => BaseEntityModel,
|
|
25
|
+
DateCodeUtils: () => DateCodeUtils,
|
|
26
|
+
DateUtil: () => DateUtil,
|
|
27
|
+
DonationHistoryModel: () => DonationHistoryModel,
|
|
28
|
+
DonationModel: () => DonationModel,
|
|
29
|
+
EntityFilterDataHelper: () => EntityFilterDataHelper,
|
|
30
|
+
EntityHistoryOperation: () => EntityHistoryOperation,
|
|
31
|
+
EntityList: () => EntityList,
|
|
32
|
+
ExpenseHistoryModel: () => ExpenseHistoryModel,
|
|
33
|
+
ExpenseModel: () => ExpenseModel,
|
|
34
|
+
ForbiddenException: () => ForbiddenException,
|
|
35
|
+
HttpException: () => HttpException,
|
|
36
|
+
NotFoundException: () => NotFoundException,
|
|
37
|
+
OrderByDirection: () => OrderByDirection,
|
|
38
|
+
RelationType: () => RelationType,
|
|
39
|
+
SponsorFor: () => SponsorFor,
|
|
40
|
+
SponsorHistoryModel: () => SponsorHistoryModel,
|
|
41
|
+
SponsorModel: () => SponsorModel,
|
|
42
|
+
TransactionHistoryModel: () => TransactionHistoryModel,
|
|
43
|
+
TransactionModel: () => TransactionModel,
|
|
44
|
+
UnauthorizedException: () => UnauthorizedException,
|
|
45
|
+
UserModel: () => UserModel,
|
|
46
|
+
VendorHistoryModel: () => VendorHistoryModel,
|
|
47
|
+
VendorModel: () => VendorModel,
|
|
48
|
+
definedValues: () => definedValues,
|
|
49
|
+
diffArrays: () => diffArrays,
|
|
50
|
+
entityListEntityModelMap: () => entityListEntityModelMap,
|
|
51
|
+
getObjectDiffingKeys: () => getObjectDiffingKeys,
|
|
52
|
+
groupBy: () => groupBy
|
|
53
|
+
});
|
|
54
|
+
module.exports = __toCommonJS(index_exports);
|
|
55
|
+
|
|
56
|
+
// src/enums/entity-history-operation.enum.ts
|
|
57
|
+
var EntityHistoryOperation = /* @__PURE__ */ ((EntityHistoryOperation2) => {
|
|
58
|
+
EntityHistoryOperation2["CREATE"] = "CREATE";
|
|
59
|
+
EntityHistoryOperation2["UPDATE"] = "UPDATE";
|
|
60
|
+
EntityHistoryOperation2["DELETE"] = "DELETE";
|
|
61
|
+
return EntityHistoryOperation2;
|
|
62
|
+
})(EntityHistoryOperation || {});
|
|
63
|
+
|
|
64
|
+
// src/enums/sponsor-for.enum.ts
|
|
65
|
+
var SponsorFor = /* @__PURE__ */ ((SponsorFor2) => {
|
|
66
|
+
SponsorFor2["GHEE"] = "ghee";
|
|
67
|
+
SponsorFor2["PRASAD"] = "prasad";
|
|
68
|
+
SponsorFor2["BANNER"] = "banner";
|
|
69
|
+
return SponsorFor2;
|
|
70
|
+
})(SponsorFor || {});
|
|
71
|
+
|
|
72
|
+
// src/utils/date-code.utils.ts
|
|
73
|
+
var DateCodeUtils = class _DateCodeUtils {
|
|
74
|
+
constructor(dateCode) {
|
|
75
|
+
this.dateCode = dateCode;
|
|
76
|
+
this.stringifiedDateCode = String(this.dateCode);
|
|
77
|
+
if (!this.isValidYYYYMMDD()) {
|
|
78
|
+
throw new Error(
|
|
79
|
+
`Invalid date code: "${this.stringifiedDateCode}". Expected format: YYYYMMDD.`
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
isValidYYYYMMDD() {
|
|
84
|
+
if (!/^\d{8}$/.test(this.stringifiedDateCode)) return false;
|
|
85
|
+
const { year, month, day } = this.parseDateParts();
|
|
86
|
+
if (month < 1 || month > 12) return false;
|
|
87
|
+
if (day < 1 || day > 31) return false;
|
|
88
|
+
const date = new Date(year, month - 1, day);
|
|
89
|
+
return date.getFullYear() === year && date.getMonth() === month - 1 && date.getDate() === day;
|
|
90
|
+
}
|
|
91
|
+
toLongDateString() {
|
|
92
|
+
const { year, month, day } = this.parseDateParts();
|
|
93
|
+
return new Date(year, month - 1, day).toLocaleDateString("en-US", {
|
|
94
|
+
year: "numeric",
|
|
95
|
+
month: "long",
|
|
96
|
+
day: "numeric"
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
addMonths(months) {
|
|
100
|
+
const { year, month, day } = this.parseDateParts();
|
|
101
|
+
const date = new Date(year, month - 1 + months, day);
|
|
102
|
+
const newYear = date.getFullYear();
|
|
103
|
+
const newMonth = String(date.getMonth() + 1).padStart(2, "0");
|
|
104
|
+
const newDay = String(date.getDate()).padStart(2, "0");
|
|
105
|
+
return `${newYear}${newMonth}${newDay}`;
|
|
106
|
+
}
|
|
107
|
+
addDays(days) {
|
|
108
|
+
const { year, month, day } = this.parseDateParts();
|
|
109
|
+
const date = new Date(year, month - 1, day);
|
|
110
|
+
date.setDate(date.getDate() + days);
|
|
111
|
+
const newYear = date.getFullYear();
|
|
112
|
+
const newMonth = String(date.getMonth() + 1).padStart(2, "0");
|
|
113
|
+
const newDay = String(date.getDate()).padStart(2, "0");
|
|
114
|
+
return `${newYear}${newMonth}${newDay}`;
|
|
115
|
+
}
|
|
116
|
+
addWeeks(weeks) {
|
|
117
|
+
return this.addDays(weeks * 7);
|
|
118
|
+
}
|
|
119
|
+
addYears(years) {
|
|
120
|
+
const { year, month, day } = this.parseDateParts();
|
|
121
|
+
const date = new Date(year + years, month - 1, day);
|
|
122
|
+
const newYear = date.getFullYear();
|
|
123
|
+
const newMonth = String(date.getMonth() + 1).padStart(2, "0");
|
|
124
|
+
const newDay = String(date.getDate()).padStart(2, "0");
|
|
125
|
+
return `${newYear}${newMonth}${newDay}`;
|
|
126
|
+
}
|
|
127
|
+
parseDateParts() {
|
|
128
|
+
return {
|
|
129
|
+
year: parseInt(this.stringifiedDateCode.substring(0, 4), 10),
|
|
130
|
+
month: parseInt(this.stringifiedDateCode.substring(4, 6), 10),
|
|
131
|
+
day: parseInt(this.stringifiedDateCode.substring(6, 8), 10)
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
static getCurrentYear() {
|
|
135
|
+
return (/* @__PURE__ */ new Date()).getFullYear();
|
|
136
|
+
}
|
|
137
|
+
static daysDiff(dateCode) {
|
|
138
|
+
const { year, month, day } = new _DateCodeUtils(dateCode).parseDateParts();
|
|
139
|
+
const target = new Date(year, month - 1, day);
|
|
140
|
+
const today = /* @__PURE__ */ new Date();
|
|
141
|
+
today.setHours(0, 0, 0, 0);
|
|
142
|
+
const diffMs = target.getTime() - today.getTime();
|
|
143
|
+
return Math.round(diffMs / (1e3 * 60 * 60 * 24));
|
|
144
|
+
}
|
|
145
|
+
static getCurrentDateCode() {
|
|
146
|
+
const today = /* @__PURE__ */ new Date();
|
|
147
|
+
const year = today.getFullYear();
|
|
148
|
+
const month = String(today.getMonth() + 1).padStart(2, "0");
|
|
149
|
+
const day = String(today.getDate()).padStart(2, "0");
|
|
150
|
+
return `${year}${month}${day}`;
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// src/utils/date.utils.ts
|
|
155
|
+
var DateUtil = class {
|
|
156
|
+
// Current time as epoch milliseconds
|
|
157
|
+
static now() {
|
|
158
|
+
return Date.now();
|
|
159
|
+
}
|
|
160
|
+
// Date object → epoch milliseconds
|
|
161
|
+
static toEpoch(date) {
|
|
162
|
+
return date.getTime();
|
|
163
|
+
}
|
|
164
|
+
// Epoch milliseconds → Date object
|
|
165
|
+
static toDate(epoch) {
|
|
166
|
+
return new Date(epoch);
|
|
167
|
+
}
|
|
168
|
+
// Epoch milliseconds → readable string
|
|
169
|
+
static toReadable(epoch) {
|
|
170
|
+
return new Date(epoch).toISOString();
|
|
171
|
+
}
|
|
172
|
+
// Add days to epoch → returns epoch
|
|
173
|
+
static addDays(epoch, days) {
|
|
174
|
+
return epoch + days * 24 * 60 * 60 * 1e3;
|
|
175
|
+
}
|
|
176
|
+
// Add months to epoch → returns epoch
|
|
177
|
+
static addMonths(epoch, months) {
|
|
178
|
+
const date = new Date(epoch);
|
|
179
|
+
date.setMonth(date.getMonth() + months);
|
|
180
|
+
return date.getTime();
|
|
181
|
+
}
|
|
182
|
+
// Add weeks to epoch → returns epoch
|
|
183
|
+
static addWeeks(epoch, weeks) {
|
|
184
|
+
return this.addDays(epoch, weeks * 7);
|
|
185
|
+
}
|
|
186
|
+
// Add years to epoch → returns epoch
|
|
187
|
+
static addYears(epoch, years) {
|
|
188
|
+
const date = new Date(epoch);
|
|
189
|
+
date.setFullYear(date.getFullYear() + years);
|
|
190
|
+
return date.getTime();
|
|
191
|
+
}
|
|
192
|
+
// Difference in days between two epochs
|
|
193
|
+
static daysDifference(epoch1, epoch2) {
|
|
194
|
+
return Math.ceil((epoch2 - epoch1) / (1e3 * 60 * 60 * 24));
|
|
195
|
+
}
|
|
196
|
+
// Check if epoch is today
|
|
197
|
+
static isToday(epoch) {
|
|
198
|
+
const date = new Date(epoch);
|
|
199
|
+
const today = /* @__PURE__ */ new Date();
|
|
200
|
+
return date.getDate() === today.getDate() && date.getMonth() === today.getMonth() && date.getFullYear() === today.getFullYear();
|
|
201
|
+
}
|
|
202
|
+
// Check if epoch is in the past
|
|
203
|
+
static isPast(epoch) {
|
|
204
|
+
return epoch < Date.now();
|
|
205
|
+
}
|
|
206
|
+
// Check if epoch is in the future
|
|
207
|
+
static isFuture(epoch) {
|
|
208
|
+
return epoch > Date.now();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
// src/models/base.entity.model.ts
|
|
213
|
+
var BaseEntityModel = class {
|
|
214
|
+
// populateRelations(searchResponse: ISearchV2Response): this {
|
|
215
|
+
// const relations = (this.constructor as typeof BaseEntityModel).relations;
|
|
216
|
+
// for (const [prop, config] of Object.entries(relations)) {
|
|
217
|
+
// const { relationType, mappingProperty, searchProperty, entity } = config!;
|
|
218
|
+
// // @ts-ignore
|
|
219
|
+
// const fkValue = this[mappingProperty];
|
|
220
|
+
// const bucket = searchResponse[entity] ?? [];
|
|
221
|
+
// if (!bucket.length) continue;
|
|
222
|
+
// if (relationType === RelationType.ONE) {
|
|
223
|
+
// // @ts-ignore
|
|
224
|
+
// const match = bucket.find((e) => e[searchProperty] === fkValue);
|
|
225
|
+
// if (match) {
|
|
226
|
+
// const hydrated = (
|
|
227
|
+
// entityListEntityModelMap[entity] as (
|
|
228
|
+
// e: EntityType<EntityList>,
|
|
229
|
+
// ) => any
|
|
230
|
+
// )(match);
|
|
231
|
+
// // recursively populate relations on the hydrated model
|
|
232
|
+
// hydrated.populateRelations(searchResponse);
|
|
233
|
+
// this[prop as keyof this] = hydrated;
|
|
234
|
+
// }
|
|
235
|
+
// } else {
|
|
236
|
+
// const matches = bucket.filter(
|
|
237
|
+
// (e: any) => e[searchProperty] === fkValue,
|
|
238
|
+
// );
|
|
239
|
+
// this[prop as keyof this] = matches.map((e: EntityType<EntityList>) => {
|
|
240
|
+
// const hydrated = (
|
|
241
|
+
// entityListEntityModelMap[entity] as (
|
|
242
|
+
// e: EntityType<EntityList>,
|
|
243
|
+
// ) => any
|
|
244
|
+
// )(e);
|
|
245
|
+
// // recursively populate relations on each hydrated model
|
|
246
|
+
// hydrated.populateRelations(searchResponse);
|
|
247
|
+
// return hydrated;
|
|
248
|
+
// }) as this[keyof this];
|
|
249
|
+
// }
|
|
250
|
+
// }
|
|
251
|
+
// return this;
|
|
252
|
+
// }
|
|
253
|
+
populateRelations(searchResponse, visited = /* @__PURE__ */ new Set()) {
|
|
254
|
+
const selfKey = `${this.constructor.name}:${this.id}`;
|
|
255
|
+
if (visited.has(selfKey)) return this;
|
|
256
|
+
visited.add(selfKey);
|
|
257
|
+
const relations = this.constructor.relations;
|
|
258
|
+
for (const [prop, config] of Object.entries(relations)) {
|
|
259
|
+
const { relationType, mappingProperty, searchProperty, entity } = config;
|
|
260
|
+
const fkValue = this[mappingProperty];
|
|
261
|
+
const bucket = searchResponse[entity] ?? [];
|
|
262
|
+
if (!bucket.length) continue;
|
|
263
|
+
if (relationType === "ONE" /* ONE */) {
|
|
264
|
+
const match = bucket.find((e) => e[searchProperty] === fkValue);
|
|
265
|
+
if (match) {
|
|
266
|
+
const hydrated = entityListEntityModelMap[entity](match);
|
|
267
|
+
hydrated.populateRelations(searchResponse, visited);
|
|
268
|
+
this[prop] = hydrated;
|
|
269
|
+
}
|
|
270
|
+
} else {
|
|
271
|
+
const matches = bucket.filter(
|
|
272
|
+
(e) => e[searchProperty] === fkValue
|
|
273
|
+
);
|
|
274
|
+
this[prop] = matches.map((e) => {
|
|
275
|
+
const hydrated = entityListEntityModelMap[entity](e);
|
|
276
|
+
hydrated.populateRelations(searchResponse, visited);
|
|
277
|
+
return hydrated;
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return this;
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
BaseEntityModel.relations = {};
|
|
285
|
+
|
|
286
|
+
// src/models/donation.entity.model.ts
|
|
287
|
+
var DonationModel = class _DonationModel extends BaseEntityModel {
|
|
288
|
+
constructor() {
|
|
289
|
+
super();
|
|
290
|
+
this.id = 0;
|
|
291
|
+
this.flatNo = "";
|
|
292
|
+
this.amount = 0;
|
|
293
|
+
this.createdOn = 0;
|
|
294
|
+
this.updatedOn = 0;
|
|
295
|
+
this.createdBy = 0;
|
|
296
|
+
this.updatedBy = 0;
|
|
297
|
+
}
|
|
298
|
+
static populateFromEntity(entity) {
|
|
299
|
+
return Object.assign(new _DonationModel(), entity);
|
|
300
|
+
}
|
|
301
|
+
};
|
|
302
|
+
|
|
303
|
+
// src/models/donation-history.entity.model.ts
|
|
304
|
+
var _DonationHistoryModel = class _DonationHistoryModel extends BaseEntityModel {
|
|
305
|
+
constructor() {
|
|
306
|
+
super();
|
|
307
|
+
this.id = 0;
|
|
308
|
+
this.entityId = 0;
|
|
309
|
+
this.data = "";
|
|
310
|
+
this.operation = "CREATE" /* CREATE */;
|
|
311
|
+
this.createdOn = 0;
|
|
312
|
+
this.updatedOn = 0;
|
|
313
|
+
this.createdBy = 0;
|
|
314
|
+
this.updatedBy = 0;
|
|
315
|
+
}
|
|
316
|
+
static populateFromEntity(entity) {
|
|
317
|
+
return Object.assign(new _DonationHistoryModel(), entity);
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
_DonationHistoryModel.relations = {};
|
|
321
|
+
var DonationHistoryModel = _DonationHistoryModel;
|
|
322
|
+
|
|
323
|
+
// src/models/expense.entity.model.ts
|
|
324
|
+
var ExpenseModel = class _ExpenseModel extends BaseEntityModel {
|
|
325
|
+
constructor() {
|
|
326
|
+
super();
|
|
327
|
+
this.id = 0;
|
|
328
|
+
this.name = "";
|
|
329
|
+
this.type = "";
|
|
330
|
+
this.vendorName = "";
|
|
331
|
+
this.amount = 0;
|
|
332
|
+
this.createdOn = 0;
|
|
333
|
+
this.updatedOn = 0;
|
|
334
|
+
this.createdBy = 0;
|
|
335
|
+
this.updatedBy = 0;
|
|
336
|
+
}
|
|
337
|
+
static populateFromEntity(entity) {
|
|
338
|
+
return Object.assign(new _ExpenseModel(), entity);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// src/models/expense-history.entity.model.ts
|
|
343
|
+
var _ExpenseHistoryModel = class _ExpenseHistoryModel extends BaseEntityModel {
|
|
344
|
+
constructor() {
|
|
345
|
+
super();
|
|
346
|
+
this.id = 0;
|
|
347
|
+
this.entityId = 0;
|
|
348
|
+
this.data = "";
|
|
349
|
+
this.operation = "CREATE" /* CREATE */;
|
|
350
|
+
this.createdOn = 0;
|
|
351
|
+
this.updatedOn = 0;
|
|
352
|
+
this.createdBy = 0;
|
|
353
|
+
this.updatedBy = 0;
|
|
354
|
+
}
|
|
355
|
+
static populateFromEntity(entity) {
|
|
356
|
+
return Object.assign(new _ExpenseHistoryModel(), entity);
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
_ExpenseHistoryModel.relations = {};
|
|
360
|
+
var ExpenseHistoryModel = _ExpenseHistoryModel;
|
|
361
|
+
|
|
362
|
+
// src/models/sponsor.entity.model.ts
|
|
363
|
+
var SponsorModel = class _SponsorModel extends BaseEntityModel {
|
|
364
|
+
constructor() {
|
|
365
|
+
super();
|
|
366
|
+
this.id = 0;
|
|
367
|
+
this.contactName = "";
|
|
368
|
+
this.contactNo = "";
|
|
369
|
+
this.sponsorFor = "ghee" /* GHEE */;
|
|
370
|
+
this.size = "";
|
|
371
|
+
this.amount = 0;
|
|
372
|
+
this.createdOn = 0;
|
|
373
|
+
this.updatedOn = 0;
|
|
374
|
+
this.createdBy = 0;
|
|
375
|
+
this.updatedBy = 0;
|
|
376
|
+
}
|
|
377
|
+
static populateFromEntity(entity) {
|
|
378
|
+
return Object.assign(new _SponsorModel(), entity);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
// src/models/sponsor-history.entity.model.ts
|
|
383
|
+
var _SponsorHistoryModel = class _SponsorHistoryModel extends BaseEntityModel {
|
|
384
|
+
constructor() {
|
|
385
|
+
super();
|
|
386
|
+
this.id = 0;
|
|
387
|
+
this.entityId = 0;
|
|
388
|
+
this.data = "";
|
|
389
|
+
this.operation = "CREATE" /* CREATE */;
|
|
390
|
+
this.createdOn = 0;
|
|
391
|
+
this.updatedOn = 0;
|
|
392
|
+
this.createdBy = 0;
|
|
393
|
+
this.updatedBy = 0;
|
|
394
|
+
}
|
|
395
|
+
static populateFromEntity(entity) {
|
|
396
|
+
return Object.assign(new _SponsorHistoryModel(), entity);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
_SponsorHistoryModel.relations = {};
|
|
400
|
+
var SponsorHistoryModel = _SponsorHistoryModel;
|
|
401
|
+
|
|
402
|
+
// src/models/transaction.entity.model.ts
|
|
403
|
+
var TransactionModel = class _TransactionModel extends BaseEntityModel {
|
|
404
|
+
constructor() {
|
|
405
|
+
super();
|
|
406
|
+
this.id = 0;
|
|
407
|
+
this.date = "";
|
|
408
|
+
this.type = "Income";
|
|
409
|
+
this.particulars = "";
|
|
410
|
+
this.amount = 0;
|
|
411
|
+
this.balanceAfter = 0;
|
|
412
|
+
this.referenceId = "";
|
|
413
|
+
this.createdOn = 0;
|
|
414
|
+
this.updatedOn = 0;
|
|
415
|
+
this.createdBy = 0;
|
|
416
|
+
this.updatedBy = 0;
|
|
417
|
+
}
|
|
418
|
+
static populateFromEntity(entity) {
|
|
419
|
+
return Object.assign(new _TransactionModel(), entity);
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// src/models/transaction-history.entity.model.ts
|
|
424
|
+
var _TransactionHistoryModel = class _TransactionHistoryModel extends BaseEntityModel {
|
|
425
|
+
constructor() {
|
|
426
|
+
super();
|
|
427
|
+
this.id = 0;
|
|
428
|
+
this.entityId = 0;
|
|
429
|
+
this.data = "";
|
|
430
|
+
this.operation = "CREATE" /* CREATE */;
|
|
431
|
+
this.createdOn = 0;
|
|
432
|
+
this.updatedOn = 0;
|
|
433
|
+
this.createdBy = 0;
|
|
434
|
+
this.updatedBy = 0;
|
|
435
|
+
}
|
|
436
|
+
static populateFromEntity(entity) {
|
|
437
|
+
return Object.assign(new _TransactionHistoryModel(), entity);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
_TransactionHistoryModel.relations = {};
|
|
441
|
+
var TransactionHistoryModel = _TransactionHistoryModel;
|
|
442
|
+
|
|
443
|
+
// src/models/user.entity.model.ts
|
|
444
|
+
var UserModel = class _UserModel extends BaseEntityModel {
|
|
445
|
+
constructor() {
|
|
446
|
+
super();
|
|
447
|
+
this.id = 0;
|
|
448
|
+
this.name = "";
|
|
449
|
+
this.password = "";
|
|
450
|
+
this.email = "";
|
|
451
|
+
this.phone = "";
|
|
452
|
+
this.createdOn = 0;
|
|
453
|
+
this.updatedOn = 0;
|
|
454
|
+
this.createdBy = 0;
|
|
455
|
+
this.updatedBy = 0;
|
|
456
|
+
}
|
|
457
|
+
static populateFromEntity(entity) {
|
|
458
|
+
return Object.assign(new _UserModel(), entity);
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// src/models/vendor.entity.model.ts
|
|
463
|
+
var VendorModel = class _VendorModel extends BaseEntityModel {
|
|
464
|
+
constructor() {
|
|
465
|
+
super();
|
|
466
|
+
this.id = 0;
|
|
467
|
+
this.name = "";
|
|
468
|
+
this.type = "";
|
|
469
|
+
this.createdOn = 0;
|
|
470
|
+
this.updatedOn = 0;
|
|
471
|
+
this.createdBy = 0;
|
|
472
|
+
this.updatedBy = 0;
|
|
473
|
+
}
|
|
474
|
+
static populateFromEntity(entity) {
|
|
475
|
+
return Object.assign(new _VendorModel(), entity);
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
// src/models/vendor-history.entity.model.ts
|
|
480
|
+
var _VendorHistoryModel = class _VendorHistoryModel extends BaseEntityModel {
|
|
481
|
+
constructor() {
|
|
482
|
+
super();
|
|
483
|
+
this.id = 0;
|
|
484
|
+
this.entityId = 0;
|
|
485
|
+
this.data = "";
|
|
486
|
+
this.operation = "CREATE" /* CREATE */;
|
|
487
|
+
this.createdOn = 0;
|
|
488
|
+
this.updatedOn = 0;
|
|
489
|
+
this.createdBy = 0;
|
|
490
|
+
this.updatedBy = 0;
|
|
491
|
+
}
|
|
492
|
+
static populateFromEntity(entity) {
|
|
493
|
+
return Object.assign(new _VendorHistoryModel(), entity);
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
_VendorHistoryModel.relations = {};
|
|
497
|
+
var VendorHistoryModel = _VendorHistoryModel;
|
|
498
|
+
|
|
499
|
+
// src/utils/entity.utils.ts
|
|
500
|
+
var EntityList = /* @__PURE__ */ ((EntityList2) => {
|
|
501
|
+
EntityList2["DONATION"] = "donation";
|
|
502
|
+
EntityList2["DONATION_HISTORY"] = "donation_history";
|
|
503
|
+
EntityList2["USER"] = "user";
|
|
504
|
+
EntityList2["EXPENSE"] = "expense";
|
|
505
|
+
EntityList2["EXPENSE_HISTORY"] = "expense_history";
|
|
506
|
+
EntityList2["VENDOR"] = "vendor";
|
|
507
|
+
EntityList2["VENDOR_HISTORY"] = "vendor_history";
|
|
508
|
+
EntityList2["TRANSACTION"] = "transaction";
|
|
509
|
+
EntityList2["TRANSACTION_HISTORY"] = "transaction_history";
|
|
510
|
+
EntityList2["SPONSOR"] = "sponsor";
|
|
511
|
+
EntityList2["SPONSOR_HISTORY"] = "sponsor_history";
|
|
512
|
+
return EntityList2;
|
|
513
|
+
})(EntityList || {});
|
|
514
|
+
|
|
515
|
+
// src/utils/entitiy-list-entity-model-map.ts
|
|
516
|
+
var entityListEntityModelMap = {
|
|
517
|
+
["donation" /* DONATION */]: DonationModel.populateFromEntity,
|
|
518
|
+
["donation_history" /* DONATION_HISTORY */]: DonationHistoryModel.populateFromEntity,
|
|
519
|
+
["user" /* USER */]: UserModel.populateFromEntity,
|
|
520
|
+
["expense" /* EXPENSE */]: ExpenseModel.populateFromEntity,
|
|
521
|
+
["expense_history" /* EXPENSE_HISTORY */]: ExpenseHistoryModel.populateFromEntity,
|
|
522
|
+
["vendor" /* VENDOR */]: VendorModel.populateFromEntity,
|
|
523
|
+
["vendor_history" /* VENDOR_HISTORY */]: VendorHistoryModel.populateFromEntity,
|
|
524
|
+
["transaction" /* TRANSACTION */]: TransactionModel.populateFromEntity,
|
|
525
|
+
["transaction_history" /* TRANSACTION_HISTORY */]: TransactionHistoryModel.populateFromEntity,
|
|
526
|
+
["sponsor" /* SPONSOR */]: SponsorModel.populateFromEntity,
|
|
527
|
+
["sponsor_history" /* SPONSOR_HISTORY */]: SponsorHistoryModel.populateFromEntity
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// src/utils/error.utils.ts
|
|
531
|
+
var HttpException = class extends Error {
|
|
532
|
+
constructor(message, statusCode, key, errors) {
|
|
533
|
+
super(message);
|
|
534
|
+
this.message = message;
|
|
535
|
+
this.statusCode = statusCode;
|
|
536
|
+
this.key = key;
|
|
537
|
+
this.errors = errors;
|
|
538
|
+
this.name = this.constructor.name;
|
|
539
|
+
if (Error.captureStackTrace) {
|
|
540
|
+
Error.captureStackTrace(this, this.constructor);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
getResponse() {
|
|
544
|
+
return {
|
|
545
|
+
statusCode: this.statusCode,
|
|
546
|
+
message: this.message,
|
|
547
|
+
key: this.key,
|
|
548
|
+
errors: this.errors
|
|
549
|
+
};
|
|
550
|
+
}
|
|
551
|
+
getStatus() {
|
|
552
|
+
return this.statusCode;
|
|
553
|
+
}
|
|
554
|
+
};
|
|
555
|
+
var BadRequestException = class extends HttpException {
|
|
556
|
+
constructor(input, errors) {
|
|
557
|
+
if (typeof input === "object" && !Array.isArray(input)) {
|
|
558
|
+
super(input.message, 400, input.key, errors);
|
|
559
|
+
} else {
|
|
560
|
+
super(
|
|
561
|
+
Array.isArray(input) ? input.join(", ") : input,
|
|
562
|
+
400,
|
|
563
|
+
void 0,
|
|
564
|
+
errors
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
};
|
|
569
|
+
var NotFoundException = class extends HttpException {
|
|
570
|
+
constructor(input = "Not Found") {
|
|
571
|
+
if (typeof input === "object") {
|
|
572
|
+
super(input.message, 404, input.key);
|
|
573
|
+
} else {
|
|
574
|
+
super(input, 404);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
};
|
|
578
|
+
var UnauthorizedException = class extends HttpException {
|
|
579
|
+
constructor(input = "Unauthorized") {
|
|
580
|
+
if (typeof input === "object") {
|
|
581
|
+
super(input.message, 401, input.key);
|
|
582
|
+
} else {
|
|
583
|
+
super(input, 401);
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
};
|
|
587
|
+
var ForbiddenException = class extends HttpException {
|
|
588
|
+
constructor(input = "Forbidden") {
|
|
589
|
+
if (typeof input === "object") {
|
|
590
|
+
super(input.message, 403, input.key);
|
|
591
|
+
} else {
|
|
592
|
+
super(input, 403);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
};
|
|
596
|
+
|
|
597
|
+
// src/utils/helper.fns.ts
|
|
598
|
+
function getObjectDiffingKeys(oldObject, newObject) {
|
|
599
|
+
const keysToExclude = [
|
|
600
|
+
"createdOn",
|
|
601
|
+
"createdBy"
|
|
602
|
+
];
|
|
603
|
+
const keysOfOldObject = Object.keys(oldObject);
|
|
604
|
+
const keysOfNewObject = Object.keys(newObject);
|
|
605
|
+
if (keysOfOldObject.length !== keysOfNewObject.length) {
|
|
606
|
+
throw new BadRequestException({
|
|
607
|
+
key: "objects",
|
|
608
|
+
message: `Different objects recieved for diffing. Please check & try again.`
|
|
609
|
+
});
|
|
610
|
+
}
|
|
611
|
+
const oldDiffingKeys = {};
|
|
612
|
+
const newDiffingKeys = {};
|
|
613
|
+
for (const key of keysOfOldObject) {
|
|
614
|
+
if (keysToExclude.includes(key)) continue;
|
|
615
|
+
const oldVal = oldObject[key];
|
|
616
|
+
const newVal = newObject[key];
|
|
617
|
+
if (JSON.stringify(oldVal) !== JSON.stringify(newVal)) {
|
|
618
|
+
oldDiffingKeys[key] = oldVal;
|
|
619
|
+
newDiffingKeys[key] = newVal;
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
return newDiffingKeys;
|
|
623
|
+
}
|
|
624
|
+
function diffArrays(arr1, arr2) {
|
|
625
|
+
const set1 = new Set(arr1);
|
|
626
|
+
const set2 = new Set(arr2);
|
|
627
|
+
return {
|
|
628
|
+
present: arr1.filter((item) => set2.has(item)),
|
|
629
|
+
deleted: arr1.filter((item) => !set2.has(item)),
|
|
630
|
+
added: arr2.filter((item) => !set1.has(item))
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function groupBy(items, key) {
|
|
634
|
+
const result = /* @__PURE__ */ new Map();
|
|
635
|
+
for (const item of items) {
|
|
636
|
+
const groupKey = String(item[key]);
|
|
637
|
+
if (!result.has(groupKey)) {
|
|
638
|
+
result.set(groupKey, []);
|
|
639
|
+
}
|
|
640
|
+
result.get(groupKey).push(item);
|
|
641
|
+
}
|
|
642
|
+
return result;
|
|
643
|
+
}
|
|
644
|
+
function definedValues(arr) {
|
|
645
|
+
return arr.filter((value) => value != null);
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/utils/relation-config.utils.ts
|
|
649
|
+
var RelationType = /* @__PURE__ */ ((RelationType2) => {
|
|
650
|
+
RelationType2["ONE"] = "ONE";
|
|
651
|
+
RelationType2["MANY"] = "MANY";
|
|
652
|
+
return RelationType2;
|
|
653
|
+
})(RelationType || {});
|
|
654
|
+
|
|
655
|
+
// src/utils/sql-utils.ts
|
|
656
|
+
var OrderByDirection = /* @__PURE__ */ ((OrderByDirection2) => {
|
|
657
|
+
OrderByDirection2["ASC"] = "ASC";
|
|
658
|
+
OrderByDirection2["DESC"] = "DESC";
|
|
659
|
+
return OrderByDirection2;
|
|
660
|
+
})(OrderByDirection || {});
|
|
661
|
+
|
|
662
|
+
// src/helpers/entity-filter-data.helper.ts
|
|
663
|
+
var EntityFilterDataHelper = class {
|
|
664
|
+
constructor(searchResponse) {
|
|
665
|
+
this.searchResponse = searchResponse;
|
|
666
|
+
this.entityModelsMap = {};
|
|
667
|
+
this.entityModelsMap = this.populateEntityModelsMap();
|
|
668
|
+
}
|
|
669
|
+
getEntityFromList(name) {
|
|
670
|
+
const populateFn = entityListEntityModelMap[name];
|
|
671
|
+
const data = this.searchResponse[name] ?? [];
|
|
672
|
+
return data.map(
|
|
673
|
+
(entity) => populateFn(
|
|
674
|
+
entity
|
|
675
|
+
)
|
|
676
|
+
);
|
|
677
|
+
}
|
|
678
|
+
// getEntityModelsMap(): EntityListEntityModelMap {
|
|
679
|
+
populateEntityModelsMap() {
|
|
680
|
+
const responseObj = {};
|
|
681
|
+
for (const key of Object.keys(this.searchResponse)) {
|
|
682
|
+
const populateFn = entityListEntityModelMap[key];
|
|
683
|
+
if (!populateFn) continue;
|
|
684
|
+
const raw = this.searchResponse[key];
|
|
685
|
+
if (!Array.isArray(raw)) continue;
|
|
686
|
+
responseObj[key] = this.searchResponse[key].map(
|
|
687
|
+
(entity) => populateFn(
|
|
688
|
+
entity
|
|
689
|
+
)
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
return responseObj;
|
|
693
|
+
}
|
|
694
|
+
getEntityModelsByFilter(entityName, filter) {
|
|
695
|
+
const filteredModels = this.entityModelsMap[entityName].filter(
|
|
696
|
+
(model) => filter.value.includes(model[filter.key])
|
|
697
|
+
);
|
|
698
|
+
if (filteredModels.length === 0) {
|
|
699
|
+
throw new BadRequestException({
|
|
700
|
+
key: `${filter.key}`,
|
|
701
|
+
message: `${entityName} with values: ${filter.value.join(", ")} not found. Please try with valid values.`
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
return filteredModels;
|
|
705
|
+
}
|
|
706
|
+
getEntityModelByFilter(entityName, filter) {
|
|
707
|
+
const filteredModel = this.entityModelsMap[entityName].filter(
|
|
708
|
+
(model) => model[filter.key] === filter.value
|
|
709
|
+
);
|
|
710
|
+
if (filteredModel.length === 0) {
|
|
711
|
+
throw new BadRequestException({
|
|
712
|
+
key: `${filter.key}`,
|
|
713
|
+
message: `${entityName} with values: ${filter.value} not found. Please try with valid values.`
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
return filteredModel[0];
|
|
717
|
+
}
|
|
718
|
+
// populateRelationsFor(entityNames: EntityList[]): EntityListEntityModelMap {
|
|
719
|
+
// for (const entityName of entityNames) {
|
|
720
|
+
// const models = this.entityModelsMap[entityName];
|
|
721
|
+
// if (!models) continue;
|
|
722
|
+
// for (const model of models) {
|
|
723
|
+
// (model as unknown as BaseEntityModel).populateRelations(
|
|
724
|
+
// this.searchResponse,
|
|
725
|
+
// );
|
|
726
|
+
// }
|
|
727
|
+
// }
|
|
728
|
+
// return this.entityModelsMap;
|
|
729
|
+
// }
|
|
730
|
+
populateRelationsFor(entityNames) {
|
|
731
|
+
for (const entityName of entityNames) {
|
|
732
|
+
const models = this.entityModelsMap[entityName];
|
|
733
|
+
if (!models) continue;
|
|
734
|
+
for (const model of models) {
|
|
735
|
+
model.populateRelations(
|
|
736
|
+
this.searchResponse,
|
|
737
|
+
/* @__PURE__ */ new Set()
|
|
738
|
+
// fresh set per top-level model
|
|
739
|
+
);
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
return this.entityModelsMap;
|
|
743
|
+
}
|
|
744
|
+
mergeEntity(entityName, savedEntity) {
|
|
745
|
+
const populateFn = entityListEntityModelMap[entityName];
|
|
746
|
+
const model = populateFn(
|
|
747
|
+
savedEntity
|
|
748
|
+
);
|
|
749
|
+
model.populateRelations(
|
|
750
|
+
this.searchResponse,
|
|
751
|
+
/* @__PURE__ */ new Set()
|
|
752
|
+
);
|
|
753
|
+
return model;
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
757
|
+
0 && (module.exports = {
|
|
758
|
+
BadRequestException,
|
|
759
|
+
BaseEntityModel,
|
|
760
|
+
DateCodeUtils,
|
|
761
|
+
DateUtil,
|
|
762
|
+
DonationHistoryModel,
|
|
763
|
+
DonationModel,
|
|
764
|
+
EntityFilterDataHelper,
|
|
765
|
+
EntityHistoryOperation,
|
|
766
|
+
EntityList,
|
|
767
|
+
ExpenseHistoryModel,
|
|
768
|
+
ExpenseModel,
|
|
769
|
+
ForbiddenException,
|
|
770
|
+
HttpException,
|
|
771
|
+
NotFoundException,
|
|
772
|
+
OrderByDirection,
|
|
773
|
+
RelationType,
|
|
774
|
+
SponsorFor,
|
|
775
|
+
SponsorHistoryModel,
|
|
776
|
+
SponsorModel,
|
|
777
|
+
TransactionHistoryModel,
|
|
778
|
+
TransactionModel,
|
|
779
|
+
UnauthorizedException,
|
|
780
|
+
UserModel,
|
|
781
|
+
VendorHistoryModel,
|
|
782
|
+
VendorModel,
|
|
783
|
+
definedValues,
|
|
784
|
+
diffArrays,
|
|
785
|
+
entityListEntityModelMap,
|
|
786
|
+
getObjectDiffingKeys,
|
|
787
|
+
groupBy
|
|
788
|
+
});
|
|
789
|
+
//# sourceMappingURL=index.js.map
|