@lendi/integrations-transform 1.1.1 → 1.2.0

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.
@@ -1,13 +1,13 @@
1
+ import { IncomeElement } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
1
2
  import { RentalIncome } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
2
- import { PartialApplication } from '../types/partial-application';
3
3
  import { Frequency, IncomeBusinessDetails, IncomeDefinition as IncomePayload, IncomeType, Ownership } from '../types/events/public-income';
4
- import { IncomeRecent } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
4
+ import { PartialApplication } from '../types/partial-application';
5
5
  export interface AmountFrequency {
6
6
  amount: string;
7
7
  frequency?: string;
8
8
  }
9
9
  export declare const EmploymentIncomeTypeMapping: Record<string, AmountFrequency>;
10
- export declare function getIncomeMapping(incomeType: IncomeType, basePath?: string): Record<string, string>;
10
+ export declare function getIncomeMapping(incomeType: IncomeType): Record<string, string>;
11
11
  /**
12
12
  * Generates an partial application from a partial income event.
13
13
  *
@@ -15,7 +15,7 @@ export declare function getIncomeMapping(incomeType: IncomeType, basePath?: stri
15
15
  * @param storedApplication: Current state of the application.
16
16
  * @return partialApplication an incomplete application.
17
17
  */
18
- export declare function generateIncome(payload: IncomePayload, storedApplication: PartialApplication): PartialApplication;
18
+ export declare function generateIncome(payload: IncomePayload, applicantId?: string): PartialApplication;
19
19
  /**
20
20
  * Creates Rental Income array.
21
21
  * @param amount Amount
@@ -32,6 +32,6 @@ export interface SelfEmploymentIncomeMapping {
32
32
  /**
33
33
  * @description Transform a Self Employed Income Details to LIXI
34
34
  * @param data Financial Year Income Details for Self Employed Income.
35
- * @returns {IncomeRecent} LIXI Income for the Self Employed.
35
+ * @returns {IncomeElement} LIXI Income for the Self Employed.
36
36
  */
37
- export declare function generateIncomeBusinessDetails(data: IncomeBusinessDetails): IncomeRecent;
37
+ export declare function generateIncomeBusinessDetails(data: IncomeBusinessDetails): IncomeElement;
@@ -1,4 +1,15 @@
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
+ };
2
13
  var __rest = (this && this.__rest) || function (s, e) {
3
14
  var t = {};
4
15
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -14,15 +25,15 @@ var _a;
14
25
  exports.__esModule = true;
15
26
  exports.generateIncomeBusinessDetails = exports.createRentalIncome = exports.generateIncome = exports.getIncomeMapping = exports.EmploymentIncomeTypeMapping = void 0;
16
27
  var lixi_internal_request_1 = require("@lendi/integrations-protocol/lib/types/lixi-internal-request");
17
- var application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
28
+ var application_paths_1 = require("@lendi/integrations-credit-protocol/utils/application-paths");
18
29
  var lodash_1 = require("lodash");
19
30
  var alieo_frequency_1 = require("../types/enum-mappings/alieo-frequency");
20
31
  var government_benefits_1 = require("../types/enum-mappings/government-benefits");
21
32
  var income_type_1 = require("../types/enum-mappings/income-type");
22
33
  var public_income_1 = require("../types/events/public-income");
34
+ var is_income_type_1 = require("../utils/is-income-type");
23
35
  var round_decimal_1 = require("../utils/round-decimal");
24
36
  var generate_lixi_percentowned_1 = require("./generate-lixi-percentowned");
25
- var is_income_type_1 = require("../utils/is-income-type");
26
37
  var netWorkAllowanceAmount = 'Income.@NetWorkAllowanceAmount';
27
38
  var netWorkAllowanceFrequency = 'Income.@NetWorkAllowanceFrequency';
28
39
  // Income types mapping from internal to LIXI types /paths.
@@ -59,37 +70,36 @@ exports.EmploymentIncomeTypeMapping = (_a = {},
59
70
  amount: 'Income.@GrossRegularOvertimeAmount',
60
71
  frequency: 'Income.@GrossRegularOvertimeFrequency'
61
72
  },
62
- _a[public_income_1.IncomeType.SelfEmployedBusinessIncome] = {
63
- amount: 'BusinessIncomeRecent.@ProfitBeforeTax'
64
- },
65
73
  _a);
