creditu-common-library 1.0.13 → 1.0.17

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.
@@ -12,7 +12,7 @@ var GreaterThanVo = /** @class */ (function () {
12
12
  }
13
13
  GreaterThanVo.prototype.guardValidValue = function (value) {
14
14
  if (value < this.min) {
15
- throw new Error("Invalid " + this.className + " value " + value + " should be greater than " + this.min);
15
+ throw new Error("Invalid ".concat(this.className, " value ").concat(value, " should be greater than ").concat(this.min));
16
16
  }
17
17
  };
18
18
  GreaterThanVo.prototype.value = function () {
@@ -6,12 +6,12 @@ var Guarder = /** @class */ (function () {
6
6
  }
7
7
  Guarder.defined = function (value, name) {
8
8
  if (value == null) {
9
- throw Error(name + " must be defined");
9
+ throw Error("".concat(name, " must be defined"));
10
10
  }
11
11
  };
12
12
  Guarder.includes = function (value, enumObject, enumName) {
13
13
  if (!Object.values(enumObject).includes(value)) {
14
- throw Error(value + " must be a valid option of " + enumName);
14
+ throw Error("".concat(value, " must be a valid option of ").concat(enumName));
15
15
  }
16
16
  };
17
17
  return Guarder;
@@ -14,16 +14,16 @@ var RangeVo = /** @class */ (function () {
14
14
  var maxMsg = this.config.maxInclusive ? ' inclusive' : ' not inclusive';
15
15
  var minMsg = this.config.minInclusive ? ' inclusive' : ' not inclusive';
16
16
  if (this.config.maxInclusive && value > this.config.max) {
17
- throw new Error("Invalid " + this.className + " value " + value + " is out of range " + this.config.min + minMsg + ", " + this.config.max + maxMsg);
17
+ throw new Error("Invalid ".concat(this.className, " value ").concat(value, " is out of range ").concat(this.config.min).concat(minMsg, ", ").concat(this.config.max).concat(maxMsg));
18
18
  }
19
19
  if (!this.config.maxInclusive && value >= this.config.max) {
20
- throw new Error("Invalid " + this.className + " value " + value + " is out of range " + this.config.min + minMsg + ", " + this.config.max + maxMsg);
20
+ throw new Error("Invalid ".concat(this.className, " value ").concat(value, " is out of range ").concat(this.config.min).concat(minMsg, ", ").concat(this.config.max).concat(maxMsg));
21
21
  }
22
22
  if (!this.config.minInclusive && value <= this.config.min) {
23
- throw new Error("Invalid " + this.className + " value " + value + " is out of range " + this.config.min + minMsg + ", " + this.config.max + maxMsg);
23
+ throw new Error("Invalid ".concat(this.className, " value ").concat(value, " is out of range ").concat(this.config.min).concat(minMsg, ", ").concat(this.config.max).concat(maxMsg));
24
24
  }
25
25
  if (this.config.minInclusive && value < this.config.min) {
26
- throw new Error("Invalid " + this.className + " value " + value + " is out of range " + this.config.min + minMsg + ", " + this.config.max + maxMsg);
26
+ throw new Error("Invalid ".concat(this.className, " value ").concat(value, " is out of range ").concat(this.config.min).concat(minMsg, ", ").concat(this.config.max).concat(maxMsg));
27
27
  }
28
28
  };
29
29
  RangeVo.prototype.value = function () {
@@ -62,8 +62,8 @@ var InstallmentService = /** @class */ (function () {
62
62
  var doublePvSum = 0;
63
63
  var numberOfDoublePayments = 0;
64
64
  for (var i = 0; i < numberOfMonths; i += 1) {
65
- var paymentDate = date_1.getPaymentDateForRow(firstPaymentDate, i, delayMonths, delayMonthsOffset);
66
- var currentMonthIsDoublePaymentMonth = date_1.isDoublePaymentMonth(paymentDate, numberOfAnnualDoublePayments, indexOfFirstDoublePayment, secondDoublePaymmentIndex);
65
+ var paymentDate = (0, date_1.getPaymentDateForRow)(firstPaymentDate, i, delayMonths, delayMonthsOffset);
66
+ var currentMonthIsDoublePaymentMonth = (0, date_1.isDoublePaymentMonth)(paymentDate, numberOfAnnualDoublePayments, indexOfFirstDoublePayment, secondDoublePaymmentIndex);
67
67
  if (currentMonthIsDoublePaymentMonth) {
68
68
  var currentPv = _this.getPresentValueFactor(monthlyInterestRate, i);
69
69
  doublePvSum = _this.math.add(doublePvSum, currentPv);
@@ -0,0 +1,7 @@
1
+ import { MathService } from '../../math';
2
+ export declare class InsuranceService {
3
+ private readonly math;
4
+ constructor(math?: MathService);
5
+ getPropertyInsurance(propertyAmount: number, propertyInsuranceRate: number): number;
6
+ getLifeInsurance(lifeInsuranceRate: number, newBalanceBefore: number, ipcaUpdate: number, negativeAmortization: number): number;
7
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InsuranceService = void 0;
4
+ var math_1 = require("../../math");
5
+ var InsuranceService = /** @class */ (function () {
6
+ function InsuranceService(math) {
7
+ if (math === void 0) { math = new math_1.MathService(true, 10); }
8
+ this.math = math;
9
+ }
10
+ InsuranceService.prototype.getPropertyInsurance = function (propertyAmount, propertyInsuranceRate) {
11
+ if (!propertyInsuranceRate)
12
+ throw new Error('Invalid property insurance rate');
13
+ return this.math.round(this.math.multiply(propertyAmount, this.math.divide(propertyInsuranceRate, 100)), 2);
14
+ };
15
+ InsuranceService.prototype.getLifeInsurance = function (lifeInsuranceRate, newBalanceBefore, ipcaUpdate, negativeAmortization) {
16
+ if (!lifeInsuranceRate)
17
+ throw new Error('Invalid life insurance rate');
18
+ var lifeInsurance = this.math.multiply(this.math.add(newBalanceBefore, ipcaUpdate, negativeAmortization), this.math.divide(lifeInsuranceRate, 100));
19
+ return this.math.round(lifeInsurance, 2);
20
+ };
21
+ return InsuranceService;
22
+ }());
23
+ exports.InsuranceService = InsuranceService;
@@ -0,0 +1,6 @@
1
+ import { MathService } from '../../math';
2
+ export declare class IPCAService {
3
+ private readonly math;
4
+ constructor(math?: MathService);
5
+ getIPCAByDate(dueDate: string, dailyRate1In: number, dailyRate2In: number): number;
6
+ }
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.IPCAService = void 0;
4
+ var creditu_date_model_1 = require("creditu-date-model");
5
+ var math_1 = require("../../math");
6
+ var IPCAService = /** @class */ (function () {
7
+ function IPCAService(math) {
8
+ if (math === void 0) { math = new math_1.MathService(true, 10); }
9
+ this.math = math;
10
+ }
11
+ IPCAService.prototype.getIPCAByDate = function (dueDate, dailyRate1In, dailyRate2In) {
12
+ var validDate = new Date(dueDate);
13
+ if (!(validDate instanceof Date) || !validDate.getTime())
14
+ throw new Error('Invalid dueDate');
15
+ if (dailyRate1In === undefined || dailyRate1In === null || dailyRate2In === undefined || dailyRate2In === null)
16
+ throw new Error('Invalid ipca rate');
17
+ var _a = dueDate.split('-'), year = _a[0], month = _a[1];
18
+ var getDateOfMonth = function (year, month, day) { return new creditu_date_model_1.DateModel("".concat(year, "-").concat(month, "-").concat(day)); };
19
+ var startDateBlock1 = getDateOfMonth(year, month, '05');
20
+ var startDateBlock2 = getDateOfMonth(year, (parseInt(month, 10) + 1).toString(), '01');
21
+ var endDateBlock1 = startDateBlock2.substractDays(1);
22
+ var endDateBlock2 = getDateOfMonth(year, (parseInt(month, 10) + 1).toString(), '05');
23
+ var daysBlock1 = this.math.add(endDateBlock1.daysDiff(startDateBlock1), 1);
24
+ var daysBlock2 = this.math.add(endDateBlock2.daysDiff(startDateBlock2), 1);
25
+ var totalDays = (daysBlock1 + daysBlock2);
26
+ var dailyRate1 = this.math.divide(dailyRate1In, 100);
27
+ var dailyRate2 = this.math.divide(dailyRate2In, 100);
28
+ var blocks1 = this.math.divide(this.math.multiply(dailyRate1, daysBlock1), totalDays);
29
+ var blocks2 = this.math.divide(this.math.multiply(dailyRate2, daysBlock2), totalDays);
30
+ return this.math.add(this.math.round(blocks1, 10), this.math.round(blocks2, 10));
31
+ };
32
+ return IPCAService;
33
+ }());
34
+ exports.IPCAService = IPCAService;
@@ -46,7 +46,7 @@ var MaximumLocalService = /** @class */ (function () {
46
46
  * @param k2Fin
47
47
  */
48
48
  MaximumLocalService.prototype.debtGuaranteeViv = function (propertyValue, maximumPropertyLTV, k1Fin, k2Fin) {
49
- return this.math.divide(this.math.subtract(this.math.multiply(propertyValue, maximumPropertyLTV.value()), k2Fin), k1Fin);
49
+ return this.math.divide(this.math.add(this.math.multiply(propertyValue, maximumPropertyLTV.value()), k2Fin), k1Fin);
50
50
  };
51
51
  /**
52
52
  * Función que calcula el Máximo Local Deuda Garantía LTV (M_a^LTV)
@@ -111,7 +111,7 @@ var OfferService = /** @class */ (function () {
111
111
  * Diciembre = 11
112
112
  */
113
113
  var indexOfSecondDoublePayment = 11;
114
- baseMonthlyPayment = this.installment.getBaseMonthlyDoublePayment(monthlyInterestRate, numberOfMonths, numberOfAnnualDoublePayments, indexOfFirstDoublePayment, indexOfSecondDoublePayment);
114
+ (baseMonthlyPayment = this.installment.getBaseMonthlyDoublePayment(monthlyInterestRate, numberOfMonths, numberOfAnnualDoublePayments, indexOfFirstDoublePayment, indexOfSecondDoublePayment).baseMonthlyDoublePayment);
115
115
  }
116
116
  else {
117
117
  baseMonthlyPayment = this.installment.getBaseMonthlyPayment(numberOfGraceMonths, graceMonthsInterestMethod, monthlyInterestRate, numberOfMonths, amortizationMethod);
@@ -23,13 +23,13 @@ var DineroFactory = /** @class */ (function () {
23
23
  var numberAsInt;
24
24
  if (this.hasDecimalPart(numberSplit)) {
25
25
  numberPrecision = numberSplit[this.decimalIndex].length;
26
- numberAsInt = parseInt("" + numberSplit[this.wholeIndex] + numberSplit[this.decimalIndex], 10);
26
+ numberAsInt = parseInt("".concat(numberSplit[this.wholeIndex]).concat(numberSplit[this.decimalIndex]), 10);
27
27
  }
28
28
  else {
29
29
  numberPrecision = 0;
30
- numberAsInt = parseInt("" + numberSplit[this.wholeIndex], 10);
30
+ numberAsInt = parseInt("".concat(numberSplit[this.wholeIndex]), 10);
31
31
  }
32
- return dinero_js_1.default({ amount: numberAsInt, precision: numberPrecision });
32
+ return (0, dinero_js_1.default)({ amount: numberAsInt, precision: numberPrecision });
33
33
  };
34
34
  DineroFactory.hasDecimalPart = function (numberSplit) {
35
35
  return numberSplit.length === 2;
@@ -1,8 +1,12 @@
1
1
  "use strict";
2
- var __spreadArray = (this && this.__spreadArray) || function (to, from) {
3
- for (var i = 0, il = from.length, j = to.length; i < il; i++, j++)
4
- to[j] = from[i];
5
- return to;
2
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
3
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
4
+ if (ar || !(i in from)) {
5
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
6
+ ar[i] = from[i];
7
+ }
8
+ }
9
+ return to.concat(ar || Array.prototype.slice.call(from));
6
10
  };
7
11
  Object.defineProperty(exports, "__esModule", { value: true });
8
12
  exports.MathService = void 0;
@@ -31,28 +35,28 @@ var MathService = /** @class */ (function () {
31
35
  for (var _i = 0; _i < arguments.length; _i++) {
32
36
  numbers[_i] = arguments[_i];
33
37
  }
34
- return _this.applyOperation.apply(_this, __spreadArray([Operation.ADD], numbers));
38
+ return _this.applyOperation.apply(_this, __spreadArray([Operation.ADD], numbers, false));
35
39
  };
36
40
  this.subtract = function () {
37
41
  var numbers = [];
38
42
  for (var _i = 0; _i < arguments.length; _i++) {
39
43
  numbers[_i] = arguments[_i];
40
44
  }
41
- return _this.applyOperation.apply(_this, __spreadArray([Operation.SUBTRACT], numbers));
45
+ return _this.applyOperation.apply(_this, __spreadArray([Operation.SUBTRACT], numbers, false));
42
46
  };
43
47
  this.multiply = function () {
44
48
  var numbers = [];
45
49
  for (var _i = 0; _i < arguments.length; _i++) {
46
50
  numbers[_i] = arguments[_i];
47
51
  }
48
- return _this.applyOperation.apply(_this, __spreadArray([Operation.MULTIPLY], numbers));
52
+ return _this.applyOperation.apply(_this, __spreadArray([Operation.MULTIPLY], numbers, false));
49
53
  };
50
54
  this.divide = function () {
51
55
  var numbers = [];
52
56
  for (var _i = 0; _i < arguments.length; _i++) {
53
57
  numbers[_i] = arguments[_i];
54
58
  }
55
- return _this.applyOperation.apply(_this, __spreadArray([Operation.DIVIDE], numbers));
59
+ return _this.applyOperation.apply(_this, __spreadArray([Operation.DIVIDE], numbers, false));
56
60
  };
57
61
  }
58
62
  MathService.prototype.customRound = function (num) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "creditu-common-library",
3
- "version": "1.0.13",
3
+ "version": "1.0.17",
4
4
  "description": "",
5
5
  "main": "lib/index.js",
6
6
  "files": [
@@ -10,8 +10,9 @@
10
10
  "scripts": {
11
11
  "build": "tsc",
12
12
  "lint": "eslint \"src/**/*.ts\" --no-fix",
13
- "test:unit": "jest --verbose",
14
- "test:cov": "jest --coverage"
13
+ "test:unit": "jest",
14
+ "test:cov": "jest --coverage",
15
+ "test:functional": "jest --config='test/jest-config.json' --verbose"
15
16
  },
16
17
  "repository": {
17
18
  "type": "git",
@@ -44,12 +45,25 @@
44
45
  "creditu-date-model": "^2.6.0"
45
46
  },
46
47
  "jest": {
47
- "rootDir": "src/",
48
+ "rootDir": "src",
48
49
  "testRegex": ".spec.ts$",
50
+ "testTimeout": 5000,
49
51
  "transform": {
50
52
  "^.+\\.(t|j)s$": "ts-jest"
51
53
  },
54
+ "collectCoverageFrom": [
55
+ "**/*.(t|j)s"
56
+ ],
57
+ "coveragePathIgnorePatterns": [
58
+ ".dto.ts"
59
+ ],
52
60
  "coverageDirectory": "../coverage",
61
+ "testEnvironment": "node",
62
+ "moduleFileExtensions": [
63
+ "js",
64
+ "json",
65
+ "ts"
66
+ ],
53
67
  "coverageThreshold": {
54
68
  "global": {
55
69
  "branches": 80,