@lendi/integrations-transform 1.1.3 → 1.1.9

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/lib/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './transform-events/transform-applicant';
2
2
  export * from './transform-events/transform-application';
3
+ export * from './transform-events/transform-income';
3
4
  export * from './transform-events/generate-asset';
4
5
  export * from './transform-events/transform-expenses';
5
6
  export * from './transform-events/generate-liability';
package/lib/index.js CHANGED
@@ -13,6 +13,7 @@ exports.__esModule = true;
13
13
  /* istanbul ignore file */
14
14
  __exportStar(require("./transform-events/transform-applicant"), exports);
15
15
  __exportStar(require("./transform-events/transform-application"), exports);
16
+ __exportStar(require("./transform-events/transform-income"), exports);
16
17
  __exportStar(require("./transform-events/generate-asset"), exports);
17
18
  __exportStar(require("./transform-events/transform-expenses"), exports);
18
19
  __exportStar(require("./transform-events/generate-liability"), exports);
@@ -36,7 +36,7 @@ var assetMapping = {
36
36
  address: application_paths_1.paths.Address
37
37
  };
38
38
  exports.residentialTypeList = Object.values(lixi_internal_request_1.ResidentialTypeList);
39
- exports.propertyTypeNameList = Object.values(lixi_internal_request_1.Custom3PropertyTypeNameList);
39
+ exports.propertyTypeNameList = Object.values(lixi_internal_request_1.Custom2PropertyTypeNameList);
40
40
  /**
41
41
  * Generates a partial internal request from a partial public asset event.
42
42
  *
@@ -119,7 +119,7 @@ function generateAsset(_a) {
119
119
  }
120
120
  else if (exports.propertyTypeNameList.includes(mappedValue)) {
121
121
  (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.RealEstateAsset, ".PropertyType.@PropertyTypeName"), mappedValue);
122
- (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.RealEstateAsset, ".PropertyType.@CategoryTypeName"), lixi_internal_request_1.Custom2CategoryTypeNameList.Residential);
122
+ (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.RealEstateAsset, ".PropertyType.@CategoryTypeName"), lixi_internal_request_1.Custom1CategoryTypeNameList.Residential);
123
123
  }
124
124
  else {
125
125
  logger_1.logger.warn({ message: "Unknown propertyType ".concat(value, " for asset ").concat(id), applicationId: applicationId });
@@ -128,10 +128,10 @@ function generateAsset(_a) {
128
128
  case 'zoneType':
129
129
  if (asset.zoneType === public_asset_1.ZoneType.Commercial) {
130
130
  (0, lodash_1.set)(partialApplication, "".concat(application_paths_1.paths.RealEstateAsset, ".Commercial.@Type"), lixi_internal_request_1.OtherAssetTypeList.Other);
131
- (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom4TypeList.Commercial);
131
+ (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom3TypeList.Commercial);
132
132
  }
133
133
  else {
134
- (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom4TypeList.Residential);
134
+ (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom3TypeList.Residential);
135
135
  }
136
136
  break;
137
137
  case 'financialInstitution':
@@ -1,6 +1,6 @@
1
- import { IncomeElement } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
1
+ import { IncomeBusinessActivityStatement, IncomeElement } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
2
2
  import { RentalIncome } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
3
- import { Frequency, IncomeBusinessDetails, IncomeDefinition as IncomePayload, IncomeType, Ownership } from '../types/events/public-income';
3
+ import { BASDefinition, Frequency, IncomeBusinessDetails, IncomeDefinition as IncomePayload, IncomeType, Ownership } from '../types/events/public-income';
4
4
  import { PartialApplication } from '../types/partial-application';
5
5
  export interface AmountFrequency {
6
6
  amount: string;
@@ -12,10 +12,10 @@ export declare function getIncomeMapping(incomeType: IncomeType): Record<string,
12
12
  * Generates an partial application from a partial income event.
13
13
  *
14
14
  * @param payload a partial income event.
15
- * @param storedApplication: Current state of the application.
15
+ * @param applicantId PersonApplicant uniqueId on the application.
16
16
  * @return partialApplication an incomplete application.
17
17
  */
18
- export declare function generateIncome(payload: IncomePayload, applicantId?: string): PartialApplication;
18
+ export declare function transformIncome(payload: IncomePayload, applicantId?: string): PartialApplication;
19
19
  /**
20
20
  * Creates Rental Income array.
21
21
  * @param amount Amount
@@ -35,3 +35,7 @@ export interface SelfEmploymentIncomeMapping {
35
35
  * @returns {IncomeElement} LIXI Income for the Self Employed.
36
36
  */