66
- function getIncomeMapping(incomeType, basePath) {
67
- if (basePath === void 0) { basePath = application_paths_1.paths.PAYG; }
74
+ function getIncomeMapping(incomeType) {
75
+ var basePath = application_paths_1.paths.OtherIncome;
68
76
  if ((0, is_income_type_1.isRentalIncome)(incomeType)) {
77
+ basePath = application_paths_1.paths.RealEstateAsset;
69
78
  return {
70
79
  assetId: "".concat(basePath, ".@UniqueID"),
71
80
  percentOwned: "".concat(basePath, ".RentalIncome")
72
81
  };
73
82
  }
74
83
  if ((0, is_income_type_1.isFullDocOrLowDocIncome)(incomeType)) {
84
+ basePath = application_paths_1.paths.CompanyApplicant;
75
85
  return {
76
- incomes: "".concat(basePath, ".IncomeRecent"),
77
86
  companyId: "".concat(basePath, ".@UniqueID"),
78
- incomeRecent: "".concat(basePath, ".IncomeRecent"),
79
- incomePrevious: "".concat(basePath, ".IncomePrevious"),
87
+ incomes: "".concat(basePath, ".Income"),
80
88
  gross: "".concat(basePath, ".DeclaredIncome.@IncomeAmount")
81
89
  };
82
90
  }
83
- if ((0, is_income_type_1.isPaygIncome)(incomeType) || (0, is_income_type_1.isSelfEmployedIncome)(incomeType)) {
84
- var _a = exports.EmploymentIncomeTypeMapping[incomeType], amount = _a.amount, frequency = _a.frequency;
85
- var mapping = {
91
+ if ((0, is_income_type_1.isSelfEmployedIncome)(incomeType)) {
92
+ basePath = application_paths_1.paths.SelfEmployed;
93
+ var amount = exports.EmploymentIncomeTypeMapping[incomeType].amount;
94
+ return {
86
95
  amount: "".concat(basePath, ".").concat(amount),
87
96
  employmentId: "".concat(basePath, ".@UniqueID")
88
97
  };
89
- if (frequency) {
90
- mapping.frequency = "".concat(basePath, ".").concat(frequency);
91
- }
92
- return mapping;
98
+ }
99
+ if ((0, is_income_type_1.isPaygIncome)(incomeType)) {
100
+ basePath = application_paths_1.paths.PAYG;
101
+ var _a = exports.EmploymentIncomeTypeMapping[incomeType], amount = _a.amount, frequency = _a.frequency;
102
+ return __assign({ amount: "".concat(basePath, ".").concat(amount), employmentId: "".concat(basePath, ".@UniqueID") }, (frequency && { frequency: "".concat(basePath, ".").concat(frequency) }));
93
103
  }
94
104
  return {
95
105
  amount: "".concat(basePath, ".@Amount"),
@@ -107,36 +117,18 @@ exports.getIncomeMapping = getIncomeMapping;
107
117
  * @param storedApplication: Current state of the application.
108
118
  * @return partialApplication an incomplete application.
109
119
  */
110
- function generateIncome(payload, storedApplication) {
120
+ function generateIncome(payload, applicantId) {
111
121
  var applicationId = payload.applicationId, id = payload.id, income = payload.income;
112
122
  var incomeAmount = income.amount, incomeType = income.type, incomeFrequency = income.frequency;
113
123
  var partialApplication = {};
114
124
  (0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
115
- if (!(0, is_income_type_1.isRentalIncome)(incomeType)) {
116
- var applicants = (0, lodash_1.get)(storedApplication, application_paths_1.paths.PersonApplicants);
117
- var applicantId = (0, is_income_type_1.getApplicantId)(income, applicants);
118
- if (applicantId) {
119
- (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.PersonApplicant, ".@UniqueID"), applicantId);
120
- }
121
- }
122
- var incomeMapping;
123
- if ((0, is_income_type_1.isRentalIncome)(incomeType)) {
124
- incomeMapping = getIncomeMapping(incomeType, application_paths_1.paths.RealEstateAsset);
125
- }
126
- else if ((0, is_income_type_1.isPaygIncome)(incomeType)) {
127
- incomeMapping = getIncomeMapping(incomeType, application_paths_1.paths.PAYG);
128
- }
129
- else if ((0, is_income_type_1.isSelfEmployedIncome)(incomeType)) {
130
- incomeMapping = getIncomeMapping(incomeType, application_paths_1.paths.SelfEmployed);
131
- }
132
- else if ((0, is_income_type_1.isFullDocOrLowDocIncome)(incomeType)) {
133
- var basePath = 'Package.Content.Application.CompanyApplicant[0]';
134
- incomeMapping = getIncomeMapping(incomeType, basePath);
125
+ if (!(0, is_income_type_1.isRentalIncome)(incomeType) && applicantId) {
126
+ (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.PersonApplicant, ".@UniqueID"), applicantId);
135
127
  }
136
- else {
128
+ if ((0, is_income_type_1.isOtherIncome)(incomeType)) {
137
129
  (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.OtherIncome, ".@UniqueID"), id);
138
- incomeMapping = getIncomeMapping(incomeType, application_paths_1.paths.OtherIncome);
139
130
  }
131
+ var incomeMapping = getIncomeMapping(incomeType);
140
132
  for (var _i = 0, _a = Object.entries(income); _i < _a.length; _i++) {
141
133
  var _b = _a[_i], key = _b[0], value = _b[1];
142
134
  if (incomeMapping[key]) {
@@ -161,7 +153,7 @@ function generateIncome(payload, storedApplication) {
161
153
  case 'type':
162
154
  if (!(0, is_income_type_1.isRentalIncome)(incomeType)) {
163
155
  var mappedType = income_type_1.otherIncomeMapping[value];
164
- if ((0, is_income_type_1.isOtherIncome)(value)) {
156
+ if ((0, is_income_type_1.isOtherIncomeWithDesc)(value)) {
165
157
  (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.OtherIncome, ".@Description"), mappedType);
166
158
  (0, lodash_1.set)(partialApplication, incomeMapping[key], lixi_internal_request_1.OtherIncomeTypeList.OtherIncome);
167
159
  }
@@ -177,7 +169,7 @@ function generateIncome(payload, storedApplication) {
177
169
  var sortedIncomeList = value
178
170
  .sort(is_income_type_1.sortBusinessIncome)
179
171
  .map(generateIncomeBusinessDetails);
180
- (0, lodash_1.set)(partialApplication, 'Package.Content.Application.CompanyApplicant[0].Income', sortedIncomeList);
172
+ (0, lodash_1.set)(partialApplication, incomeMapping[key], sortedIncomeList);
181
173
  break;
182
174
  default:
183
175
  (0, lodash_1.set)(partialApplication, incomeMapping[key], value);
@@ -230,7 +222,7 @@ var selfEmploymentIncomeMapping = {
230
222
  /**
231
223
  * @description Transform a Self Employed Income Details to LIXI
232
224
  * @param data Financial Year Income Details for Self Employed Income.
233
- * @returns {IncomeRecent} LIXI Income for the Self Employed.
225
+ * @returns {IncomeElement} LIXI Income for the Self Employed.
234
226
  */
235
227
  function generateIncomeBusinessDetails(data) {
236
228
  var income = {};
@@ -2,6 +2,7 @@ import { PersonApplicant } from '@lendi/integrations-protocol/lib/types/lixi-int
2
2
  import { IncomeType, Income, IncomeBusinessDetails } from '../types/events/public-income';
3
3
  export declare const descriptionOtherIncomeTypes: string[];
4
4
  export declare const PAYGList: string[];
5
+ export declare const otherIncomeList: IncomeType[];
5
6
  /**
6
7
  * @description Is income type one of the PAYG income.
7
8
  * @param {string} incomeType Income type.
@@ -20,12 +21,18 @@ export declare function isSelfEmployedIncome(incomeType: string): boolean;
20
21
  * @returns {boolean} true if Income type is Rental Income.
21
22
  */
22
23
  export declare function isRentalIncome(incomeType: string): boolean;
24
+ /**
25
+ * @description Is income type grouped as OtherIncome.
26
+ * @param {IncomeType} incomeType Income type.
27
+ * @returns {boolean} true if income is of type other income.
28
+ */
29
+ export declare function isOtherIncome(incomeType: IncomeType): boolean;
23
30
  /**
24
31
  * @description Is Income type one of OtherIncome types.
25
32
  * @param {IncomeType} incomeType Income Type.
26
33
  * @returns {boolean} returns true for other income.
27
34
  */
28
- export declare function isOtherIncome(incomeType: string): boolean;
35
+ export declare function isOtherIncomeWithDesc(incomeType: string): boolean;
29
36
  /**
30
37
  * @description Is Self Employed Full Doc or Low Doc Income
31
38
  * @param incomeType Income Type from Event
@@ -33,40 +40,21 @@ export declare function isOtherIncome(incomeType: string): boolean;
33
40
  */
34
41
  export declare function isFullDocOrLowDocIncome(incomeType: IncomeType): boolean;
35
42
  /**
36
- * @description Checks if an Income event is a valid rental income event.
37
- * @param {Income} income Income.
38
- * @returns {boolean} true if event is a valid Rental Income.
39
- */
40
- export declare function isValidRentalIncomeEvent({ assetId, type: incomeType }: Income): boolean;
41
- /**
42
- * @description Is event valid PAYG income event.
43
- * @param {Income} income Income.
44
- * @param {PersonApplicant[]} applicants An array of applicants.
45
- * @returns {boolean} true if Income type is a PAYG value and event is valid PAYG event.
46
- */
47
- export declare function isValidPaygIncomeEvent({ percentOwned, employmentId, type: incomeType }: Income, applicants?: PersonApplicant[]): boolean;
48
- /**
49
- * @description Checks if an Income event is a valid self-employment income event.
50
- * @param {Income} income Income.
51
- * @param {PersonApplicant[]} applicants An array of applicants.
52
- * @returns {boolean} Returns true if event is a valid self employment income event.
53
- */
54
- export declare function isValidSelfEmployedIncomeEvent({ percentOwned, employmentId, type: incomeType }: Income, applicants?: PersonApplicant[]): boolean;
55
- /**
56
- * @description Get the employment ids for an applicant for a specific employment type.
57
- * @param {PersonApplicant} applicant An applicant
58
- * @param {string} key Employment type key: PAYG or SelfEmployed.
59
- * @returns {string[]} An array of employment ids for the applicant of the specified type.
43
+ * Checks if there is some employment for the applicant that has the same employment id as the employment id in the income event
44
+ *
45
+ * @param {PersonApplicant} applicant - An applicant
46
+ * @param {string} employmentId - Employment id being searched for
47
+ * @returns {boolean} - Whether or not the applicant has an employment with matching employmentId
60
48
  */
61
- export declare function getEmploymentIds(applicant: PersonApplicant, key: 'PAYG' | 'SelfEmployed'): string[];
49
+ export declare const hasMatchingEmploymentId: (applicant: PersonApplicant, employmentId: string) => boolean;
62
50
  /**
63
- * @description Get applicantId from an array of applicants given an employmentId and employmentType.
64
- * @param {PersonApplicant[]} applicants An array of applicants.
65
- * @param {string} employmentId EmploymentId
66
- * @param {string} key Employment type: PAYG or SelfEmployed
67
- * @returns {string | undefined} Returns applicantId or undefined.
51
+ * Gets the applicant id using the employment id
52
+ *
53
+ * @param {PersonApplicant[]} applicants - An array of applicants.
54
+ * @param {string} employmentId - Employment ID
55
+ * @returns {string | undefined} - Applicant id or undefined
68
56
  */
69
- export declare function getStoredApplicantId(applicants: PersonApplicant[], employmentId: string, key: 'PAYG' | 'SelfEmployed'): string | undefined;
57
+ export declare function getApplicantIdFromEmploymentId(applicants: PersonApplicant[], employmentId: string): string | undefined;
70
58
  /**
71
59
  * @description Get an applicantId from the event or the applicants.
72
60
  * @param {Income} income Income.
@@ -78,6 +66,6 @@ export declare function getApplicantId({ percentOwned, employmentId }: Income, a
78
66
  * @description Sort Business Income By Year.
79
67
  * @param incomeA Income Details for Self Employed Full Doc.
80
68
  * @param incomeB Income Details for Self Employed Full Doc.
81
- * @returns {0 | - 1 | 1} Returns a number to be used for sorting income.
69
+ * @returns {0 | < 0 | > 0} Returns a number to be used for sorting income.
82
70
  */
83
- export declare function sortBusinessIncome({ year: yearA }: IncomeBusinessDetails, { year: yearB }: IncomeBusinessDetails): number;
71
+ export declare const sortBusinessIncome: ({ year: yearA }: IncomeBusinessDetails, { year: yearB }: IncomeBusinessDetails) => number;
@@ -1,12 +1,11 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.sortBusinessIncome = exports.getApplicantId = exports.getStoredApplicantId = exports.getEmploymentIds = exports.isValidSelfEmployedIncomeEvent = exports.isValidPaygIncomeEvent = exports.isValidRentalIncomeEvent = exports.isFullDocOrLowDocIncome = exports.isOtherIncome = exports.isRentalIncome = exports.isSelfEmployedIncome = exports.isPaygIncome = exports.PAYGList = exports.descriptionOtherIncomeTypes = void 0;
3
+ exports.sortBusinessIncome = exports.getApplicantId = exports.getApplicantIdFromEmploymentId = exports.hasMatchingEmploymentId = exports.isFullDocOrLowDocIncome = exports.isOtherIncomeWithDesc = exports.isOtherIncome = exports.isRentalIncome = exports.isSelfEmployedIncome = exports.isPaygIncome = exports.otherIncomeList = exports.PAYGList = exports.descriptionOtherIncomeTypes = void 0;
4
4
  var lodash_1 = require("lodash");
5
5
  var public_income_1 = require("../types/events/public-income");
6
6
  exports.descriptionOtherIncomeTypes = [
7
7
  public_income_1.IncomeType.InvestmentIncome,
8
8
  public_income_1.IncomeType.PaygNonVoluntaryDeductionsPreTax,
9
- public_income_1.IncomeType.RentalIncome,
10
9
  ];
11
10
  exports.PAYGList = [
12
11
  public_income_1.IncomeType.PaygAllowancesNotTaxed,
@@ -18,6 +17,17 @@ exports.PAYGList = [
18
17
  public_income_1.IncomeType.PaygCompanyCar,
19
18
  public_income_1.IncomeType.PaygOvertimeIncome,
20
19
  ];
20
+ exports.otherIncomeList = [
21
+ public_income_1.IncomeType.ChildMaintenance,
22
+ public_income_1.IncomeType.ForeignIncome,
23
+ public_income_1.IncomeType.GovtBenefit,
24
+ public_income_1.IncomeType.InvestmentIncome,
25
+ public_income_1.IncomeType.OtherIncome,
26
+ public_income_1.IncomeType.PaygNonVoluntaryDeductionsPreTax,
27
+ public_income_1.IncomeType.PaygSalarySacrifice,
28
+ public_income_1.IncomeType.SuperAnnuityPension,
29
+ public_income_1.IncomeType.WorkersCompensation,
30
+ ];
21
31
  /**
22
32
  * @description Is income type one of the PAYG income.
23
33
  * @param {string} incomeType Income type.
@@ -45,15 +55,24 @@ function isRentalIncome(incomeType) {
45
55
  return incomeType === public_income_1.IncomeType.RentalIncome;
46
56
  }
47
57
  exports.isRentalIncome = isRentalIncome;
58
+ /**
59
+ * @description Is income type grouped as OtherIncome.
60
+ * @param {IncomeType} incomeType Income type.
61
+ * @returns {boolean} true if income is of type other income.
62
+ */
63
+ function isOtherIncome(incomeType) {
64
+ return exports.otherIncomeList.includes(incomeType);
65
+ }
66
+ exports.isOtherIncome = isOtherIncome;
48
67
  /**
49
68
  * @description Is Income type one of OtherIncome types.
50
69
  * @param {IncomeType} incomeType Income Type.
51
70
  * @returns {boolean} returns true for other income.
52
71
  */
53
- function isOtherIncome(incomeType) {
72
+ function isOtherIncomeWithDesc(incomeType) {
54
73
  return exports.descriptionOtherIncomeTypes.includes(incomeType);
55
74
  }
56
- exports.isOtherIncome = isOtherIncome;
75
+ exports.isOtherIncomeWithDesc = isOtherIncomeWithDesc;
57
76
  /**
58
77
  * @description Is Self Employed Full Doc or Low Doc Income
59
78
  * @param incomeType Income Type from Event
@@ -64,76 +83,37 @@ function isFullDocOrLowDocIncome(incomeType) {
64
83
  }
65
84
  exports.isFullDocOrLowDocIncome = isFullDocOrLowDocIncome;
66
85
  /**
67
- * @description Checks if an Income event is a valid rental income event.
68
- * @param {Income} income Income.
69
- * @returns {boolean} true if event is a valid Rental Income.
86
+ * Checks if there is some employment for the applicant that has the same employment id as the employment id in the income event
87
+ *
88
+ * @param {PersonApplicant} applicant - An applicant
89
+ * @param {string} employmentId - Employment id being searched for
90
+ * @returns {boolean} - Whether or not the applicant has an employment with matching employmentId
70
91
  */
71
- function isValidRentalIncomeEvent(_a) {
72
- var assetId = _a.assetId, incomeType = _a.type;
73
- return isRentalIncome(incomeType) && !assetId;
74
- }
75
- exports.isValidRentalIncomeEvent = isValidRentalIncomeEvent;
92
+ var hasMatchingEmploymentId = function (applicant, employmentId) {
93
+ return (applicant.Employment || []).some(function (employment) {
94
+ var id = (0, lodash_1.get)(employment, 'PAYG.@UniqueID') ||
95
+ (0, lodash_1.get)(employment, 'SelfEmployed.@UniqueID') ||
96
+ (0, lodash_1.get)(employment, 'NotEmployed.@UniqueID');
97
+ return id === employmentId;
98
+ });
99
+ };
100
+ exports.hasMatchingEmploymentId = hasMatchingEmploymentId;
76
101
  /**
77
- * @description Is event valid PAYG income event.
78
- * @param {Income} income Income.
79
- * @param {PersonApplicant[]} applicants An array of applicants.
80
- * @returns {boolean} true if Income type is a PAYG value and event is valid PAYG event.
102
+ * Gets the applicant id using the employment id
103
+ *
104
+ * @param {PersonApplicant[]} applicants - An array of applicants.
105
+ * @param {string} employmentId - Employment ID
106
+ * @returns {string | undefined} - Applicant id or undefined
81
107
  */
82
- function isValidPaygIncomeEvent(_a, applicants) {
83
- var percentOwned = _a.percentOwned, employmentId = _a.employmentId, incomeType = _a.type;
84
- if (applicants === void 0) { applicants = []; }
85
- if (!isPaygIncome(incomeType))
86
- return false;
87
- var applicantId = (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getStoredApplicantId(applicants, employmentId, 'PAYG');
88
- if (!applicantId)
89
- return false;
90
- return true;
91
- }
92
- exports.isValidPaygIncomeEvent = isValidPaygIncomeEvent;
93
- /**
94
- * @description Checks if an Income event is a valid self-employment income event.
95
- * @param {Income} income Income.
96
- * @param {PersonApplicant[]} applicants An array of applicants.
97
- * @returns {boolean} Returns true if event is a valid self employment income event.
98
- */
99
- function isValidSelfEmployedIncomeEvent(_a, applicants) {
100
- var percentOwned = _a.percentOwned, employmentId = _a.employmentId, incomeType = _a.type;
101
- if (applicants === void 0) { applicants = []; }
102
- if (!isSelfEmployedIncome(incomeType))
103
- return false;
104
- var applicantId = (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getStoredApplicantId(applicants, employmentId, 'PAYG');
105
- if (!applicantId)
106
- return false;
107
- return true;
108
- }
109
- exports.isValidSelfEmployedIncomeEvent = isValidSelfEmployedIncomeEvent;
110
- /**
111
- * @description Get the employment ids for an applicant for a specific employment type.
112
- * @param {PersonApplicant} applicant An applicant
113
- * @param {string} key Employment type key: PAYG or SelfEmployed.
114
- * @returns {string[]} An array of employment ids for the applicant of the specified type.
115
- */
116
- function getEmploymentIds(applicant, key) {
117
- return (0, lodash_1.compact)(applicant.Employment.flatMap(function (employment) { return (0, lodash_1.get)(employment, "".concat(key, ".@UniqueID")); }));
118
- }
119
- exports.getEmploymentIds = getEmploymentIds;
120
- /**
121
- * @description Get applicantId from an array of applicants given an employmentId and employmentType.
122
- * @param {PersonApplicant[]} applicants An array of applicants.
123
- * @param {string} employmentId EmploymentId
124
- * @param {string} key Employment type: PAYG or SelfEmployed
125
- * @returns {string | undefined} Returns applicantId or undefined.
126
- */
127
- function getStoredApplicantId(applicants, employmentId, key) {
128
- for (var _i = 0, applicants_1 = applicants; _i < applicants_1.length; _i++) {
129
- var applicant = applicants_1[_i];
130
- var employmentIds = getEmploymentIds(applicant, key);
131
- if (employmentIds.includes(employmentId))
132
- return applicant['@UniqueID'];
108
+ function getApplicantIdFromEmploymentId(applicants, employmentId) {
109
+ var applicantId;
110
+ if (applicants && employmentId) {
111
+ var applicant = applicants.find(function (applicant) { return (0, exports.hasMatchingEmploymentId)(applicant, employmentId); });
112
+ applicantId = applicant === null || applicant === void 0 ? void 0 : applicant['@UniqueID'];
133
113
  }
134
- return undefined;
114
+ return applicantId;
135
115
  }
136
- exports.getStoredApplicantId = getStoredApplicantId;
116
+ exports.getApplicantIdFromEmploymentId = getApplicantIdFromEmploymentId;
137
117
  /**
138
118
  * @description Get an applicantId from the event or the applicants.
139
119
  * @param {Income} income Income.
@@ -143,24 +123,18 @@ exports.getStoredApplicantId = getStoredApplicantId;
143
123
  function getApplicantId(_a, applicants) {
144
124
  var percentOwned = _a.percentOwned, employmentId = _a.employmentId;
145
125
  if (applicants === void 0) { applicants = []; }
146
- return ((0, lodash_1.get)(percentOwned, 'owners[0].applicantId') ||
147
- getStoredApplicantId(applicants, employmentId, 'PAYG') ||
148
- getStoredApplicantId(applicants, employmentId, 'SelfEmployed'));
126
+ return (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getApplicantIdFromEmploymentId(applicants, employmentId);
149
127
  }
150
128
  exports.getApplicantId = getApplicantId;
151
129
  /**
152
130
  * @description Sort Business Income By Year.
153
131
  * @param incomeA Income Details for Self Employed Full Doc.
154
132
  * @param incomeB Income Details for Self Employed Full Doc.
155
- * @returns {0 | - 1 | 1} Returns a number to be used for sorting income.
133
+ * @returns {0 | < 0 | > 0} Returns a number to be used for sorting income.
156
134
  */
157
- function sortBusinessIncome(_a, _b) {
135
+ var sortBusinessIncome = function (_a, _b) {
158
136
  var _c = _a.year, yearA = _c === void 0 ? 0 : _c;
159
137
  var _d = _b.year, yearB = _d === void 0 ? 0 : _d;
160
- if (yearA > yearB)
161
- return -1;
162
- if (yearB > yearA)
163
- return 1;
164
- return 0;
165
- }
138
+ return yearB - yearA;
139
+ };
166
140
  exports.sortBusinessIncome = sortBusinessIncome;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lendi/integrations-transform",
3
- "version": "1.1.1",
3
+ "version": "1.2.0",
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",
@@ -21,7 +21,7 @@
21
21
  "url": "git+ssh://git@bitbucket.org/lendi-dev/integrations-shared-packages.git"
22
22
  },
23
23
  "dependencies": {
24
- "@lendi/integrations-credit-protocol": "1.13.9",
24
+ "@lendi/integrations-credit-protocol": "1.14.4",
25
25
  "@lendi/integrations-protocol": "2.3.0",
26
26
  "clean-deep": "^3.4.0",
27
27
  "date-fns": "2.19.0",