gemcap-be-common 1.4.69 → 1.4.71

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.
@@ -30,7 +30,7 @@ export declare const fieldsToUnset: string[];
30
30
  export declare const getLoanProductById: (productId: string) => Promise<mongoose.FlattenMaps<import("../models/LoanProducts.model").ILoanProductDoc> & {
31
31
  _id: mongoose.Types.ObjectId;
32
32
  }>;
33
- export declare const getLoanProductBalance: (productId: string, forDate?: Date) => Promise<{
33
+ export declare const getLoanProductBalance: (productId: string, asOfDate?: Date) => Promise<{
34
34
  balance: number;
35
35
  floatedBalance: number;
36
36
  }>;
@@ -21,12 +21,12 @@ const getLoanProductById = async (productId) => {
21
21
  return LoanProducts_model_1.LoanProduct.findById(productId).lean();
22
22
  };
23
23
  exports.getLoanProductById = getLoanProductById;
24
- const getLoanProductBalance = async (productId, forDate = new Date()) => {
24
+ const getLoanProductBalance = async (productId, asOfDate = new Date()) => {
25
25
  const simpleTransactions = await LoanTransaction_model_1.LoanTransaction.aggregate([
26
26
  {
27
27
  $match: {
28
28
  'productId': new mongoose_1.default.Types.ObjectId(productId),
29
- 'date': { $lte: (0, dayjs_1.default)(forDate).startOf('day').subtract(1, 'seconds').toDate() },
29
+ 'date': { $lte: asOfDate },
30
30
  },
31
31
  }, {
32
32
  $sort: {
@@ -42,7 +42,7 @@ const getLoanProductBalance = async (productId, forDate = new Date()) => {
42
42
  {
43
43
  $match: {
44
44
  'productId': new mongoose_1.default.Types.ObjectId(productId),
45
- 'effectiveDate': { $lte: forDate },
45
+ 'effectiveDate': { $lte: asOfDate },
46
46
  $expr: { $ne: ['$date', '$effectiveDate'] },
47
47
  },
48
48
  }, {
@@ -59,7 +59,7 @@ const getLoanProductBalance = async (productId, forDate = new Date()) => {
59
59
  {
60
60
  $match: {
61
61
  'productId': new mongoose_1.default.Types.ObjectId(productId),
62
- 'effectiveDate': { $lte: forDate },
62
+ 'effectiveDate': { $lte: asOfDate },
63
63
  $expr: { $eq: ['$date', '$effectiveDate'] },
64
64
  },
65
65
  }, {
@@ -97,7 +97,7 @@ const getLoanProductBalance = async (productId, forDate = new Date()) => {
97
97
  if (normalTransaction && !collectionsTransaction) {
98
98
  floatedBalance = normalTransaction.floatedBalance;
99
99
  }
100
- const totalPostponed = await (0, exports.getPostponedTransactions)(forDate, productId);
100
+ const totalPostponed = await (0, exports.getPostponedTransactions)(asOfDate, productId);
101
101
  if (transactions.length === 0) {
102
102
  return { balance: 0, floatedBalance: totalPostponed };
103
103
  }
@@ -21,13 +21,13 @@ export const getLoanProductById = async (productId: string) => {
21
21
  return LoanProduct.findById(productId).lean();
22
22
  };
23
23
 
24
- export const getLoanProductBalance = async (productId: string, forDate = new Date()) => {
24
+ export const getLoanProductBalance = async (productId: string, asOfDate = new Date()) => {
25
25
 
26
26
  const simpleTransactions = await LoanTransaction.aggregate<ILoanTransactionDoc>([
27
27
  {
28
28
  $match: {
29
29
  'productId': new mongoose.Types.ObjectId(productId),
30
- 'date': { $lte: dayjs(forDate).startOf('day').subtract(1, 'seconds').toDate() },
30
+ 'date': { $lte: asOfDate },
31
31
  },
32
32
  }, {
33
33
  $sort: {
@@ -44,7 +44,7 @@ export const getLoanProductBalance = async (productId: string, forDate = new Dat
44
44
  {
45
45
  $match: {
46
46
  'productId': new mongoose.Types.ObjectId(productId),
47
- 'effectiveDate': { $lte: forDate },
47
+ 'effectiveDate': { $lte: asOfDate },
48
48
  $expr: { $ne: ['$date', '$effectiveDate'] },
49
49
  },
50
50
  }, {
@@ -62,7 +62,7 @@ export const getLoanProductBalance = async (productId: string, forDate = new Dat
62
62
  {
63
63
  $match: {
64
64
  'productId': new mongoose.Types.ObjectId(productId),
65
- 'effectiveDate': { $lte: forDate },
65
+ 'effectiveDate': { $lte: asOfDate },
66
66
  $expr: { $eq: ['$date', '$effectiveDate'] },
67
67
  },
68
68
  }, {
@@ -103,7 +103,7 @@ export const getLoanProductBalance = async (productId: string, forDate = new Dat
103
103
  if (normalTransaction && !collectionsTransaction) {
104
104
  floatedBalance = normalTransaction.floatedBalance;
105
105
  }
106
- const totalPostponed = await getPostponedTransactions(forDate, productId);
106
+ const totalPostponed = await getPostponedTransactions(asOfDate, productId);
107
107
  if (transactions.length === 0) {
108
108
  return { balance: 0, floatedBalance: totalPostponed };
109
109
  }
@@ -27,4 +27,5 @@ exports.AssignedProspectSchema = new mongoose_1.default.Schema({
27
27
  timestamps: true,
28
28
  versionKey: false,
29
29
  });
30
+ exports.AssignedProspectSchema.index({ borrowerId: 1 }, { unique: true });
30
31
  exports.AssignedProspect = mongoose_1.default.model(_models_1.MODEL_NAMES.assignedProspects, exports.AssignedProspectSchema);
@@ -56,4 +56,6 @@ export const AssignedProspectSchema = new mongoose.Schema<IAssignedProspectDoc>(
56
56
  versionKey: false,
57
57
  });
58
58
 
59
+ AssignedProspectSchema.index({ borrowerId: 1 }, { unique: true });
60
+
59
61
  export const AssignedProspect = mongoose.model<IAssignedProspectDoc>(MODEL_NAMES.assignedProspects, AssignedProspectSchema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.4.69",
3
+ "version": "1.4.71",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -173,7 +173,8 @@ class LoanStatementService {
173
173
  return;
174
174
  }
175
175
  await this.cleanProductStatement(productId, statementDate);
176
- const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs_1.default.utc(statementDate).add(1, 'day').toDate());
176
+ const balanceDate = dayjs_1.default.utc(statementDate).add(1, 'day').subtract(1, 'second').toDate();
177
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, balanceDate);
177
178
  const loanStatementEffectsService = this.getLoanStatementEffectsService();
178
179
  await loanStatementEffectsService.saveMonthData(productId, statementDate);
179
180
  const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
@@ -208,7 +208,8 @@ export class LoanStatementService {
208
208
  return;
209
209
  }
210
210
  await this.cleanProductStatement(productId, statementDate);
211
- const balance = await this.loanChargesService.getLoanProductBalance(productId, dayjs.utc(statementDate).add(1, 'day').toDate());
211
+ const balanceDate = dayjs.utc(statementDate).add(1, 'day').subtract(1, 'second').toDate();
212
+ const balance = await this.loanChargesService.getLoanProductBalance(productId, balanceDate);
212
213
 
213
214
  const loanStatementEffectsService = this.getLoanStatementEffectsService();
214
215
  await loanStatementEffectsService.saveMonthData(productId, statementDate);
@@ -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<{