gemcap-be-common 1.3.185 → 1.3.187

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.3.185",
3
+ "version": "1.3.187",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -14,6 +14,7 @@ export declare class TermLoanService {
14
14
  private readonly getUploadsService;
15
15
  constructor(financialIndexesService: FinancialIndexesService, loanChargesService: LoanChargesService, getLoanStatementStatusService: () => LoanStatementStatusService, getLoanTransactionsService: () => LoanTransactionsService, getUploadsService: () => UploadsService);
16
16
  private createTermLoan;
17
+ private refreshChargeSettings;
17
18
  private createTermLoanSettings;
18
19
  private getCreateTermLoan;
19
20
  getTermLoan(productId: string, actual: boolean): Promise<ITermLoanView & {
@@ -61,6 +61,27 @@ class TermLoanService {
61
61
  };
62
62
  return TermLoan_model_1.TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
63
63
  }
64
+ async refreshChargeSettings(productId, actual) {
65
+ const product = await this.loanChargesService.getLoanProductById(productId);
66
+ const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
67
+ if (charges.length === 0) {
68
+ return null;
69
+ }
70
+ const adminCharge = charges.find((charge) => charge.chargeType === loan_charge_type_enum_1.ELoanChargeType.ADMIN_FEE);
71
+ const interestCharge = charges.find((charge) => charge.chargeType === loan_charge_type_enum_1.ELoanChargeType.INTEREST_FEE);
72
+ if (!adminCharge || !interestCharge) {
73
+ return null;
74
+ }
75
+ const newEmptyTerm = {
76
+ productId: new mongoose_1.default.Types.ObjectId(String(product._id)),
77
+ initialBalance: product.commitment,
78
+ adminRate: adminCharge.percent,
79
+ interestRate: interestCharge.percent,
80
+ loanStartDate: product.startDate,
81
+ actual,
82
+ };
83
+ return TermLoan_model_1.TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
84
+ }
64
85
  async createTermLoanSettings(termLoanId) {
65
86
  return TermLoanSettings_model_1.TermLoanSettingsModel.findOneAndUpdate({ termLoanId }, { termLoanId, ...newEmptySettings }, {
66
87
  upsert: true,
@@ -106,6 +127,7 @@ class TermLoanService {
106
127
  return { ...termLoan, calculated: mappedCalculatedTermLoan };
107
128
  }
108
129
  async saveTermLoanSettings(productId, actual, settings) {
130
+ await this.refreshChargeSettings(productId, actual);
109
131
  let termLoan = await TermLoan_model_1.TermLoanModel.findOne({ productId, actual }).lean();
110
132
  if (!termLoan || termLoan.calculationStatus === TermLoan_model_1.ETermLoanStatus.NEW) {
111
133
  termLoan = await this.createTermLoan(productId, actual);
@@ -82,6 +82,29 @@ export class TermLoanService {
82
82
  return TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
83
83
  }
84
84
 
85
+ private async refreshChargeSettings(productId: string, actual: boolean) {
86
+ const product = await this.loanChargesService.getLoanProductById(productId);
87
+ const charges = await this.loanChargesService.getLoanChargeForProduct(productId);
88
+ if (charges.length === 0) {
89
+ return null;
90
+ }
91
+ const adminCharge = charges.find((charge) => charge.chargeType === ELoanChargeType.ADMIN_FEE);
92
+ const interestCharge = charges.find((charge) => charge.chargeType === ELoanChargeType.INTEREST_FEE);
93
+ if (!adminCharge || !interestCharge) {
94
+ return null;
95
+ }
96
+
97
+ const newEmptyTerm: Partial<ITermLoan> = {
98
+ productId: new mongoose.Types.ObjectId(String(product._id)),
99
+ initialBalance: product.commitment,
100
+ adminRate: adminCharge.percent,
101
+ interestRate: interestCharge.percent,
102
+ loanStartDate: product.startDate,
103
+ actual,
104
+ };
105
+ return TermLoanModel.findOneAndUpdate({ productId, actual }, newEmptyTerm, { upsert: true, new: true });
106
+ }
107
+
85
108
  private async createTermLoanSettings(termLoanId: string) {
86
109
  return TermLoanSettingsModel.findOneAndUpdate({ termLoanId }, { termLoanId, ...newEmptySettings }, {
87
110
  upsert: true,
@@ -135,6 +158,7 @@ export class TermLoanService {
135
158
  }
136
159
 
137
160
  async saveTermLoanSettings(productId: string, actual: boolean, settings: ITermLoanSettingsOnly): Promise<any> {
161
+ await this.refreshChargeSettings(productId, actual);
138
162
  let termLoan = await TermLoanModel.findOne({ productId, actual }).lean();
139
163
  if (!termLoan || termLoan.calculationStatus === ETermLoanStatus.NEW) {
140
164
  termLoan = await this.createTermLoan(productId, actual);