@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.
@@ -0,0 +1,488 @@
1
+ declare enum EntityHistoryOperation {
2
+ CREATE = "CREATE",
3
+ UPDATE = "UPDATE",
4
+ DELETE = "DELETE"
5
+ }
6
+
7
+ declare enum SponsorFor {
8
+ GHEE = "ghee",
9
+ PRASAD = "prasad",
10
+ BANNER = "banner"
11
+ }
12
+
13
+ interface IAuditColumnEntity {
14
+ createdOn: number;
15
+ updatedOn: number;
16
+ createdBy: number;
17
+ updatedBy: number;
18
+ }
19
+
20
+ interface IDonationEntity extends IAuditColumnEntity {
21
+ id: number;
22
+ flatNo: string;
23
+ amount: number;
24
+ }
25
+
26
+ interface IBaseHistoryEntity extends IAuditColumnEntity {
27
+ id: number;
28
+ entityId: number;
29
+ data: string;
30
+ operation: EntityHistoryOperation;
31
+ }
32
+
33
+ interface IDonationHistoryEntity extends IBaseHistoryEntity {
34
+ }
35
+
36
+ interface IExpenseEntity extends IAuditColumnEntity {
37
+ id: number;
38
+ name: string;
39
+ type: string;
40
+ vendorName: string;
41
+ amount: number;
42
+ }
43
+
44
+ interface IExpenseHistoryEntity extends IBaseHistoryEntity {
45
+ }
46
+
47
+ interface ISponsorEntity extends IAuditColumnEntity {
48
+ id: number;
49
+ contactName: string;
50
+ contactNo: string;
51
+ sponsorFor: SponsorFor;
52
+ size: string;
53
+ amount: number;
54
+ }
55
+
56
+ interface ISponsorHistoryEntity extends IBaseHistoryEntity {
57
+ }
58
+
59
+ type TransactionType = 'Income' | 'Expense' | 'Sponsor';
60
+ interface ITransactionEntity extends IAuditColumnEntity {
61
+ id: number;
62
+ date: string;
63
+ type: TransactionType;
64
+ particulars: string;
65
+ amount: number;
66
+ balanceAfter: number;
67
+ referenceId: string;
68
+ }
69
+
70
+ interface ITransactionHistoryEntity extends IBaseHistoryEntity {
71
+ }
72
+
73
+ interface IUserEntity extends IAuditColumnEntity {
74
+ id: number;
75
+ name: string;
76
+ password: string;
77
+ email: string;
78
+ phone: string;
79
+ }
80
+
81
+ interface IVendorEntity extends IAuditColumnEntity {
82
+ id: number;
83
+ name: string;
84
+ type: string;
85
+ }
86
+
87
+ interface IVendorHistoryEntity extends IBaseHistoryEntity {
88
+ }
89
+
90
+ /**
91
+ * Utility class for validating date codes in `YYYYMMDD` format.
92
+ *
93
+ * @example new DateCodeUtils(20240315)
94
+ *
95
+ * @methods
96
+ * - `isValidYYYYMMDD()` — checks if the date code is a real calendar date. e.g. `new DateCodeUtils(20240315).isValidYYYYMMDD() // true`
97
+ */
98
+ declare class DateCodeUtils {
99
+ private readonly dateCode;
100
+ stringifiedDateCode: string;
101
+ constructor(dateCode: string | number);
102
+ isValidYYYYMMDD(): boolean;
103
+ toLongDateString(): string;
104
+ addMonths(months: number): string;
105
+ addDays(days: number): string;
106
+ addWeeks(weeks: number): string;
107
+ addYears(years: number): string;
108
+ private parseDateParts;
109
+ static getCurrentYear(): number;
110
+ static daysDiff(dateCode: string | number): number;
111
+ static getCurrentDateCode(): string;
112
+ }
113
+
114
+ declare class DateUtil {
115
+ static now(): number;
116
+ static toEpoch(date: Date): number;
117
+ static toDate(epoch: number): Date;
118
+ static toReadable(epoch: number): string;
119
+ static addDays(epoch: number, days: number): number;
120
+ static addMonths(epoch: number, months: number): number;
121
+ static addWeeks(epoch: number, weeks: number): number;
122
+ static addYears(epoch: number, years: number): number;
123
+ static daysDifference(epoch1: number, epoch2: number): number;
124
+ static isToday(epoch: number): boolean;
125
+ static isPast(epoch: number): boolean;
126
+ static isFuture(epoch: number): boolean;
127
+ }
128
+
129
+ declare class DonationHistoryModel extends BaseEntityModel implements IDonationHistoryEntity {
130
+ id: number;
131
+ entityId: number;
132
+ data: string;
133
+ operation: EntityHistoryOperation;
134
+ createdOn: number;
135
+ updatedOn: number;
136
+ createdBy: number;
137
+ updatedBy: number;
138
+ protected constructor();
139
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList.DONATION_HISTORY>>>;
140
+ static populateFromEntity(entity: IDonationHistoryEntity): DonationHistoryModel;
141
+ }
142
+
143
+ declare class ExpenseModel extends BaseEntityModel implements IExpenseEntity {
144
+ id: number;
145
+ name: string;
146
+ type: string;
147
+ vendorName: string;
148
+ amount: number;
149
+ createdOn: number;
150
+ updatedOn: number;
151
+ createdBy: number;
152
+ updatedBy: number;
153
+ protected constructor();
154
+ static populateFromEntity(entity: IExpenseEntity): ExpenseModel;
155
+ }
156
+
157
+ declare class ExpenseHistoryModel extends BaseEntityModel implements IExpenseHistoryEntity {
158
+ id: number;
159
+ entityId: number;
160
+ data: string;
161
+ operation: EntityHistoryOperation;
162
+ createdOn: number;
163
+ updatedOn: number;
164
+ createdBy: number;
165
+ updatedBy: number;
166
+ protected constructor();
167
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList.EXPENSE_HISTORY>>>;
168
+ static populateFromEntity(entity: IExpenseHistoryEntity): ExpenseHistoryModel;
169
+ }
170
+
171
+ declare class SponsorModel extends BaseEntityModel implements ISponsorEntity {
172
+ id: number;
173
+ contactName: string;
174
+ contactNo: string;
175
+ sponsorFor: SponsorFor;
176
+ size: string;
177
+ amount: number;
178
+ createdOn: number;
179
+ updatedOn: number;
180
+ createdBy: number;
181
+ updatedBy: number;
182
+ protected constructor();
183
+ static populateFromEntity(entity: ISponsorEntity): SponsorModel;
184
+ }
185
+
186
+ declare class SponsorHistoryModel extends BaseEntityModel implements ISponsorHistoryEntity {
187
+ id: number;
188
+ entityId: number;
189
+ data: string;
190
+ operation: EntityHistoryOperation;
191
+ createdOn: number;
192
+ updatedOn: number;
193
+ createdBy: number;
194
+ updatedBy: number;
195
+ protected constructor();
196
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList.SPONSOR_HISTORY>>>;
197
+ static populateFromEntity(entity: ISponsorHistoryEntity): SponsorHistoryModel;
198
+ }
199
+
200
+ declare class TransactionModel extends BaseEntityModel implements ITransactionEntity {
201
+ id: number;
202
+ date: string;
203
+ type: TransactionType;
204
+ particulars: string;
205
+ amount: number;
206
+ balanceAfter: number;
207
+ referenceId: string;
208
+ createdOn: number;
209
+ updatedOn: number;
210
+ createdBy: number;
211
+ updatedBy: number;
212
+ protected constructor();
213
+ static populateFromEntity(entity: ITransactionEntity): TransactionModel;
214
+ }
215
+
216
+ declare class TransactionHistoryModel extends BaseEntityModel implements ITransactionHistoryEntity {
217
+ id: number;
218
+ entityId: number;
219
+ data: string;
220
+ operation: EntityHistoryOperation;
221
+ createdOn: number;
222
+ updatedOn: number;
223
+ createdBy: number;
224
+ updatedBy: number;
225
+ protected constructor();
226
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList.TRANSACTION_HISTORY>>>;
227
+ static populateFromEntity(entity: ITransactionHistoryEntity): TransactionHistoryModel;
228
+ }
229
+
230
+ declare class UserModel extends BaseEntityModel implements IUserEntity {
231
+ id: number;
232
+ name: string;
233
+ password: string;
234
+ email: string;
235
+ phone: string;
236
+ createdOn: number;
237
+ updatedOn: number;
238
+ createdBy: number;
239
+ updatedBy: number;
240
+ protected constructor();
241
+ static populateFromEntity(entity: IUserEntity): UserModel;
242
+ }
243
+
244
+ declare class VendorModel extends BaseEntityModel implements IVendorEntity {
245
+ id: number;
246
+ name: string;
247
+ type: string;
248
+ createdOn: number;
249
+ updatedOn: number;
250
+ createdBy: number;
251
+ updatedBy: number;
252
+ protected constructor();
253
+ static populateFromEntity(entity: IVendorEntity): VendorModel;
254
+ }
255
+
256
+ declare class VendorHistoryModel extends BaseEntityModel implements IVendorHistoryEntity {
257
+ id: number;
258
+ entityId: number;
259
+ data: string;
260
+ operation: EntityHistoryOperation;
261
+ createdOn: number;
262
+ updatedOn: number;
263
+ createdBy: number;
264
+ updatedBy: number;
265
+ protected constructor();
266
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList.VENDOR_HISTORY>>>;
267
+ static populateFromEntity(entity: IVendorHistoryEntity): VendorHistoryModel;
268
+ }
269
+
270
+ declare const entityListEntityModelMap: {
271
+ donation: typeof DonationModel.populateFromEntity;
272
+ donation_history: typeof DonationHistoryModel.populateFromEntity;
273
+ user: typeof UserModel.populateFromEntity;
274
+ expense: typeof ExpenseModel.populateFromEntity;
275
+ expense_history: typeof ExpenseHistoryModel.populateFromEntity;
276
+ vendor: typeof VendorModel.populateFromEntity;
277
+ vendor_history: typeof VendorHistoryModel.populateFromEntity;
278
+ transaction: typeof TransactionModel.populateFromEntity;
279
+ transaction_history: typeof TransactionHistoryModel.populateFromEntity;
280
+ sponsor: typeof SponsorModel.populateFromEntity;
281
+ sponsor_history: typeof SponsorHistoryModel.populateFromEntity;
282
+ };
283
+
284
+ declare class HttpException extends Error {
285
+ readonly message: string;
286
+ readonly statusCode: number;
287
+ readonly key?: string | undefined;
288
+ readonly errors?: any | undefined;
289
+ constructor(message: string, statusCode: number, key?: string | undefined, errors?: any | undefined);
290
+ getResponse(): {
291
+ statusCode: number;
292
+ message: string;
293
+ key: string | undefined;
294
+ errors: any;
295
+ };
296
+ getStatus(): number;
297
+ }
298
+ declare class BadRequestException extends HttpException {
299
+ constructor(input: {
300
+ key: string;
301
+ message: string;
302
+ } | string | string[], errors?: any);
303
+ }
304
+ declare class NotFoundException extends HttpException {
305
+ constructor(input?: {
306
+ key: string;
307
+ message: string;
308
+ } | string);
309
+ }
310
+ declare class UnauthorizedException extends HttpException {
311
+ constructor(input?: {
312
+ key: string;
313
+ message: string;
314
+ } | string);
315
+ }
316
+ declare class ForbiddenException extends HttpException {
317
+ constructor(input?: {
318
+ key: string;
319
+ message: string;
320
+ } | string);
321
+ }
322
+
323
+ declare function getObjectDiffingKeys<T extends Record<string, any>>(oldObject: T, newObject: T): Partial<T>;
324
+ /**
325
+ * Compares two arrays and returns the difference between them.
326
+ *
327
+ * @template T - The type of elements in the arrays
328
+ * @param {T[]} arr1 - The original array
329
+ * @param {T[]} arr2 - The new array to compare against
330
+ * @returns {{ present: T[], deleted: T[], added: T[] }} An object containing:
331
+ * - `present` — items found in both arrays (intersection)
332
+ * - `deleted` — items in `arr1` but not in `arr2`
333
+ * - `added` — items in `arr2` but not in `arr1`
334
+ *
335
+ * @example
336
+ * const arr1 = [1, 2, 3, 4];
337
+ * const arr2 = [3, 4, 5, 6];
338
+ *
339
+ * diffArrays(arr1, arr2);
340
+ * // {
341
+ * // present: [3, 4],
342
+ * // deleted: [1, 2],
343
+ * // added: [5, 6]
344
+ * // }
345
+ */
346
+ declare function diffArrays<T>(arr1: T[], arr2: T[]): {
347
+ present: T[];
348
+ deleted: T[];
349
+ added: T[];
350
+ };
351
+ /**
352
+ * Groups an array of objects by a specified key, returning a `Map` where each
353
+ * unique value of the key becomes an entry containing all items that share that value.
354
+ * Use this as a fallback if `Object.groupBy` (ES2024) is not available in your environment.
355
+ *
356
+ * @template T - The type of objects in the array
357
+ * @param items - The array of objects to group
358
+ * @param key - A key of `T` whose value will be used as the group identifier
359
+ * @returns A `Map` where each key maps to an array of items belonging to that group
360
+ *
361
+ * @example
362
+ * const grouped = groupBy(items, 'someKey');
363
+ * grouped.get('keyValue1'); // [item1, item2]
364
+ * grouped.get('keyValue2'); // [item3]
365
+ */
366
+ declare function groupBy<T>(items: T[], key: keyof T): Map<string, T[]>;
367
+ declare function definedValues<T>(arr: Array<T | undefined | null>): T[];
368
+
369
+ declare enum RelationType {
370
+ ONE = "ONE",
371
+ MANY = "MANY"
372
+ }
373
+ interface IModelRelationConfig<T extends EntityList> {
374
+ relationType: RelationType;
375
+ mappingProperty: keyof EntityType<T> & string;
376
+ searchProperty: string;
377
+ entity: EntityList;
378
+ }
379
+
380
+ declare enum OrderByDirection {
381
+ ASC = "ASC",
382
+ DESC = "DESC"
383
+ }
384
+
385
+ declare abstract class BaseEntityModel {
386
+ static relations: Partial<Record<EntityList, IModelRelationConfig<EntityList>>>;
387
+ populateRelations(searchResponse: ISearchV2Response, visited?: Set<string>): this;
388
+ }
389
+
390
+ declare class DonationModel extends BaseEntityModel implements IDonationEntity {
391
+ id: number;
392
+ flatNo: string;
393
+ amount: number;
394
+ createdOn: number;
395
+ updatedOn: number;
396
+ createdBy: number;
397
+ updatedBy: number;
398
+ protected constructor();
399
+ static populateFromEntity(entity: IDonationEntity): DonationModel;
400
+ }
401
+
402
+ declare enum EntityList {
403
+ DONATION = "donation",
404
+ DONATION_HISTORY = "donation_history",
405
+ USER = "user",
406
+ EXPENSE = "expense",
407
+ EXPENSE_HISTORY = "expense_history",
408
+ VENDOR = "vendor",
409
+ VENDOR_HISTORY = "vendor_history",
410
+ TRANSACTION = "transaction",
411
+ TRANSACTION_HISTORY = "transaction_history",
412
+ SPONSOR = "sponsor",
413
+ SPONSOR_HISTORY = "sponsor_history"
414
+ }
415
+ type EntityType<T extends EntityList> = T extends EntityList.DONATION ? IDonationEntity : T extends EntityList.DONATION_HISTORY ? IDonationHistoryEntity : T extends EntityList.USER ? IUserEntity : T extends EntityList.EXPENSE ? IExpenseEntity : T extends EntityList.EXPENSE_HISTORY ? IExpenseHistoryEntity : T extends EntityList.VENDOR ? IVendorEntity : T extends EntityList.VENDOR_HISTORY ? IVendorHistoryEntity : T extends EntityList.TRANSACTION ? ITransactionEntity : T extends EntityList.TRANSACTION_HISTORY ? ITransactionHistoryEntity : T extends EntityList.SPONSOR ? ISponsorEntity : T extends EntityList.SPONSOR_HISTORY ? ISponsorHistoryEntity : never;
416
+ type EntityModelType<T extends EntityList> = T extends EntityList.DONATION ? DonationModel : T extends EntityList.DONATION_HISTORY ? DonationHistoryModel : T extends EntityList.USER ? UserModel : T extends EntityList.EXPENSE ? ExpenseModel : T extends EntityList.EXPENSE_HISTORY ? ExpenseHistoryModel : T extends EntityList.VENDOR ? VendorModel : T extends EntityList.VENDOR_HISTORY ? VendorHistoryModel : T extends EntityList.TRANSACTION ? TransactionModel : T extends EntityList.TRANSACTION_HISTORY ? TransactionHistoryModel : T extends EntityList.SPONSOR ? SponsorModel : T extends EntityList.SPONSOR_HISTORY ? SponsorHistoryModel : never;
417
+ type EntityListEntityModelMap = {
418
+ [T in EntityList]: EntityModelType<T>[];
419
+ };
420
+
421
+ type IEntityCreateDto<T> = Omit<T, "id" | keyof IAuditColumnEntity>;
422
+ type IEntityUpdateDto<T> = Omit<Partial<T>, "id" | keyof IAuditColumnEntity>;
423
+ type IEntityFilterSearchData<K extends EntityList = EntityList> = {
424
+ name: K;
425
+ include?: IEntityFilterData<EntityType<K>>;
426
+ relations?: IEntityFilterSearchData<EntityList>[];
427
+ columnKeys?: (keyof EntityType<K>)[];
428
+ orderBy?: Partial<Record<keyof EntityType<K>, OrderByDirection>>;
429
+ limit?: number;
430
+ };
431
+ type IEntityFilterData<T> = {
432
+ [K in keyof T]?: T[K][];
433
+ } & {
434
+ include?: IEntityFilterData<EntityType<EntityList>>;
435
+ columnKeys?: (keyof T)[];
436
+ entities?: IEntityFilterSearchData<EntityList>[];
437
+ relations?: IEntityFilterSearchData<EntityList>[];
438
+ orderBy?: Partial<Record<keyof T, OrderByDirection>>;
439
+ limit?: number;
440
+ };
441
+ interface IEntityFilterSearchDataV2<K extends EntityList = EntityList> {
442
+ /**
443
+ * Root entity being queried
444
+ */
445
+ name: K;
446
+ /**
447
+ * Query configuration + filters
448
+ */
449
+ filter?: IEntityFilterData<EntityType<K>>;
450
+ }
451
+ type ISearchV2Response = {
452
+ [key in EntityList]?: EntityType<key>[];
453
+ };
454
+
455
+ /**
456
+ * Helper class for extracting typed entities from a `searchV2` response.
457
+ *
458
+ * @example new EntityFilterDataHelper(searchV2Response)
459
+ *
460
+ * @methods
461
+ * - `getEntityFromList(name)` — returns typed entity array for the given `EntityList` key. e.g. `helper.getEntityFromList(EntityList.USER) // IUserEntity[]`
462
+ */
463
+ declare class EntityFilterDataHelper {
464
+ private readonly searchResponse;
465
+ entityModelsMap: EntityListEntityModelMap;
466
+ constructor(searchResponse: ISearchV2Response);
467
+ getEntityFromList<T extends EntityList>(name: T): EntityModelType<T>[];
468
+ private populateEntityModelsMap;
469
+ getEntityModelsByFilter<T extends EntityList>(entityName: T, filter: {
470
+ key: keyof EntityType<T> & string;
471
+ value: any[];
472
+ }): EntityModelType<T>[];
473
+ getEntityModelByFilter<T extends EntityList>(entityName: T, filter: {
474
+ key: keyof EntityType<T> & string;
475
+ value: any;
476
+ }): EntityModelType<T>;
477
+ populateRelationsFor(entityNames: EntityList[]): EntityListEntityModelMap;
478
+ mergeEntity<T extends EntityList>(entityName: T, savedEntity: EntityType<T>): EntityModelType<T>;
479
+ }
480
+
481
+ interface IDtoValidationError {
482
+ key: string;
483
+ message: string;
484
+ }
485
+
486
+ type Nullable<T> = T | null;
487
+
488
+ export { BadRequestException, BaseEntityModel, DateCodeUtils, DateUtil, DonationHistoryModel, DonationModel, EntityFilterDataHelper, EntityHistoryOperation, EntityList, type EntityListEntityModelMap, type EntityModelType, type EntityType, ExpenseHistoryModel, ExpenseModel, ForbiddenException, HttpException, type IAuditColumnEntity, type IBaseHistoryEntity, type IDonationEntity, type IDonationHistoryEntity, type IDtoValidationError, type IEntityCreateDto, type IEntityFilterData, type IEntityFilterSearchData, type IEntityFilterSearchDataV2, type IEntityUpdateDto, type IExpenseEntity, type IExpenseHistoryEntity, type IModelRelationConfig, type ISearchV2Response, type ISponsorEntity, type ISponsorHistoryEntity, type ITransactionEntity, type ITransactionHistoryEntity, type IUserEntity, type IVendorEntity, type IVendorHistoryEntity, NotFoundException, type Nullable, OrderByDirection, RelationType, SponsorFor, SponsorHistoryModel, SponsorModel, TransactionHistoryModel, TransactionModel, type TransactionType, UnauthorizedException, UserModel, VendorHistoryModel, VendorModel, definedValues, diffArrays, entityListEntityModelMap, getObjectDiffingKeys, groupBy };