gemcap-be-common 1.5.67 → 1.5.69

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/db/reports.db.js CHANGED
@@ -207,7 +207,7 @@ const getLedgerData = async (params, options = defaultReportLedgerOptions) => {
207
207
  };
208
208
  }))
209
209
  : statementTransactions.slice();
210
- const isParticipant = group.product.masteredLoanProductId != null;
210
+ const isParticipant = group.product.masterLoanProductId != null;
211
211
  const groupedMappedStatementTransactions = await Promise.all(statementTransactionsWithBalance.map(async (statement) => {
212
212
  const transactions = [];
213
213
  if (statement.amountPaid > 0) {
package/db/reports.db.ts CHANGED
@@ -285,7 +285,7 @@ const getLedgerData = async (params: ReportLedgerParams, options = defaultReport
285
285
  }))
286
286
  : statementTransactions.slice();
287
287
 
288
- const isParticipant = group.product.masteredLoanProductId != null;
288
+ const isParticipant = group.product.masterLoanProductId != null;
289
289
  const groupedMappedStatementTransactions = await Promise.all(statementTransactionsWithBalance.map(async (statement) => {
290
290
 
291
291
  const transactions = [];
@@ -40,7 +40,7 @@ export interface ILoanProduct {
40
40
  isBalanceActual: boolean;
41
41
  isFloatedBalanceActual: boolean;
42
42
  isParticipant?: boolean;
43
- masteredLoanProductId: mongoose.Types.ObjectId;
43
+ masterLoanProductId: mongoose.Types.ObjectId;
44
44
  minPercent: number;
45
45
  maxPercent: number;
46
46
  prepaymentDate?: Date;
@@ -60,10 +60,10 @@ export interface ILoanProductLean extends ILoanProduct {
60
60
  createdAt: Date;
61
61
  updatedAt: Date;
62
62
  }
63
- export interface ILoanProductPlain extends Omit<ILoanProduct, 'borrowerId' | 'masteredLoanProductId'> {
63
+ export interface ILoanProductPlain extends Omit<ILoanProduct, 'borrowerId' | 'masterLoanProductId'> {
64
64
  _id: string;
65
65
  borrowerId: string;
66
- masteredLoanProductId: string;
66
+ masterLoanProductId: string;
67
67
  }
68
68
  export interface ILoanProductWithId extends ILoanProduct {
69
69
  _id: mongoose.Types.ObjectId;
@@ -84,7 +84,7 @@ export declare const LoanProductSchema: mongoose.Schema<any, mongoose.Model<any,
84
84
  updatedAt: NativeDate;
85
85
  } & {
86
86
  borrowerId: mongoose.Types.ObjectId;
87
- masteredLoanProductId: mongoose.Types.ObjectId;
87
+ masterLoanProductId: mongoose.Types.ObjectId;
88
88
  order: number;
89
89
  active: boolean;
90
90
  code: string;
@@ -111,7 +111,7 @@ export declare const LoanProductSchema: mongoose.Schema<any, mongoose.Model<any,
111
111
  updatedAt: NativeDate;
112
112
  } & {
113
113
  borrowerId: mongoose.Types.ObjectId;
114
- masteredLoanProductId: mongoose.Types.ObjectId;
114
+ masterLoanProductId: mongoose.Types.ObjectId;
115
115
  order: number;
116
116
  active: boolean;
117
117
  code: string;
@@ -138,7 +138,7 @@ export declare const LoanProductSchema: mongoose.Schema<any, mongoose.Model<any,
138
138
  updatedAt: NativeDate;
139
139
  } & {
140
140
  borrowerId: mongoose.Types.ObjectId;
141
- masteredLoanProductId: mongoose.Types.ObjectId;
141
+ masterLoanProductId: mongoose.Types.ObjectId;
142
142
  order: number;
143
143
  active: boolean;
144
144
  code: string;
@@ -68,7 +68,7 @@ exports.LoanProductSchema = new mongoose_1.default.Schema({
68
68
  type: Boolean,
69
69
  required: false,
70
70
  },
71
- masteredLoanProductId: {
71
+ masterLoanProductId: {
72
72
  type: mongoose_1.default.Schema.Types.ObjectId,
73
73
  ref: _models_1.MODEL_NAMES.loanProducts,
74
74
  default: null,
@@ -19,7 +19,7 @@ export interface ILoanProduct {
19
19
  isBalanceActual: boolean;
20
20
  isFloatedBalanceActual: boolean;
21
21
  isParticipant?: boolean;
22
- masteredLoanProductId: mongoose.Types.ObjectId;
22
+ masterLoanProductId: mongoose.Types.ObjectId;
23
23
  minPercent: number;
24
24
  maxPercent: number;
25
25
  prepaymentDate?: Date;
@@ -42,10 +42,10 @@ export interface ILoanProductLean extends ILoanProduct {
42
42
  updatedAt: Date;
43
43
  }
44
44
 
45
- export interface ILoanProductPlain extends Omit<ILoanProduct, 'borrowerId' | 'masteredLoanProductId'> {
45
+ export interface ILoanProductPlain extends Omit<ILoanProduct, 'borrowerId' | 'masterLoanProductId'> {
46
46
  _id: string;
47
47
  borrowerId: string;
48
- masteredLoanProductId: string;
48
+ masterLoanProductId: string;
49
49
  }
50
50
 
51
51
  export interface ILoanProductWithId extends ILoanProduct {
@@ -128,7 +128,7 @@ export const LoanProductSchema = new mongoose.Schema(
128
128
  type: Boolean,
129
129
  required: false,
130
130
  },
131
- masteredLoanProductId: {
131
+ masterLoanProductId: {
132
132
  type: mongoose.Schema.Types.ObjectId,
133
133
  ref: MODEL_NAMES.loanProducts,
134
134
  default: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.5.67",
3
+ "version": "1.5.69",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -84,10 +84,10 @@ export declare class BorrowerService {
84
84
  getBorrowerCodesMap(): Promise<Map<string, string>>;
85
85
  getBorrowerStatementDetails(borrowers: IBorrowerDoc[]): Promise<{
86
86
  [x: string]: {
87
- SELECTED_PERIOD?: boolean;
88
- ENTIRE_LOAN?: boolean;
89
87
  LAST_MONTH?: boolean;
90
88
  CURRENT_MONTH?: boolean;
89
+ ENTIRE_LOAN?: boolean;
90
+ SELECTED_PERIOD?: boolean;
91
91
  TERM_LOAN?: boolean;
92
92
  };
93
93
  }>;
@@ -23,27 +23,28 @@
23
23
  /// <reference types="mongoose/types/virtuals" />
24
24
  /// <reference types="mongoose/types/inferschematype" />
25
25
  import mongoose from 'mongoose';
26
- import { IEmailRecipient } from '../models/ComplianceItem.model';
26
+ import { IBorrowerItemDocument, IBorrowerItemInstanceDocument, IEmailRecipient } from '../models/ComplianceItem.model';
27
27
  import { IGroupedEmailsUpdate } from '../interfaces/email-addresses.interface';
28
28
  import { IComplianceBorrowerWithBorrower, IComplianceBorrowerDocumentFull, IComplianceBorrowerWithPlaidToken } from '../models/BorrowerCompliance.model';
29
29
  import { IUserAccess } from '../interfaces/auth-user.interface';
30
30
  import { FileManagerService } from './file-manager.service';
31
31
  import { UploadsService } from './uploads.service';
32
+ export interface IInstanceStatus {
33
+ progress: {
34
+ text: string;
35
+ status: string;
36
+ };
37
+ score: {
38
+ value: number;
39
+ tooltip: string;
40
+ };
41
+ }
32
42
  export declare class ComplianceBorrowersService {
33
43
  private readonly _fileManagerService;
34
44
  private readonly _uploadsService;
35
45
  constructor(_fileManagerService: FileManagerService, _uploadsService: UploadsService);
36
46
  isComplianceBorrowerAllowed(userAccess: IUserAccess, requestedBorrowerId: string): boolean;
37
- calculateInstanceStatuses(instance: any, item: any): {
38
- progress: {
39
- text: string;
40
- status: string;
41
- };
42
- score: {
43
- value: number;
44
- tooltip: string;
45
- };
46
- };
47
+ calculateInstanceStatuses(instance: IBorrowerItemInstanceDocument, item: IBorrowerItemDocument): IInstanceStatus;
47
48
  getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<any>;
48
49
  getAllBorrowersShortened(userAccess: IUserAccess): Promise<(Pick<IComplianceBorrowerWithBorrower, "borrower" | "fundingStatus" | "items"> | {
49
50
  items: {
@@ -2,7 +2,12 @@ import dayjs, { ManipulateType } from 'dayjs';
2
2
  import _ from 'lodash';
3
3
  import mongoose from 'mongoose';
4
4
 
5
- import { IBorrowerItemDocument, IEmailRecipient } from '../models/ComplianceItem.model';
5
+ import {
6
+ IBorrowerItemDocument,
7
+ IBorrowerItemInstanceDocument,
8
+ IComplianceFile,
9
+ IEmailRecipient,
10
+ } from '../models/ComplianceItem.model';
6
11
  import { IGroupedEmailsUpdate } from '../interfaces/email-addresses.interface';
7
12
  import { EItemProgressStatus } from '../enums/item-progress-status.enum';
8
13
  import {
@@ -35,6 +40,17 @@ const dueDifference = (date) => {
35
40
  return currentDate.diff(nextDate, 'day');
36
41
  };
37
42
 
43
+ export interface IInstanceStatus {
44
+ progress: {
45
+ text: string;
46
+ status: string;
47
+ };
48
+ score: {
49
+ value: number;
50
+ tooltip: string;
51
+ };
52
+ }
53
+
38
54
  export class ComplianceBorrowersService {
39
55
 
40
56
  constructor(
@@ -51,7 +67,7 @@ export class ComplianceBorrowersService {
51
67
  return true;
52
68
  }
53
69
 
54
- calculateInstanceStatuses(instance, item) {
70
+ calculateInstanceStatuses(instance: IBorrowerItemInstanceDocument, item: IBorrowerItemDocument): IInstanceStatus {
55
71
  let progress: { text: string, status: string };
56
72
  let score: { value: number, tooltip: string } = null;
57
73
  if (instance.submittedDate) {
@@ -77,7 +93,7 @@ export class ComplianceBorrowersService {
77
93
  return { progress, score };
78
94
  }
79
95
 
80
- async getFullComplianceBorrowerById(complianceBorrowerId: string): Promise<any> {
96
+ async getFullComplianceBorrowerById(complianceBorrowerId: string) {
81
97
  if (!complianceBorrowerId) {
82
98
  return null;
83
99
  }
@@ -109,7 +125,7 @@ export class ComplianceBorrowersService {
109
125
  return Promise.resolve(null);
110
126
  }
111
127
 
112
- const items = { items: [], ...ourBorrower }.items.map((item) => {
128
+ const items = { items: [] as IBorrowerItemDocument[], ...ourBorrower }.items.map((item) => {
113
129
  return {
114
130
  ...item,
115
131
  instances: item.instances.reduce((acc, instance) => {
@@ -124,7 +140,10 @@ export class ComplianceBorrowersService {
124
140
  console.error({ e });
125
141
  return acc;
126
142
  }
127
- }, []),
143
+ }, <(IBorrowerItemInstanceDocument & IInstanceStatus & {
144
+ itemId: mongoose.Types.ObjectId,
145
+ files: IComplianceFile[]
146
+ })[]>[]),
128
147
  };
129
148
  });
130
149
  return Promise.resolve({ ...ourBorrower, items });
@@ -85,7 +85,7 @@ class LoanChargesService {
85
85
  if (!masterProduct) {
86
86
  return 0;
87
87
  }
88
- const participationProduct = await LoanProducts_model_1.LoanProduct.findOne({ masteredLoanProductId: masterProduct._id }).lean();
88
+ const participationProduct = await LoanProducts_model_1.LoanProduct.findOne({ masterLoanProductId: masterProduct._id }).lean();
89
89
  if (!participationProduct) {
90
90
  return 0;
91
91
  }
@@ -155,9 +155,7 @@ class LoanChargesService {
155
155
  }
156
156
  }
157
157
  else {
158
- console.debug({ product });
159
- const updated = await LoanProducts_model_1.LoanProduct.findByIdAndUpdate(product._id, product, { new: true });
160
- console.debug({ updated });
158
+ await LoanProducts_model_1.LoanProduct.findByIdAndUpdate(product._id, product);
161
159
  if (updateChargesForProduct) {
162
160
  await this.updatedChargeCodes(product._id.toString());
163
161
  }
@@ -112,7 +112,7 @@ export class LoanChargesService {
112
112
  if (!masterProduct) {
113
113
  return 0;
114
114
  }
115
- const participationProduct = await LoanProduct.findOne({ masteredLoanProductId: masterProduct._id }).lean();
115
+ const participationProduct = await LoanProduct.findOne({ masterLoanProductId: masterProduct._id }).lean();
116
116
  if (!participationProduct) {
117
117
  return 0;
118
118
  }
@@ -184,9 +184,7 @@ export class LoanChargesService {
184
184
  await this.saveLoanCharges(borrowerId, charges, true);
185
185
  }
186
186
  } else {
187
- console.debug({ product });
188
- const updated = await LoanProduct.findByIdAndUpdate(product._id, product, { new: true });
189
- console.debug({ updated });
187
+ await LoanProduct.findByIdAndUpdate(product._id, product);
190
188
  if (updateChargesForProduct) {
191
189
  await this.updatedChargeCodes(product._id.toString());
192
190
  }
@@ -25,7 +25,7 @@ class LoanProductsService {
25
25
  const masterProducts = await LoanProducts_model_1.LoanProduct.find({ code: { $in: codes } });
26
26
  const masterProductIds = masterProducts.map((product) => product._id);
27
27
  const loanProducts = await LoanProducts_model_1.LoanProduct
28
- .find({ masteredLoanProductId: { $in: masterProductIds } })
28
+ .find({ masterLoanProductId: { $in: masterProductIds } })
29
29
  .sort({ code: 1 })
30
30
  .lean();
31
31
  return loanProducts.reduce((acc, loanProduct) => ({ ...acc, [loanProduct.code]: loanProduct._id.toString() }), {});
@@ -29,7 +29,7 @@ export class LoanProductsService {
29
29
  const masterProducts = await LoanProduct.find({ code: { $in: codes } });
30
30
  const masterProductIds = masterProducts.map((product) => product._id);
31
31
  const loanProducts = await LoanProduct
32
- .find({ masteredLoanProductId: { $in: masterProductIds } })
32
+ .find({ masterLoanProductId: { $in: masterProductIds } })
33
33
  .sort({ code: 1 })
34
34
  .lean();
35
35
  return loanProducts.reduce((acc, loanProduct) => ({ ...acc, [loanProduct.code]: loanProduct._id.toString() }), {});
@@ -155,7 +155,7 @@ export declare class LoanTransactionsService {
155
155
  getTransactionReport(transactionIds: string[], borrowerId: string, effectiveDate: Date): Promise<{
156
156
  transactionIdsToMark: string[];
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<{
@@ -357,7 +357,7 @@ class QuickbooksService {
357
357
  if (totalAmountValue === 0) {
358
358
  return;
359
359
  }
360
- let totalAmount = product.masteredLoanProductId != null ? -totalAmountValue : totalAmountValue;
360
+ let totalAmount = product.masterLoanProductId != null ? -totalAmountValue : totalAmountValue;
361
361
  totalAmount = isAccrual ? totalAmount : -totalAmount;
362
362
  const quickbooksAccountBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
363
363
  const quickbooksAccountPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
@@ -374,7 +374,7 @@ class QuickbooksService {
374
374
  ...trTemplate,
375
375
  productId,
376
376
  class: borrower.code,
377
- memo: `${borrower.code} ${product.masteredLoanProductId != null ? 'PARTICIPANT' : ''} ${reports_db_1.EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
377
+ memo: `${borrower.code} ${product.masterLoanProductId != null ? 'PARTICIPANT' : ''} ${reports_db_1.EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
378
378
  };
379
379
  tr.account = quickbooksAccountBS.fullName;
380
380
  tr.amount = totalAmount;
@@ -429,8 +429,8 @@ class QuickbooksService {
429
429
  ...trTemplate,
430
430
  productId,
431
431
  class: borrower.code,
432
- amount: product.masteredLoanProductId != null ? +amount : -+amount,
433
- memo: `${borrower.code} ${product.masteredLoanProductId != null ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
432
+ amount: product.masterLoanProductId != null ? +amount : -+amount,
433
+ memo: `${borrower.code} ${product.masterLoanProductId != null ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
434
434
  };
435
435
  if (settlementCode === 'null') {
436
436
  const products = await this.loanChargesService.getLoanProducts(borrower._id.toString());
@@ -416,7 +416,7 @@ export class QuickbooksService {
416
416
  if (totalAmountValue === 0) {
417
417
  return;
418
418
  }
419
- let totalAmount = product.masteredLoanProductId != null ? -totalAmountValue : totalAmountValue;
419
+ let totalAmount = product.masterLoanProductId != null ? -totalAmountValue : totalAmountValue;
420
420
  totalAmount = isAccrual ? totalAmount : -totalAmount;
421
421
  const quickbooksAccountBS = await QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
422
422
  const quickbooksAccountPL = await QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
@@ -433,7 +433,7 @@ export class QuickbooksService {
433
433
  ...trTemplate,
434
434
  productId,
435
435
  class: borrower.code,
436
- memo: `${borrower.code} ${product.masteredLoanProductId != null ? 'PARTICIPANT' : ''} ${EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
436
+ memo: `${borrower.code} ${product.masterLoanProductId != null ? 'PARTICIPANT' : ''} ${EChargeType[charge.chargeType].toUpperCase()} ${product.type.toUpperCase()} - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
437
437
  };
438
438
 
439
439
  tr.account = quickbooksAccountBS.fullName;
@@ -500,8 +500,8 @@ export class QuickbooksService {
500
500
  ...trTemplate,
501
501
  productId,
502
502
  class: borrower.code,
503
- amount: product.masteredLoanProductId != null ? +amount : -+amount,
504
- memo: `${borrower.code} ${product.masteredLoanProductId != null ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
503
+ amount: product.masterLoanProductId != null ? +amount : -+amount,
504
+ memo: `${borrower.code} ${product.masterLoanProductId != null ? 'PARTICIPANT' : ''} PRINCIPAL PAID TERM - TRANS: ${reportDateTrFormatted} - POST: ${currentDateTrFormatted}`,
505
505
  };
506
506
 
507
507
  if (settlementCode === 'null') {
@@ -76,7 +76,7 @@ class InvestorSummaryService {
76
76
  await Promise.all(borrowerIds.map(async (borrowerId) => {
77
77
  const borrower = await Borrower_model_1.BorrowerModel.findById(borrowerId).lean();
78
78
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrowerId);
79
- await Promise.all(borrowerProducts.filter((product) => product.masteredLoanProductId == null).map(async (product) => {
79
+ await Promise.all(borrowerProducts.filter((product) => product.masterLoanProductId == null).map(async (product) => {
80
80
  const productId = product._id.toString();
81
81
  const isRevolver = product.type === loan_types_enum_1.ELoanTypes.REVOLVER;
82
82
  const { balance: balanceEnd } = await this.loanChargesService.getLoanProductBalance(productId, end);
@@ -100,7 +100,7 @@ export class InvestorSummaryService {
100
100
  await Promise.all(borrowerIds.map(async (borrowerId) => {
101
101
  const borrower = await BorrowerModel.findById(borrowerId).lean();
102
102
  const borrowerProducts = await this.loanChargesService.getLoanProducts(borrowerId);
103
- await Promise.all(borrowerProducts.filter((product) => product.masteredLoanProductId == null).map(async (product) => {
103
+ await Promise.all(borrowerProducts.filter((product) => product.masterLoanProductId == null).map(async (product) => {
104
104
  const productId = product._id.toString();
105
105
  const isRevolver = product.type === ELoanTypes.REVOLVER;
106
106
  const { balance: balanceEnd } = await this.loanChargesService.getLoanProductBalance(productId, end);
@@ -323,7 +323,7 @@ class ReportsService {
323
323
  const hasTermProduct = products.some((product) => product.type === loan_types_enum_1.ELoanTypes.TERM);
324
324
  const manyTermProduct = products.filter((product) => product.type === loan_types_enum_1.ELoanTypes.TERM).length > 1;
325
325
  return await Promise.all(products.map(async (product) => {
326
- if (product.masteredLoanProductId != null) {
326
+ if (product.masterLoanProductId != null) {
327
327
  return null;
328
328
  }
329
329
  if ((0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(date))) {
@@ -426,7 +426,7 @@ export class ReportsService {
426
426
  const manyTermProduct = products.filter((product) => product.type === ELoanTypes.TERM).length > 1;
427
427
 
428
428
  return await Promise.all(products.map(async (product) => {
429
- if (product.masteredLoanProductId != null) {
429
+ if (product.masterLoanProductId != null) {
430
430
  return null as IBankReportData;
431
431
  }
432
432
  if (dayjs(product.deactivationDate).isBefore(dayjs(date))) {