37
37
  export declare function generateIncomeBusinessDetails(data: IncomeBusinessDetails): IncomeElement;
38
+ /**
39
+ * Generates the BAS array from the bas definition on the event.
40
+ */
41
+ export declare function generateBAS(bas: BASDefinition[]): IncomeBusinessActivityStatement[];
@@ -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)
@@ -12,7 +23,7 @@ var __rest = (this && this.__rest) || function (s, e) {
12
23
  };
13
24
  var _a;
14
25
  exports.__esModule = true;
15
- exports.generateIncomeBusinessDetails = exports.createRentalIncome = exports.generateIncome = exports.getIncomeMapping = exports.EmploymentIncomeTypeMapping = void 0;
26
+ exports.generateBAS = exports.generateIncomeBusinessDetails = exports.createRentalIncome = exports.transformIncome = exports.getIncomeMapping = exports.EmploymentIncomeTypeMapping = void 0;
16
27
  var lixi_internal_request_1 = require("@lendi/integrations-protocol/lib/types/lixi-internal-request");
17
28
  var application_paths_1 = require("@lendi/integrations-credit-protocol/utils/application-paths");
18
29
  var lodash_1 = require("lodash");
@@ -59,6 +70,9 @@ exports.EmploymentIncomeTypeMapping = (_a = {},
59
70
  amount: 'Income.@GrossRegularOvertimeAmount',
60
71
  frequency: 'Income.@GrossRegularOvertimeFrequency'
61
72
  },
73
+ _a[public_income_1.IncomeType.SelfEmployedBusinessIncome] = {
74
+ amount: 'BusinessIncomeRecent.@ProfitBeforeTax'
75
+ },
62
76
  _a);
