@lendi/integrations-transform 1.3.8 → 1.4.1

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.
@@ -63,6 +63,34 @@
63
63
  "enum": ["EMPLOYEE", "SELF_EMPLOYED", "UNKNOWN"],
64
64
  "description": "applicant's employment type"
65
65
  },
66
+ "guarantorRelationshipToBorrowerApplicantId": {
67
+ "$ref": "#/definitions/id",
68
+ "description": "Applicant Id of borrower that has relationship with guarantor."
69
+ },
70
+ "guarantorRelationshipToBorrowerType": {
71
+ "enum": ["Father", "Mother", "Spouse", "Brother", "Sister", "Son", "Daughter", "Other Relative", "Other"],
72
+ "description": "The relationship between borrower and guarantor."
73
+ },
74
+ "guarantorRelationshipToBorrowerTypeOther": {
75
+ "type": "string",
76
+ "description": "Description of relationship between borrower and guarantor when other."
77
+ },
78
+ "guarantorRelationshipToBorrowerDefinition": {
79
+ "type": "object",
80
+ "additionalProperties": false,
81
+ "properties": {
82
+ "applicantId": {
83
+ "$ref": "#/definitions/guarantorRelationshipToBorrowerApplicantId"
84
+ },
85
+ "type": {
86
+ "$ref": "#/definitions/guarantorRelationshipToBorrowerType"
87
+ },
88
+ "typeOther": {
89
+ "$ref": "#/definitions/guarantorRelationshipToBorrowerTypeOther"
90
+ }
91
+ },
92
+ "required": ["applicantId", "type"]
93
+ },
66
94
  "isPrimaryApplicant": {
67
95
  "type": "boolean"
68
96
  },
@@ -568,6 +596,9 @@
568
596
  "employmentType": {
569
597
  "$ref": "#/definitions/employmentType"
570
598
  },
599
+ "guarantorRelationshipToBorrower": {
600
+ "$ref": "#/definitions/guarantorRelationshipToBorrowerDefinition"
601
+ },
571
602
  "isPrimaryApplicant": {
572
603
  "$ref": "#/definitions/isPrimaryApplicant"
573
604
  },
