creditu-common-library 2.3.11 → 2.3.13
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/middlewares/app-logger-middleware.js +3 -2
- package/offer/models/dto/offer-params.dto.d.ts +15 -0
- package/offer/services/maximum-local.service.d.ts +1 -1
- package/offer/services/maximum-local.service.js +1 -1
- package/offer/services/offer.service.d.ts +8 -0
- package/offer/services/offer.service.js +30 -2
- package/package.json +1 -1
- package/test/common/offer-service.spec.ts +0 -20
|
@@ -83,6 +83,7 @@ var AppLoggerMiddleware = /** @class */ (function () {
|
|
|
83
83
|
var originalSend = response.send;
|
|
84
84
|
var chunks = [];
|
|
85
85
|
// Interceptar el método send que suele usarse para errores
|
|
86
|
+
// eslint-disable-next-line func-names
|
|
86
87
|
response.send = function (body) {
|
|
87
88
|
if (body && typeof body === 'object' && response.statusCode >= 400) {
|
|
88
89
|
var sanitizedBody = this.sanitizeObject(body);
|
|
@@ -137,7 +138,7 @@ var AppLoggerMiddleware = /** @class */ (function () {
|
|
|
137
138
|
// Sanitizar la respuesta
|
|
138
139
|
var sanitizedResponseBody = this.sanitizeObject(parsedBody);
|
|
139
140
|
// Mensaje base con tiempo de respuesta
|
|
140
|
-
var baseMessage = "".concat(method, " ").concat(originalUrl, " ").concat(statusCode, " ").concat(statusMessage, " - ").concat(responseTime, "ms");
|
|
141
|
+
var baseMessage = "".concat(method, " ").concat(originalUrl, " ").concat(statusCode, " ").concat(statusMessage !== null && statusMessage !== void 0 ? statusMessage : '', " - ").concat(responseTime, "ms");
|
|
141
142
|
// Mensaje detallado con cuerpos de solicitud y respuesta
|
|
142
143
|
var detailedMessage = {
|
|
143
144
|
method: method,
|
|
@@ -156,7 +157,7 @@ var AppLoggerMiddleware = /** @class */ (function () {
|
|
|
156
157
|
this.logger.warn("".concat(baseMessage, "\n").concat(JSON.stringify(detailedMessage, null, 2)));
|
|
157
158
|
}
|
|
158
159
|
else {
|
|
159
|
-
this.logger.log("".concat(baseMessage));
|
|
160
|
+
this.logger.log("".concat(baseMessage, "\n").concat(JSON.stringify(detailedMessage, null, 2)));
|
|
160
161
|
}
|
|
161
162
|
return originalEnd.apply(response, __spreadArray([chunk], args, true));
|
|
162
163
|
}.bind(this);
|
|
@@ -211,4 +211,19 @@ export declare class OfferParams {
|
|
|
211
211
|
* Nombre del producto / servicio financiero
|
|
212
212
|
*/
|
|
213
213
|
product?: string;
|
|
214
|
+
/**
|
|
215
|
+
* Umbral de LTV para cambiar el DR
|
|
216
|
+
* Threshold value for determining which frontend ratio to apply
|
|
217
|
+
*/
|
|
218
|
+
ltvThresholdForFrontendRatio?: number;
|
|
219
|
+
/**
|
|
220
|
+
* DR 40% para LTV > 75%
|
|
221
|
+
* Maximum frontend ratio to apply when LTV is above the threshold
|
|
222
|
+
*/
|
|
223
|
+
maximumFrontendRatioHighLTV?: number;
|
|
224
|
+
/**
|
|
225
|
+
* DR 50% para LTV ≤ 75%
|
|
226
|
+
* Maximum frontend ratio to apply when LTV is below or equal to the threshold
|
|
227
|
+
*/
|
|
228
|
+
maximumFrontendRatioLowLTV?: number;
|
|
214
229
|
}
|
|
@@ -16,7 +16,7 @@ export declare class MaximumLocalService {
|
|
|
16
16
|
/**
|
|
17
17
|
* Función que calcula el Máximo Local Dividendo Renta (M_a^DR)
|
|
18
18
|
* Más info en {@link https://creditu-team.gitlab.io/wiki/content/journeys/acquisition/Offer.html#maximo-local-dividendo-renta}
|
|
19
|
-
* @param params Parámetros definidos por el negocio para el
|
|
19
|
+
* @param params Parámetros definidos por el negocio para el cálculo máximo local
|
|
20
20
|
* @param longTermMonthlyFee Cuota largo plazo (Clp)
|
|
21
21
|
*/
|
|
22
22
|
incomeDividend(params: MaximumLocalParams, longTermMonthlyFee: number): number;
|
|
@@ -36,7 +36,7 @@ var MaximumLocalService = /** @class */ (function () {
|
|
|
36
36
|
/**
|
|
37
37
|
* Función que calcula el Máximo Local Dividendo Renta (M_a^DR)
|
|
38
38
|
* Más info en {@link https://creditu-team.gitlab.io/wiki/content/journeys/acquisition/Offer.html#maximo-local-dividendo-renta}
|
|
39
|
-
* @param params Parámetros definidos por el negocio para el
|
|
39
|
+
* @param params Parámetros definidos por el negocio para el cálculo máximo local
|
|
40
40
|
* @param longTermMonthlyFee Cuota largo plazo (Clp)
|
|
41
41
|
*/
|
|
42
42
|
MaximumLocalService.prototype.incomeDividend = function (params, longTermMonthlyFee) {
|
|
@@ -101,4 +101,12 @@ export declare class OfferService {
|
|
|
101
101
|
* @param creditMaxAmount
|
|
102
102
|
*/
|
|
103
103
|
getCreditAmountToOffer(approvedAmount: number, credituAmount: number, creditMinAmount: CreditAmount, creditMaxAmount: CreditAmount): number;
|
|
104
|
+
/**
|
|
105
|
+
* Ajusta el ratio máximo de frontend (dividendo/renta) en base al LTV
|
|
106
|
+
* @param maximumFrontendRatio - Ratio máximo de frontend original (por defecto)
|
|
107
|
+
* @param estimatedLoanToValueHome - LTV estimado para la operación
|
|
108
|
+
* @param params - Parámetros de la oferta
|
|
109
|
+
* @returns Ratio máximo de frontend ajustado
|
|
110
|
+
*/
|
|
111
|
+
private adjustMaximumFrontendRatio;
|
|
104
112
|
}
|
|
@@ -121,12 +121,14 @@ var OfferService = /** @class */ (function () {
|
|
|
121
121
|
// creditInsuranceFactor,
|
|
122
122
|
creditInsurancePercentageFinanced);
|
|
123
123
|
var amountRequestedByClient = this.amountRequestedByClient(downPayment, subsidy, propertyValue);
|
|
124
|
+
var estimatedLoanToValueHome = this.math.divide(amountRequestedByClient, propertyValue);
|
|
124
125
|
var kScr = this.constantService.calculateKScr();
|
|
125
126
|
// creditInsuranceFactor,
|
|
126
127
|
// creditInsurancePercentageFinanced,
|
|
127
128
|
// creditInsuranceNumberOfMonths
|
|
128
129
|
var k1Gop = this.constantService.calculateK1Gop(creditTaxRate, creditTaxRatePercentage, operationalExpensesFinancing, operationalExpensesInterest, operationalExpensesNumberOfMonths);
|
|
129
130
|
var k2Gop = this.constantService.calculateK2Gop(operationalExpensesWeightedSum, operationalExpensesFinancing, operationalExpensesInterest, operationalExpensesNumberOfMonths);
|
|
131
|
+
var adjustedMaximumFrontendRatio = this.adjustMaximumFrontendRatio(maximumFrontendRatio, estimatedLoanToValueHome, params);
|
|
130
132
|
var maximumLocalParams = {
|
|
131
133
|
creditInsuranceFactor: creditInsuranceFactor,
|
|
132
134
|
creditInsurancePercentageFinanced: creditInsurancePercentageFinanced.value(),
|
|
@@ -146,7 +148,7 @@ var OfferService = /** @class */ (function () {
|
|
|
146
148
|
purpose: purpose,
|
|
147
149
|
investmentWeight: investmentWeight,
|
|
148
150
|
maximumBackendRatio: maximumBackendRatio,
|
|
149
|
-
maximumFrontendRatio:
|
|
151
|
+
maximumFrontendRatio: adjustedMaximumFrontendRatio,
|
|
150
152
|
numberOfGraceMonths: numberOfGraceMonths,
|
|
151
153
|
creditInsuranceNumberOfMonths: creditInsuranceNumberOfMonths
|
|
152
154
|
};
|
|
@@ -166,6 +168,7 @@ var OfferService = /** @class */ (function () {
|
|
|
166
168
|
? 0
|
|
167
169
|
: operationalExpensesFinanceable;
|
|
168
170
|
var loanToValueCredit = this.ltv.credit(financingAmount, creditInsurancePremium, propertyValue, creditInsurancePercentageFinanced, operationalExpensesFinanced, operationalExpensesFinancing);
|
|
171
|
+
var financingRatio = this.math.divide(financingAmount, amountRequestedByClient);
|
|
169
172
|
var loanToValueHome = this.ltv.home(financingAmount, propertyValue);
|
|
170
173
|
var creditInsuranceInstallment = this.insurance.creditInsurance(financingAmount, creditInsuranceFactor, creditInsurancePercentageFinanced.value(), creditInsuranceNumberOfMonths, isCreditInsuranceAccelerated, creditInsurancePremium, numberOfGraceMonths, installment);
|
|
171
174
|
var lifeInsuranceFee = this.insurance.lifeInsurance(creditAmount, totalLifeInsuranceMonthlyRate);
|
|
@@ -232,7 +235,7 @@ var OfferService = /** @class */ (function () {
|
|
|
232
235
|
operationalExpensesFinanced: operationalExpensesFinanced,
|
|
233
236
|
operationalExpenses: operationalExpenses,
|
|
234
237
|
creditInsuranceFactor: creditInsuranceFactor,
|
|
235
|
-
financingRatio:
|
|
238
|
+
financingRatio: financingRatio
|
|
236
239
|
};
|
|
237
240
|
};
|
|
238
241
|
/**
|
|
@@ -361,6 +364,31 @@ var OfferService = /** @class */ (function () {
|
|
|
361
364
|
return 0;
|
|
362
365
|
return minApprovedAmount;
|
|
363
366
|
};
|
|
367
|
+
/**
|
|
368
|
+
* Ajusta el ratio máximo de frontend (dividendo/renta) en base al LTV
|
|
369
|
+
* @param maximumFrontendRatio - Ratio máximo de frontend original (por defecto)
|
|
370
|
+
* @param estimatedLoanToValueHome - LTV estimado para la operación
|
|
371
|
+
* @param params - Parámetros de la oferta
|
|
372
|
+
* @returns Ratio máximo de frontend ajustado
|
|
373
|
+
*/
|
|
374
|
+
OfferService.prototype.adjustMaximumFrontendRatio = function (maximumFrontendRatio, estimatedLoanToValueHome, params) {
|
|
375
|
+
// Valor original por defecto
|
|
376
|
+
var adjustedMaximumFrontendRatio = maximumFrontendRatio;
|
|
377
|
+
// Si existen los parámetros de umbral, ajustar el maximumFrontendRatio directamente
|
|
378
|
+
if (params.ltvThresholdForFrontendRatio !== undefined
|
|
379
|
+
&& params.maximumFrontendRatioHighLTV !== undefined
|
|
380
|
+
&& params.maximumFrontendRatioLowLTV !== undefined) {
|
|
381
|
+
if (estimatedLoanToValueHome <= params.ltvThresholdForFrontendRatio) {
|
|
382
|
+
// LTV por debajo o igual al umbral - aplicar ratio mayor
|
|
383
|
+
adjustedMaximumFrontendRatio = new models_1.MaximumFrontendRatio(params.maximumFrontendRatioLowLTV);
|
|
384
|
+
}
|
|
385
|
+
else {
|
|
386
|
+
// LTV por encima del umbral - aplicar ratio menor
|
|
387
|
+
adjustedMaximumFrontendRatio = new models_1.MaximumFrontendRatio(params.maximumFrontendRatioHighLTV);
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
return adjustedMaximumFrontendRatio;
|
|
391
|
+
};
|
|
364
392
|
return OfferService;
|
|
365
393
|
}());
|
|
366
394
|
exports.OfferService = OfferService;
|
package/package.json
CHANGED
|
@@ -49,26 +49,6 @@ describe('offer service functional tests common', () => {
|
|
|
49
49
|
expect(result).toBe(70);
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
|
-
describe('getPropertyValue', () => {
|
|
53
|
-
it('getPropertyValue should return commercialValue when appraisal is 0', () => {
|
|
54
|
-
// ACT
|
|
55
|
-
const result = offerService.getPropertyValue(0, 70);
|
|
56
|
-
// ASSERT
|
|
57
|
-
expect(result).toBe(70);
|
|
58
|
-
});
|
|
59
|
-
it('getPropertyValue should return appraisal when appraisal is less than commercialValue', () => {
|
|
60
|
-
// ACT
|
|
61
|
-
const result = offerService.getPropertyValue(10, 70);
|
|
62
|
-
// ASSERT
|
|
63
|
-
expect(result).toBe(10);
|
|
64
|
-
});
|
|
65
|
-
it('getPropertyValue should return appraicommercialValuesal when commercialValue is less than appraisalValue', () => {
|
|
66
|
-
// ACT
|
|
67
|
-
const result = offerService.getPropertyValue(60, 30);
|
|
68
|
-
// ASSERT
|
|
69
|
-
expect(result).toBe(30);
|
|
70
|
-
});
|
|
71
|
-
});
|
|
72
52
|
describe('getApprovedAmount', () => {
|
|
73
53
|
it('getApprovedAmount should return maximumLocalFinanceCharge when is the minimum value', () => {
|
|
74
54
|
// ACT
|