63
77
  function getIncomeMapping(incomeType) {
64
78
  var basePath = application_paths_1.paths.OtherIncome;
@@ -72,24 +86,24 @@ function getIncomeMapping(incomeType) {
72
86
  if ((0, is_income_type_1.isFullDocOrLowDocIncome)(incomeType)) {
73
87
  basePath = application_paths_1.paths.CompanyApplicant;
74
88
  return {
89
+ bas: "".concat(basePath, ".Income[0].BusinessActivityStatement"),
75
90
  companyId: "".concat(basePath, ".@UniqueID"),
76
- incomes: "".concat(basePath, ".IncomeRecent"),
77
- incomeRecent: "".concat(basePath, ".IncomeRecent"),
78
- incomePrevious: "".concat(basePath, ".IncomePrevious"),
91
+ incomes: "".concat(basePath, ".Income"),
79
92
  gross: "".concat(basePath, ".DeclaredIncome.@IncomeAmount")
80
93
  };
81
94
  }
82
- if ((0, is_income_type_1.isPaygIncome)(incomeType)) {
83
- basePath = application_paths_1.paths.PAYG;
84
- var _a = exports.EmploymentIncomeTypeMapping[incomeType], amount = _a.amount, frequency = _a.frequency;
85
- var mapping = {
95
+ if ((0, is_income_type_1.isSelfEmployedIncome)(incomeType)) {
96
+ basePath = application_paths_1.paths.SelfEmployed;
97
+ var amount = exports.EmploymentIncomeTypeMapping[incomeType].amount;
98
+ return {
86
99
  amount: "".concat(basePath, ".").concat(amount),
87
100
  employmentId: "".concat(basePath, ".@UniqueID")
88
101
  };
89
- if (frequency) {
90
- mapping.frequency = "".concat(basePath, ".").concat(frequency);
91
- }
92
- return mapping;
102
+ }
103
+ if ((0, is_income_type_1.isPaygIncome)(incomeType)) {
104
+ basePath = application_paths_1.paths.PAYG;
105
+ var _a = exports.EmploymentIncomeTypeMapping[incomeType], amount = _a.amount, frequency = _a.frequency;
106
+ return __assign({ amount: "".concat(basePath, ".").concat(amount), employmentId: "".concat(basePath, ".@UniqueID") }, (frequency && { frequency: "".concat(basePath, ".").concat(frequency) }));
93
107
  }
94
108
  return {
95
109
  amount: "".concat(basePath, ".@Amount"),
@@ -104,10 +118,10 @@ exports.getIncomeMapping = getIncomeMapping;
104
118
  * Generates an partial application from a partial income event.
105
119
  *
106
120
  * @param payload a partial income event.
107
- * @param storedApplication: Current state of the application.
121
+ * @param applicantId PersonApplicant uniqueId on the application.
108
122
  * @return partialApplication an incomplete application.
109
123
  */
110
- function generateIncome(payload, applicantId) {
124
+ function transformIncome(payload, applicantId) {
111
125
  var applicationId = payload.applicationId, id = payload.id, income = payload.income;
112
126
  var incomeAmount = income.amount, incomeType = income.type, incomeFrequency = income.frequency;
113
127
  var partialApplication = {};
@@ -127,6 +141,11 @@ function generateIncome(payload, applicantId) {
127
141
  var amount = incomeFrequency === public_income_1.Frequency.Quarterly ? value * 4 : value;
128
142
  (0, lodash_1.set)(partialApplication, incomeMapping[key], (0, round_decimal_1.roundDecimal)(amount));
129
143
  break;
144
+ case 'bas':
145
+ var basWithAmount = value.filter(function (bas) { return bas.salesAmount !== undefined || false; });
146
+ if (!(0, lodash_1.isEmpty)(basWithAmount))
147
+ (0, lodash_1.set)(partialApplication, incomeMapping[key], generateBAS(basWithAmount));
148
+ break;
130
149
  case 'frequency':
131
150
  (0, lodash_1.set)(partialApplication, incomeMapping[key], alieo_frequency_1.incomeExpenseFrequencyMapping[value]);
132
151
  break;
@@ -159,7 +178,7 @@ function generateIncome(payload, applicantId) {
159
178
  var sortedIncomeList = value
160
179
  .sort(is_income_type_1.sortBusinessIncome)
161
180
  .map(generateIncomeBusinessDetails);
162
- (0, lodash_1.set)(partialApplication, 'Package.Content.Application.CompanyApplicant[0].Income', sortedIncomeList);
181
+ (0, lodash_1.set)(partialApplication, incomeMapping[key], sortedIncomeList);
163
182
  break;
164
183
  default:
165
184
  (0, lodash_1.set)(partialApplication, incomeMapping[key], value);
@@ -169,7 +188,7 @@ function generateIncome(payload, applicantId) {
169
188
  }
170
189
  return partialApplication;
171
190
  }
172
- exports.generateIncome = generateIncome;
191
+ exports.transformIncome = transformIncome;
173
192
  /**
174
193
  * Creates Rental Income array.
175
194
  * @param amount Amount
@@ -203,7 +222,7 @@ var selfEmploymentIncomeMapping = {
203
222
  interest: 'Addback.@Interest',
204
223
  lease: 'Addback.@Lease',
205
224
  nonRecurringExpenses: 'Addback.@NonRecurringExpenses',
206
- other: 'Addback.@Other',
225
+ other: 'Addback.OtherAddback[0].@Amount',
207
226
  salary: 'Addback.@Salary',
208
227
  superannuationExcess: 'Addback.@SuperannuationExcess'
209
228
  },
@@ -219,13 +238,19 @@ function generateIncomeBusinessDetails(data) {
219
238
  var addbackMapping = selfEmploymentIncomeMapping.addback, dateAndIncomeMapping = __rest(selfEmploymentIncomeMapping, ["addback"]);
220
239
  for (var _i = 0, _a = Object.entries(data); _i < _a.length; _i++) {
221
240
  var _b = _a[_i], key = _b[0], value = _b[1];
222
- if (selfEmploymentIncomeMapping[key] != null) {
241
+ if (selfEmploymentIncomeMapping[key] !== null) {
223
242
  if (key === 'addback') {
224
243
  for (var _c = 0, _d = Object.entries(value); _c < _d.length; _c++) {
225
244
  var _e = _d[_c], addbackKey = _e[0], addbackValue = _e[1];
245
+ if (addbackKey === 'other') {
246
+ (0, lodash_1.set)(income, 'Addback.OtherAddback[0].@Description', 'other');
247
+ }
226
248
  (0, lodash_1.set)(income, addbackMapping[addbackKey], addbackValue);
227
249
  }
228
250
  }
251
+ else if (key === 'year') {
252
+ (0, lodash_1.set)(income, dateAndIncomeMapping[key], "".concat(value, "-01-01"));
253
+ }
229
254
  else {
230
255
  (0, lodash_1.set)(income, dateAndIncomeMapping[key], value);
231
256
  }
@@ -234,3 +259,13 @@ function generateIncomeBusinessDetails(data) {
234
259
  return income;
235
260
  }
236
261
  exports.generateIncomeBusinessDetails = generateIncomeBusinessDetails;
262
+ /**
263
+ * Generates the BAS array from the bas definition on the event.
264
+ */
265
+ function generateBAS(bas) {
266
+ return bas.map(function (bas) { return ({
267
+ '@Quarter': bas.quarter,
268
+ '@SalesAmount': bas.salesAmount
269
+ }); });
270
+ }
271
+ exports.generateBAS = generateBAS;
@@ -1,4 +1,4 @@
1
- import { FeeCategoryList, FeeTypeList, Custom5DescriptionList as DescriptionList, ContributionFundsTypeList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
1
+ import { FeeCategoryList, FeeTypeList, Custom4DescriptionList as DescriptionList, ContributionFundsTypeList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
2
2
  declare type CategoryMapping = {
3
3
  [key: string]: FeeCategoryList;
4
4
  };
@@ -25,8 +25,8 @@ exports.typeMapping = {
25
25
  foreignBuyerSurcharge: lixi_internal_request_1.FeeTypeList.Other
26
26
  };
27
27
  exports.descriptionMapping = {
28
- accruedInterest: lixi_internal_request_1.Custom5DescriptionList.PotentialAccruedInterest,
29
- otherSundries: lixi_internal_request_1.Custom5DescriptionList.OtherSundries
28
+ accruedInterest: lixi_internal_request_1.Custom4DescriptionList.PotentialAccruedInterest,
29
+ otherSundries: lixi_internal_request_1.Custom4DescriptionList.OtherSundries
30
30
  };
31
31
  exports.contributionMapping = {
32
32
  totalGovernmentContributions: lixi_internal_request_1.ContributionFundsTypeList.FirstHomeOwnerGrant,
@@ -1,7 +1,7 @@
1
- import { OtherIncomeTypeList, Custom1DescriptionList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
1
+ import { OtherIncomeTypeList, Custom0DescriptionList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
2
2
  import { IncomeType } from '../events/public-income';
3
3
  declare type OtherIncomeMapping = {
4
- [key in IncomeType]: OtherIncomeTypeList | Custom1DescriptionList;
4
+ [key in IncomeType]: OtherIncomeTypeList | Custom0DescriptionList;
5
5
  };
6
6
  export declare const otherIncomeMapping: Partial<OtherIncomeMapping>;
7
7
  export {};
@@ -8,9 +8,9 @@ exports.otherIncomeMapping = (_a = {},
8
8
  _a[public_income_1.IncomeType.ChildMaintenance] = lixi_internal_request_1.OtherIncomeTypeList.ChildMaintenance,
9
9
  _a[public_income_1.IncomeType.ForeignIncome] = lixi_internal_request_1.OtherIncomeTypeList.ForeignSourced,
10
10
  _a[public_income_1.IncomeType.GovtBenefit] = lixi_internal_request_1.OtherIncomeTypeList.GovernmentBenefits,
11
- _a[public_income_1.IncomeType.InvestmentIncome] = lixi_internal_request_1.Custom1DescriptionList.InvestmentIncome,
11
+ _a[public_income_1.IncomeType.InvestmentIncome] = lixi_internal_request_1.Custom0DescriptionList.InvestmentIncome,
12
12
  _a[public_income_1.IncomeType.OtherIncome] = lixi_internal_request_1.OtherIncomeTypeList.OtherIncome,
13
- _a[public_income_1.IncomeType.PaygNonVoluntaryDeductionsPreTax] = lixi_internal_request_1.Custom1DescriptionList.PAYGNonVoluntaryDeductionsPreTax,
13
+ _a[public_income_1.IncomeType.PaygNonVoluntaryDeductionsPreTax] = lixi_internal_request_1.Custom0DescriptionList.PAYGNonVoluntaryDeductionsPreTax,
14
14
  _a[public_income_1.IncomeType.PaygSalarySacrifice] = lixi_internal_request_1.OtherIncomeTypeList.SalarySacrificeContribution,
15
15
  _a[public_income_1.IncomeType.SuperAnnuityPension] = lixi_internal_request_1.OtherIncomeTypeList.Superannuation,
16
16
  _a[public_income_1.IncomeType.WorkersCompensation] = lixi_internal_request_1.OtherIncomeTypeList.WorkersCompensation,
@@ -1,7 +1,7 @@
1
1
  import { PropertyType } from '../events/public-asset';
2
- import { ResidentialTypeList, Custom3PropertyTypeNameList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
2
+ import { ResidentialTypeList, Custom2PropertyTypeNameList } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
3
3
  declare type PropertyTypeMapping = {
4
- [key in PropertyType]: ResidentialTypeList | Custom3PropertyTypeNameList;
4
+ [key in PropertyType]: ResidentialTypeList | Custom2PropertyTypeNameList;
5
5
  };
6
6
  export declare const propertyTypeMapping: PropertyTypeMapping;
7
7
  export {};
@@ -19,6 +19,6 @@ exports.propertyTypeMapping = (_a = {},
19
19
  _a[public_asset_1.PropertyType.Townhouse] = lixi_internal_request_1.ResidentialTypeList.Townhouse,
20
20
  _a[public_asset_1.PropertyType.Villa] = lixi_internal_request_1.ResidentialTypeList.Villa,
21
21
  _a[public_asset_1.PropertyType.WarehouseApartment] = lixi_internal_request_1.ResidentialTypeList.StudioWarehouseApartment,
22
- _a[public_asset_1.PropertyType.PropertyOver10_Ha] = lixi_internal_request_1.Custom3PropertyTypeNameList.PropertyOver10HA,
23
- _a[public_asset_1.PropertyType.MultiDwellingSingleTitle] = lixi_internal_request_1.Custom3PropertyTypeNameList.MultiDwellingSingleTitle,
22
+ _a[public_asset_1.PropertyType.PropertyOver10_Ha] = lixi_internal_request_1.Custom2PropertyTypeNameList.PropertyOver10HA,
23
+ _a[public_asset_1.PropertyType.MultiDwellingSingleTitle] = lixi_internal_request_1.Custom2PropertyTypeNameList.MultiDwellingSingleTitle,
24
24
  _a);
@@ -40,20 +40,21 @@ export declare function isOtherIncomeWithDesc(incomeType: string): boolean;
40
40
  */
41
41
  export declare function isFullDocOrLowDocIncome(incomeType: IncomeType): boolean;
42
42
  /**
43
- * @description Get the employment ids for an applicant for a specific employment type.
44
- * @param {PersonApplicant} applicant An applicant
45
- * @param {string} key Employment type key: PAYG or SelfEmployed.
46
- * @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
47
48
  */
48
- export declare function getEmploymentIds(applicant: PersonApplicant, key: 'PAYG' | 'SelfEmployed'): string[];
49
+ export declare const hasMatchingEmploymentId: (applicant: PersonApplicant, employmentId: string) => boolean;
49
50
  /**
50
- * @description Get applicantId from an array of applicants given an employmentId and employmentType.
51
- * @param {PersonApplicant[]} applicants An array of applicants.
52
- * @param {string} employmentId EmploymentId
53
- * @param {string} key Employment type: PAYG or SelfEmployed
54
- * @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
55
56
  */
56
- export declare function getStoredApplicantId(applicants: PersonApplicant[], employmentId: string, key: 'PAYG' | 'SelfEmployed'): string | undefined;
57
+ export declare function getApplicantIdFromEmploymentId(applicants: PersonApplicant[], employmentId: string): string | undefined;
57
58
  /**
58
59
  * @description Get an applicantId from the event or the applicants.
59
60
  * @param {Income} income Income.
@@ -65,6 +66,6 @@ export declare function getApplicantId({ percentOwned, employmentId }: Income, a
65
66
  * @description Sort Business Income By Year.
66
67
  * @param incomeA Income Details for Self Employed Full Doc.
67
68
  * @param incomeB Income Details for Self Employed Full Doc.
68
- * @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.
69
70
  */
70
- export declare function sortBusinessIncome({ year: yearA }: IncomeBusinessDetails, { year: yearB }: IncomeBusinessDetails): number;
71
+ export declare const sortBusinessIncome: ({ year: yearA }: IncomeBusinessDetails, { year: yearB }: IncomeBusinessDetails) => number;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  exports.__esModule = true;
3
- exports.sortBusinessIncome = exports.getApplicantId = exports.getStoredApplicantId = exports.getEmploymentIds = exports.isFullDocOrLowDocIncome = exports.isOtherIncomeWithDesc = exports.isOtherIncome = exports.isRentalIncome = exports.isSelfEmployedIncome = exports.isPaygIncome = exports.otherIncomeList = 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 = [
@@ -83,32 +83,37 @@ function isFullDocOrLowDocIncome(incomeType) {
83
83
  }
84
84
  exports.isFullDocOrLowDocIncome = isFullDocOrLowDocIncome;
85
85
  /**
86
- * @description Get the employment ids for an applicant for a specific employment type.
87
- * @param {PersonApplicant} applicant An applicant
88
- * @param {string} key Employment type key: PAYG or SelfEmployed.
89
- * @returns {string[]} An array of employment ids for the applicant of the specified type.
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
90
91
  */
91
- function getEmploymentIds(applicant, key) {
92
- return (0, lodash_1.compact)(applicant.Employment.flatMap(function (employment) { return (0, lodash_1.get)(employment, "".concat(key, ".@UniqueID")); }));
93
- }
94
- exports.getEmploymentIds = getEmploymentIds;
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;
95
101
  /**
96
- * @description Get applicantId from an array of applicants given an employmentId and employmentType.
97
- * @param {PersonApplicant[]} applicants An array of applicants.
98
- * @param {string} employmentId EmploymentId
99
- * @param {string} key Employment type: PAYG or SelfEmployed
100
- * @returns {string | undefined} Returns applicantId or undefined.
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
101
107
  */
102
- function getStoredApplicantId(applicants, employmentId, key) {
103
- for (var _i = 0, applicants_1 = applicants; _i < applicants_1.length; _i++) {
104
- var applicant = applicants_1[_i];
105
- var employmentIds = getEmploymentIds(applicant, key);
106
- if (employmentIds.includes(employmentId))
107
- 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'];
108
113
  }
109
- return undefined;
114
+ return applicantId;
110
115
  }
111
- exports.getStoredApplicantId = getStoredApplicantId;
116
+ exports.getApplicantIdFromEmploymentId = getApplicantIdFromEmploymentId;
112
117
  /**
113
118
  * @description Get an applicantId from the event or the applicants.
114
119
  * @param {Income} income Income.
@@ -118,24 +123,18 @@ exports.getStoredApplicantId = getStoredApplicantId;
118
123
  function getApplicantId(_a, applicants) {
119
124
  var percentOwned = _a.percentOwned, employmentId = _a.employmentId;
120
125
  if (applicants === void 0) { applicants = []; }
121
- return ((0, lodash_1.get)(percentOwned, 'owners[0].applicantId') ||
122
- getStoredApplicantId(applicants, employmentId, 'PAYG') ||
123
- getStoredApplicantId(applicants, employmentId, 'SelfEmployed'));
126
+ return (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getApplicantIdFromEmploymentId(applicants, employmentId);
124
127
  }
125
128
  exports.getApplicantId = getApplicantId;
126
129
  /**
127
130
  * @description Sort Business Income By Year.
128
131
  * @param incomeA Income Details for Self Employed Full Doc.
129
132
  * @param incomeB Income Details for Self Employed Full Doc.
130
- * @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.
131
134
  */
132
- function sortBusinessIncome(_a, _b) {
135
+ var sortBusinessIncome = function (_a, _b) {
133
136
  var _c = _a.year, yearA = _c === void 0 ? 0 : _c;
134
137
  var _d = _b.year, yearB = _d === void 0 ? 0 : _d;
135
- if (yearA > yearB)
136
- return -1;
137
- if (yearB > yearA)
138
- return 1;
139
- return 0;
140
- }
138
+ return yearB - yearA;
139
+ };
141
140
  exports.sortBusinessIncome = sortBusinessIncome;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lendi/integrations-transform",
3
- "version": "1.1.3",
3
+ "version": "1.1.9",
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,8 +21,8 @@
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.14.4",
25
- "@lendi/integrations-protocol": "2.3.0",
24
+ "@lendi/integrations-credit-protocol": "1.14.7",
25
+ "@lendi/integrations-protocol": "2.4.9",
26
26
  "clean-deep": "^3.4.0",
27
27
  "date-fns": "2.19.0",
28
28
  "dd-trace": "^0.28.1",