gemcap-be-common 1.4.100 → 1.4.102

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.100",
3
+ "version": "1.4.102",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -43,7 +43,14 @@ interface IWorkingDaysApi {
43
43
  export declare class CalendarService {
44
44
  private readonly calendarRepository;
45
45
  constructor(calendarRepository: CalendarRepository);
46
- fulfillCalendar(): Promise<void>;
46
+ /**
47
+ * Download a calendar from working days API and save it to DB.
48
+ * It will download all days between startDate and endDate inclusive,
49
+ * for example,
50
+ * startDate as 2025-01-01
51
+ * endDate as 2026-01-01
52
+ */
53
+ fulfillCalendar(startDate: string, endDate: string): Promise<void>;
47
54
  createDate(date: string, dateProp: IWorkingDaysApi): Promise<void>;
48
55
  isWorkingDay(date: string): Promise<boolean>;
49
56
  isLastWorkingDay(date: string): Promise<boolean>;
@@ -12,11 +12,18 @@ class CalendarService {
12
12
  constructor(calendarRepository) {
13
13
  this.calendarRepository = calendarRepository;
14
14
  }
15
- async fulfillCalendar() {
15
+ /**
16
+ * Download a calendar from working days API and save it to DB.
17
+ * It will download all days between startDate and endDate inclusive,
18
+ * for example,
19
+ * startDate as 2025-01-01
20
+ * endDate as 2026-01-01
21
+ */
22
+ async fulfillCalendar(startDate, endDate) {
16
23
  const getDays = () => {
17
24
  const days = [];
18
- const start = (0, dayjs_1.default)('2025-01-01');
19
- const end = (0, dayjs_1.default)('2026-01-01'); // TODO add custom date
25
+ const start = (0, dayjs_1.default)(startDate);
26
+ const end = (0, dayjs_1.default)(endDate);
20
27
  for (let day = (0, dayjs_1.default)(start); day.isBefore(end); day = day.add(1, 'day')) {
21
28
  days.push(day.format('YYYY-MM-DD'));
22
29
  }
@@ -28,12 +28,19 @@ export class CalendarService {
28
28
  ) {
29
29
  }
30
30
 
31
- async fulfillCalendar() {
31
+ /**
32
+ * Download a calendar from working days API and save it to DB.
33
+ * It will download all days between startDate and endDate inclusive,
34
+ * for example,
35
+ * startDate as 2025-01-01
36
+ * endDate as 2026-01-01
37
+ */
38
+ async fulfillCalendar(startDate: string, endDate: string) {
32
39
 
33
40
  const getDays = () => {
34
41
  const days: string[] = [];
35
- const start = dayjs('2025-01-01');
36
- const end = dayjs('2026-01-01'); // TODO add custom date
42
+ const start = dayjs(startDate);
43
+ const end = dayjs(endDate);
37
44
  for (let day = dayjs(start); day.isBefore(end); day = day.add(1, 'day')) {
38
45
  days.push(day.format('YYYY-MM-DD'));
39
46
  }
@@ -24,6 +24,7 @@ class LoanStatementStatusService {
24
24
  let currentDate = (0, dayjs_1.default)(product.startDate).utcOffset(0).startOf('month');
25
25
  while (currentDate.diff(endDate, 'month') <= 0) {
26
26
  const statementDate = this.getStatementDateForDate(currentDate.toDate());
27
+ console.log('initStatementStatuses');
27
28
  await this.getCreateStatementStatus(product._id.toString(), statementDate);
28
29
  currentDate = currentDate.add(1, 'month');
29
30
  }
@@ -68,6 +69,7 @@ class LoanStatementStatusService {
68
69
  return [{ start: startOfMonth, end: endOfMonth }];
69
70
  }
70
71
  async toggleStatementLock(productId, statementDate) {
72
+ console.log('toggleStatementLock');
71
73
  const statementStatus = await this.getCreateStatementStatus(productId, statementDate);
72
74
  if (statementStatus) {
73
75
  statementStatus.locked = !statementStatus.locked;
@@ -75,6 +77,7 @@ class LoanStatementStatusService {
75
77
  }
76
78
  }
77
79
  async updateStatementStatus(productId, statementDate, actual) {
80
+ console.log('updateStatementStatus');
78
81
  const statementStatus = await this.getCreateStatementStatus(productId, statementDate);
79
82
  if (statementStatus && !statementStatus.locked) {
80
83
  statementStatus.actual = actual;
@@ -99,6 +102,7 @@ class LoanStatementStatusService {
99
102
  }
100
103
  async getStatementStatus(productId, date) {
101
104
  const statementDate = this.getStatementDateForDate(date);
105
+ console.log('getStatementStatus');
102
106
  return this.getCreateStatementStatus(productId, statementDate);
103
107
  }
104
108
  async getCreateStatementStatus(productId, statementDate) {
@@ -151,6 +155,7 @@ class LoanStatementStatusService {
151
155
  const loanChargesService = this.getLoanChargesService();
152
156
  const products = await loanChargesService.getLoanProducts(borrowerId);
153
157
  const lastResults = await Promise.all(products.map(async (product) => {
158
+ console.log('getBorrowerMonthStatus');
154
159
  return await this.getCreateStatementStatus(product._id.toString(), statementDate);
155
160
  }));
156
161
  return lastResults.reduce((acc, res) => res.actual && acc, true);
@@ -30,6 +30,7 @@ export class LoanStatementStatusService {
30
30
  let currentDate = dayjs(product.startDate).utcOffset(0).startOf('month');
31
31
  while (currentDate.diff(endDate, 'month') <= 0) {
32
32
  const statementDate = this.getStatementDateForDate(currentDate.toDate());
33
+ console.log('initStatementStatuses');
33
34
  await this.getCreateStatementStatus(product._id.toString(), statementDate);
34
35
  currentDate = currentDate.add(1, 'month');
35
36
  }
@@ -82,6 +83,7 @@ export class LoanStatementStatusService {
82
83
  }
83
84
 
84
85
  async toggleStatementLock(productId: string, statementDate: ISelectedMonth) {
86
+ console.log('toggleStatementLock');
85
87
  const statementStatus = await this.getCreateStatementStatus(productId, statementDate);
86
88
  if (statementStatus) {
87
89
  statementStatus.locked = !statementStatus.locked;
@@ -90,6 +92,7 @@ export class LoanStatementStatusService {
90
92
  }
91
93
 
92
94
  async updateStatementStatus(productId: string, statementDate: ISelectedMonth, actual: boolean) {
95
+ console.log('updateStatementStatus');
93
96
  const statementStatus = await this.getCreateStatementStatus(productId, statementDate);
94
97
  if (statementStatus && !statementStatus.locked) {
95
98
  statementStatus.actual = actual;
@@ -116,6 +119,7 @@ export class LoanStatementStatusService {
116
119
 
117
120
  async getStatementStatus(productId: string, date: Date) {
118
121
  const statementDate = this.getStatementDateForDate(date);
122
+ console.log('getStatementStatus');
119
123
  return this.getCreateStatementStatus(productId, statementDate);
120
124
  }
121
125
 
@@ -136,7 +140,6 @@ export class LoanStatementStatusService {
136
140
  await newStatementStatus.save();
137
141
  return newStatementStatus;
138
142
  }
139
-
140
143
  }
141
144
 
142
145
  async validateDate(productId: string, date: Date) {
@@ -170,6 +173,7 @@ export class LoanStatementStatusService {
170
173
  const loanChargesService = this.getLoanChargesService();
171
174
  const products = await loanChargesService.getLoanProducts(borrowerId);
172
175
  const lastResults = await Promise.all(products.map(async (product) => {
176
+ console.log('getBorrowerMonthStatus');
173
177
  return await this.getCreateStatementStatus(product._id.toString(), statementDate);
174
178
  }));
175
179
  return lastResults.reduce((acc, res) => res.actual && acc, true);
@@ -155,7 +155,7 @@ export declare class LoanTransactionsService {
155
155
  getTransactionReport(transactionIds: string[], borrowerId: string, effectiveDate: Date): Promise<{
156
156
  transactionIdsToMark: any[];
157
157
  transactions: {
158
- [x: string]: (string | number | Date | string[])[];
158
+ [x: string]: (string | number | string[] | Date)[];
159
159
  }[];
160
160
  }>;
161
161
  getBorrowerIdsForFile(transactionFileId: string): Promise<{