@@ -148,6 +148,9 @@ function transformAsset(_a) {
148
148
  case 'address':
149
149
  (0, lodash_1.set)(partialApplication, assetMapping[key], (0, transform_asset_address_1.transformAddress)(value, addressId));
150
150
  break;
151
+ case 'isConstruction':
152
+ (0, lodash_1.set)(partialApplication, assetMapping[key], (0, __1.booleanMapping)(value));
153
+ break;
151
154
  case 'percentOwned':
152
155
  var percentOwned = (0, transform_percent_owned_1.transformPercentOwned)(value);
153
156
  if (percentOwned) {
@@ -1,15 +1,4 @@
1
1
  "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
2
  exports.__esModule = true;
14
3
  exports.isLivingExpenseEstimate = exports.isOtherCommitment = exports.normaliseExpenseAmount = exports.transformExpense = exports.transformExpenses = exports.otherCommitmentExpenseTypes = void 0;
15
4
  var application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
@@ -21,6 +10,12 @@ exports.otherCommitmentExpenseTypes = [
21
10
  public_expense_1.ExpenseType.ChildAndSpousalMaintenance,
22
11
  public_expense_1.ExpenseType.Rent,
23
12
  ];
13
+ var propertyExpenseCategories = [
14
+ public_expense_1.ExpenseType.InvestmentPropertyRunningCosts,
15
+ public_expense_1.ExpenseType.BodyCorporateFeesStrataFeesAndLandTax,
16
+ public_expense_1.ExpenseType.SecondaryResidenceRunningCosts,
17
+ public_expense_1.ExpenseType.PrimaryResidenceRunningCosts,
18
+ ];
24
19
  /**
25
20
  * @description Transforms expense items on the application from the event.
26
21
  * @returns {PartialApplication} A PartialApplication returned by transforming the expense event.
@@ -33,12 +28,13 @@ function transformExpenses(expense) {
33
28
  return partialApplication;
34
29
  }
35
30
  var normalisedExpenses = expenses.map(normaliseExpenseAmount);
36
- var livingExpenseEstimate = normalisedExpenses.find(isLivingExpenseEstimate);
37
- var otherCommitments = normalisedExpenses.filter(isOtherCommitment);
38
- var expenseBreakdown = normalisedExpenses.filter(function (item) { return !(isOtherCommitment(item) || isLivingExpenseEstimate(item)); });
31
+ var filteredLivingExpensesWithAmount = normalisedExpenses.filter(function (expense) { return expense.amount || !propertyExpenseCategories.includes(expense.type); });
32
+ var livingExpenseEstimate = filteredLivingExpensesWithAmount.find(isLivingExpenseEstimate);
33
+ var otherCommitments = filteredLivingExpensesWithAmount.filter(isOtherCommitment);
34
+ var expenseBreakdown = filteredLivingExpensesWithAmount.filter(function (item) { return !(isOtherCommitment(item) || isLivingExpenseEstimate(item)); });
39
35
  var livingExpenseEstimateExists = (0, lodash_1.get)(livingExpenseEstimate || {}, 'amount', 0) > 0;
40
36
  var expenseBreakdownAmountSum = (0, lodash_1.sumBy)(expenseBreakdown, 'amount');
41
- var lixiLivingExpenses = [];
37
+ var lixiLivingExpenses;
42
38
  // unless all individual expenses have a value of 0 and a living estimate exists, transform them without question.
43
39
  if (expenseBreakdownAmountSum === 0 && livingExpenseEstimateExists) {
44
40
  var estimate = transformExpense(livingExpenseEstimate, applicantId, 0, id);
@@ -92,12 +88,15 @@ exports.transformExpense = transformExpense;
92
88
  * @returns {Expense} An normalised expense.
93
89
  */
94
90
  function normaliseExpenseAmount(expense) {
95
- var _a = (0, lodash_1.pick)(expense, 'amount', 'frequency'), _b = _a.amount, amount = _b === void 0 ? 0 : _b, _c = _a.frequency, frequency = _c === void 0 ? public_expense_1.Frequency.Yearly : _c;
91
+ var amount = expense.amount, _a = expense.frequency, frequency = _a === void 0 ? public_expense_1.Frequency.Yearly : _a, expenseType = expense.type;
96
92
  if (frequency === public_expense_1.Frequency.Quarterly) {
97
- frequency = public_expense_1.Frequency.Yearly;
98
- amount = amount * 4;
93
+ expense.frequency = public_expense_1.Frequency.Yearly;
94
+ expense.amount *= 4;
95
+ }
96
+ if (!amount && !propertyExpenseCategories.includes(expenseType)) {
97
+ expense.amount = 0;
99
98
  }
100
- return __assign(__assign({}, expense), { amount: amount, frequency: frequency });
99
+ return expense;
101
100
  }
102
101
  exports.normaliseExpenseAmount = normaliseExpenseAmount;
103
102
  /**
@@ -36,6 +36,7 @@ export interface Payload {
36
36
  entity?: Entity;
37
37
  firstName?: string;
38
38
  gender?: Gender;
39
+ guarantorRelationshipToBorrower?: GuarantorRelationshipToBorrowerDefinition;
39
40
  hasSelfEmploymentProof?: boolean;
40
41
  /**
41
42
  * uuid of applicant
@@ -429,6 +430,25 @@ export declare enum Gender {
429
430
  Undisclosed = "UNDISCLOSED",
430
431
  Unknown = "UNKNOWN"
431
432
  }
433
+ export interface GuarantorRelationshipToBorrowerDefinition {
434
+ applicantId: string;
435
+ type: GuarantorRelationshipToBorrowerType;
436
+ typeOther?: string;
437
+ }
438
+ /**
439
+ * The relationship between borrower and guarantor.
440
+ */
441
+ export declare enum GuarantorRelationshipToBorrowerType {
442
+ Brother = "Brother",
443
+ Daughter = "Daughter",
444
+ Father = "Father",
445
+ Mother = "Mother",
446
+ Other = "Other",
447
+ OtherRelative = "Other Relative",
448
+ Sister = "Sister",
449
+ Son = "Son",
450
+ Spouse = "Spouse"
451
+ }
432
452
  /**
433
453
  * different invitation statuses an applicant can have
434
454
  */
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.Type = exports.Title = exports.ResidencyStatus = exports.ActionedByRole = exports.MaritalStatus = exports.InvitationStatus = exports.Gender = exports.Entity = exports.EmploymentType = exports.CreditStatus = exports.HousingStatusList = exports.Countries = exports.ApplicantType = void 0;
3
+ exports.Type = exports.Title = exports.ResidencyStatus = exports.ActionedByRole = exports.MaritalStatus = exports.InvitationStatus = exports.GuarantorRelationshipToBorrowerType = exports.Gender = exports.Entity = exports.EmploymentType = exports.CreditStatus = exports.HousingStatusList = exports.Countries = exports.ApplicantType = void 0;
4
4
  var ApplicantType;
5
5
  (function (ApplicantType) {
6
6
  ApplicantType["Borrower"] = "BORROWER";
@@ -294,6 +294,21 @@ var Gender;
294
294
  Gender["Undisclosed"] = "UNDISCLOSED";
295
295
  Gender["Unknown"] = "UNKNOWN";
296
296
  })(Gender = exports.Gender || (exports.Gender = {}));
297
+ /**
298
+ * The relationship between borrower and guarantor.
299
+ */
300
+ var GuarantorRelationshipToBorrowerType;
301
+ (function (GuarantorRelationshipToBorrowerType) {
302
+ GuarantorRelationshipToBorrowerType["Brother"] = "Brother";
303
+ GuarantorRelationshipToBorrowerType["Daughter"] = "Daughter";
304
+ GuarantorRelationshipToBorrowerType["Father"] = "Father";
305
+ GuarantorRelationshipToBorrowerType["Mother"] = "Mother";
306
+ GuarantorRelationshipToBorrowerType["Other"] = "Other";
307
+ GuarantorRelationshipToBorrowerType["OtherRelative"] = "Other Relative";
308
+ GuarantorRelationshipToBorrowerType["Sister"] = "Sister";
309
+ GuarantorRelationshipToBorrowerType["Son"] = "Son";
310
+ GuarantorRelationshipToBorrowerType["Spouse"] = "Spouse";
311
+ })(GuarantorRelationshipToBorrowerType = exports.GuarantorRelationshipToBorrowerType || (exports.GuarantorRelationshipToBorrowerType = {}));
297
312
  /**
298
313
  * different invitation statuses an applicant can have
299
314
  */
@@ -0,0 +1,30 @@
1
+ import { PersonApplicant } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
2
+ import { PartialApplication } from '../types/partial-application';
3
+ import { Payload } from '../types/events/public-applicant';
4
+ /**
5
+ * Checks if there are more than one person applicants with applicant type borrower
6
+ *
7
+ * @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
8
+ *
9
+ * @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
10
+ */
11
+ export declare const isMultiplePersonApplicantBorrowers: (personApplicants: PersonApplicant[]) => boolean;
12
+ /**
13
+ * Updates the primary applicant of the application based on the new primary applicant id
14
+ *
15
+ * @param {String} newPrimaryApplicantId - New primary applicant id
16
+ * @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
17
+ *
18
+ * @returns {PersonApplicant[]} - Updated person applicants
19
+ */
20
+ export declare const updatePrimaryApplicant: (newPrimaryApplicantId: string, personApplicants: PersonApplicant[]) => PersonApplicant[];
21
+ /**
22
+ * Updates the primary applicant on the application based on the data in the guarantor applicant event
23
+ *
24
+ * @param {PartialApplication} application - Application after deep merge
25
+ * @param {Payload} applicantPayload - Public applicant event payload
26
+ *
27
+ * @returns {PartialApplication} - Updated application
28
+ */
29
+ declare const updatePrimaryApplicantUsingGuarantor: (application: PartialApplication, applicantPayload: Payload) => PartialApplication;
30
+ export default updatePrimaryApplicantUsingGuarantor;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.updatePrimaryApplicant = exports.isMultiplePersonApplicantBorrowers = void 0;
15
+ var application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
16
+ var lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
17
+ var lodash_1 = require("lodash");
18
+ var public_applicant_1 = require("../types/events/public-applicant");
19
+ /**
20
+ * Checks if there are more than one person applicants with applicant type borrower
21
+ *
22
+ * @param {PersonApplicants[]} personApplicants - Person applicants on the deep merged application
23
+ *
24
+ * @returns {boolean} - Whether or not there are more than one applicant with applicant type borrower
25
+ */
26
+ var isMultiplePersonApplicantBorrowers = function (personApplicants) {
27
+ var totalBorrowerApplicants = personApplicants.filter(function (applicant) { return applicant['@ApplicantType'] === lixi_internal_request_1.ApplicantTypeList.Borrower; }).length;
28
+ return totalBorrowerApplicants > 1;
29
+ };
30
+ exports.isMultiplePersonApplicantBorrowers = isMultiplePersonApplicantBorrowers;
31
+ /**
32
+ * Updates the primary applicant of the application based on the new primary applicant id
33
+ *
34
+ * @param {String} newPrimaryApplicantId - New primary applicant id
35
+ * @param {PersonApplicant[]} personApplicants - Person applicants from the updated application after deep merge
36
+ *
37
+ * @returns {PersonApplicant[]} - Updated person applicants
38
+ */
39
+ var updatePrimaryApplicant = function (newPrimaryApplicantId, personApplicants) {
40
+ return personApplicants.map(function (applicant) {
41
+ var _a;
42
+ return (__assign(__assign({}, applicant), (_a = {}, _a['@PrimaryApplicant'] = applicant['@UniqueID'] === newPrimaryApplicantId ? lixi_internal_request_1.YesNoList.Yes : lixi_internal_request_1.YesNoList.No, _a)));
43
+ });
44
+ };
45
+ exports.updatePrimaryApplicant = updatePrimaryApplicant;
46
+ /**
47
+ * Updates the primary applicant on the application based on the data in the guarantor applicant event
48
+ *
49
+ * @param {PartialApplication} application - Application after deep merge
50
+ * @param {Payload} applicantPayload - Public applicant event payload
51
+ *
52
+ * @returns {PartialApplication} - Updated application
53
+ */
54
+ var updatePrimaryApplicantUsingGuarantor = function (application, applicantPayload) {
55
+ var updatedApplication = application, personApplicants = (0, lodash_1.get)(application, application_paths_1.paths.PersonApplicants, []);
56
+ // Checks if there are more than one borrower in the application and that the applicant type of the applicant event being processed is GUARANTOR
57
+ if ((0, exports.isMultiplePersonApplicantBorrowers)(personApplicants) &&
58
+ applicantPayload.applicantType === public_applicant_1.ApplicantType.Guarantor) {
59
+ (0, lodash_1.set)(updatedApplication, application_paths_1.paths.PersonApplicants, (0, exports.updatePrimaryApplicant)(applicantPayload.guarantorRelationshipToBorrower.applicantId, personApplicants));
60
+ }
61
+ return updatedApplication;
62
+ };
63
+ exports["default"] = updatePrimaryApplicantUsingGuarantor;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lendi/integrations-transform",
3
- "version": "1.3.8",
3
+ "version": "1.4.1",
4
4
  "description": "Library for kafka event data transforming",
5
5
  "author": "Integrations <integrations@lendi.com.au>",
6
6
  "homepage": "https://bitbucket.org/lendi-dev/integrations-shared-packages#readme",