@lendi/act-credit-decisions-transform 2.0.14 → 2.0.16

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.
@@ -3,6 +3,7 @@ import { Payload } from '../types/events/public-employment';
3
3
  * Generates a partial application from a employment event.
4
4
  *
5
5
  * @param employment a employment event payload.
6
+ * @param isSelfEmployed
6
7
  * @returns partialApplication an incomplete application.
7
8
  */
8
9
  export declare function transformEmployment(employment: Payload, isSelfEmployed: boolean): {};
@@ -11,6 +11,7 @@ const enum_mappings_1 = require("../types/enum-mappings");
11
11
  * Generates a partial application from a employment event.
12
12
  *
13
13
  * @param employment a employment event payload.
14
+ * @param isSelfEmployed
14
15
  * @returns partialApplication an incomplete application.
15
16
  */
16
17
  function transformEmployment(employment, isSelfEmployed) {
@@ -32,6 +33,9 @@ function transformEmployment(employment, isSelfEmployed) {
32
33
  break;
33
34
  case public_employment_1.EmploymentType.SelfEmployed:
34
35
  employmentPath = application_paths_1.paths.SelfEmployed;
36
+ /**
37
+ * @todo This is wrong but does not harm anything coz right now we dont call this function with `isSelfEmployed`
38
+ */
35
39
  if (companyId && isSelfEmployed) {
36
40
  (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.CompanyApplicant}.@UniqueID`, companyId);
37
41
  (0, lodash_1.set)(partialApplication, `${employmentPath}.@x_Employer`, companyId);
@@ -17,6 +17,7 @@ export declare function getIncomeMapping(incomeType: IncomeType): Record<string,
17
17
  *
18
18
  * @param payload a partial income event.
19
19
  * @param applicantId PersonApplicant uniqueId on the application.
20
+ * @param storedApplication The stored application version, to retrieve the applicant id when processing SelfEmployed Income
20
21
  * @returns partialApplication an incomplete application.
21
22
  */
22
23
  export declare function transformIncome(payload: IncomePayload, applicantId?: string): PartialApplication;
@@ -32,6 +33,9 @@ export interface SelfEmploymentIncomeMapping {
32
33
  year: string;
33
34
  companyProfitBeforeTax: string;
34
35
  addback: Record<string, string>;
36
+ /**
37
+ * @todo to map this field, currently no field in SelfEmployed to map this field to
38
+ */
35
39
  nonRecurringIncome: string;
36
40
  }
37
41
  /**
@@ -74,14 +74,23 @@ function getIncomeMapping(incomeType) {
74
74
  };
75
75
  }
76
76
  if ((0, is_income_type_1.isFullDocOrLowDocIncome)(incomeType)) {
77
- basePath = application_paths_1.paths.CompanyApplicant;
77
+ basePath = application_paths_1.paths.SelfEmployed;
78
78
  return {
79
- bas: `${basePath}.Income[0].BusinessActivityStatement`,
80
- companyId: `${basePath}.@UniqueID`,
81
- incomes: `${basePath}.Income`,
79
+ // Low Doc and Full Doc common fields
80
+ companyId: `${basePath}.@x_Employer`,
82
81
  gross: `${basePath}.DeclaredIncome.@IncomeAmount`,
82
+ // Full Doc
83
+ incomes: `${basePath}.BusinessIncome`,
84
+ /**
85
+ * @todo To map bas correctly. Currently there is no way to map bas to SelfEmployed
86
+ */
87
+ // bas: `${basePath}.Income[0].BusinessActivityStatement`,
88
+ //
83
89
  };
84
90
  }
91
+ /**
92
+ * @deprecated This is legacy version and shall not be used
93
+ */
85
94
  if ((0, is_income_type_1.isSelfEmployedIncome)(incomeType)) {
86
95
  basePath = application_paths_1.paths.SelfEmployed;
87
96
  const { amount } = exports.EmploymentIncomeTypeMapping[incomeType];
@@ -109,9 +118,10 @@ exports.getIncomeMapping = getIncomeMapping;
109
118
  *
110
119
  * @param payload a partial income event.
111
120
  * @param applicantId PersonApplicant uniqueId on the application.
121
+ * @param storedApplication The stored application version, to retrieve the applicant id when processing SelfEmployed Income
112
122
  * @returns partialApplication an incomplete application.
113
123
  */
114
- function transformIncome(payload, applicantId) {
124
+ function transformIncome(payload, applicantId = undefined) {
115
125
  const { applicationId, id, income } = payload;
116
126
  const { amount: incomeAmount, type: incomeType, frequency: incomeFrequency } = income;
117
127
  const partialApplication = {};
@@ -175,6 +185,9 @@ function transformIncome(payload, applicantId) {
175
185
  }
176
186
  }
177
187
  }
188
+ if ((0, is_income_type_1.isFullDocOrLowDocIncome)(incomeType)) {
189
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@UniqueID`, applicantId);
190
+ }
178
191
  return partialApplication;
179
192
  }
180
193
  exports.transformIncome = transformIncome;
@@ -205,7 +218,7 @@ function createRentalIncome(amount, frequency, ownership = []) {
205
218
  exports.createRentalIncome = createRentalIncome;
206
219
  const selfEmploymentIncomeMapping = {
207
220
  year: '@StartDate',
208
- companyProfitBeforeTax: '@CompanyProfitBeforeTax',
221
+ companyProfitBeforeTax: '@ProfitBeforeTax',
209
222
  addback: {
210
223
  depreciation: 'Addback.@Depreciation',
211
224
  interest: 'Addback.@Interest',
@@ -215,6 +228,10 @@ const selfEmploymentIncomeMapping = {
215
228
  salary: 'Addback.@Salary',
216
229
  superannuationExcess: 'Addback.@SuperannuationExcess',
217
230
  },
231
+ /**
232
+ * @todo to map this field, currently no field in SelfEmployed to map this field to
233
+ * Due to some limitation, leave this field here which will map the data wrongly but eventually will be removed by the validator
234
+ */
218
235
  nonRecurringIncome: 'NonRecurringIncome[0].@Amount',
219
236
  };
220
237
  /**
@@ -18,6 +18,9 @@ export interface Income {
18
18
  bas?: BASDefinition[];
19
19
  benefitType?: BenefitType;
20
20
  comments?: string;
21
+ /**
22
+ * SelfEmployed
23
+ */
21
24
  companyId?: string;
22
25
  description?: string;
23
26
  /**
@@ -43,25 +43,28 @@ export declare function isFullDocOrLowDocIncome(incomeType: IncomeType): boolean
43
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
44
  *
45
45
  * @param {PersonApplicant} applicant - An applicant
46
- * @param {string} employmentId - Employment id being searched for
46
+ * @param {string} lookupId - Could be EmploymentId or x_EmployerId
47
+ * @param lookupField
47
48
  * @returns {boolean} - Whether or not the applicant has an employment with matching employmentId
48
49
  */
49
- export declare const hasMatchingEmploymentId: (applicant: PersonApplicant, employmentId: string) => boolean;
50
+ export declare const hasMatchingEmployment: (lookupField: string) => (applicant: PersonApplicant, lookupId: string) => boolean;
50
51
  /**
51
52
  * Gets the applicant id using the employment id
52
53
  *
53
54
  * @param {PersonApplicant[]} applicants - An array of applicants.
54
55
  * @param {string} employmentId - Employment ID
56
+ * @param lookupId
57
+ * @param lookupField
55
58
  * @returns {string | undefined} - Applicant id or undefined
56
59
  */
57
- export declare function getApplicantIdFromEmploymentId(applicants: PersonApplicant[], employmentId: string): string | undefined;
60
+ export declare function getApplicantIdFromEmployment(applicants: PersonApplicant[], lookupId: string, lookupField: string): string | undefined;
58
61
  /**
59
62
  * @description Get an applicantId from the event or the applicants.
60
63
  * @param {Income} income Income.
61
64
  * @param {PersonApplicant[]} applicants An array of LIXI applicants.
62
65
  * @returns {string | undefined} An applicantId or undefined.
63
66
  */
64
- export declare function getApplicantId({ percentOwned, employmentId }: Income, applicants?: PersonApplicant[]): string | undefined;
67
+ export declare function getApplicantId({ percentOwned, employmentId, companyId }: Income, applicants?: PersonApplicant[]): string | undefined;
65
68
  /**
66
69
  * @description Sort Business Income By Year.
67
70
  * @param incomeA Income Details for Self Employed Full Doc.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
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;
3
+ exports.sortBusinessIncome = exports.getApplicantId = exports.getApplicantIdFromEmployment = exports.hasMatchingEmployment = exports.isFullDocOrLowDocIncome = exports.isOtherIncomeWithDesc = exports.isOtherIncome = exports.isRentalIncome = exports.isSelfEmployedIncome = exports.isPaygIncome = exports.otherIncomeList = exports.PAYGList = exports.descriptionOtherIncomeTypes = void 0;
4
4
  const lodash_1 = require("lodash");
5
5
  const public_income_1 = require("../types/events/public-income");
6
6
  exports.descriptionOtherIncomeTypes = [
@@ -86,40 +86,47 @@ exports.isFullDocOrLowDocIncome = isFullDocOrLowDocIncome;
86
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
87
  *
88
88
  * @param {PersonApplicant} applicant - An applicant
89
- * @param {string} employmentId - Employment id being searched for
89
+ * @param {string} lookupId - Could be EmploymentId or x_EmployerId
90
+ * @param lookupField
90
91
  * @returns {boolean} - Whether or not the applicant has an employment with matching employmentId
91
92
  */
92
- const hasMatchingEmploymentId = (applicant, employmentId) => (applicant.Employment || []).some((employment) => {
93
- const id = (0, lodash_1.get)(employment, 'PAYG.@UniqueID') ||
94
- (0, lodash_1.get)(employment, 'SelfEmployed.@UniqueID') ||
95
- (0, lodash_1.get)(employment, 'NotEmployed.@UniqueID');
96
- return id === employmentId;
93
+ const hasMatchingEmployment = (lookupField) => (applicant, lookupId) => (applicant.Employment || []).some((employment) => {
94
+ const id = (0, lodash_1.get)(employment, `PAYG.${lookupField}`) ||
95
+ (0, lodash_1.get)(employment, `SelfEmployed.${lookupField}`) ||
96
+ (0, lodash_1.get)(employment, `NotEmployed.${lookupField}`);
97
+ return id === lookupId;
97
98
  });
98
- exports.hasMatchingEmploymentId = hasMatchingEmploymentId;
99
+ exports.hasMatchingEmployment = hasMatchingEmployment;
99
100
  /**
100
101
  * Gets the applicant id using the employment id
101
102
  *
102
103
  * @param {PersonApplicant[]} applicants - An array of applicants.
103
104
  * @param {string} employmentId - Employment ID
105
+ * @param lookupId
106
+ * @param lookupField
104
107
  * @returns {string | undefined} - Applicant id or undefined
105
108
  */
106
- function getApplicantIdFromEmploymentId(applicants, employmentId) {
109
+ function getApplicantIdFromEmployment(applicants, lookupId, lookupField) {
107
110
  let applicantId;
108
- if (applicants && employmentId) {
109
- const applicant = applicants.find((applicant) => (0, exports.hasMatchingEmploymentId)(applicant, employmentId));
111
+ if (applicants && lookupId) {
112
+ const applicant = applicants.find((applicant) => (0, exports.hasMatchingEmployment)(lookupField)(applicant, lookupId));
110
113
  applicantId = applicant === null || applicant === void 0 ? void 0 : applicant['@UniqueID'];
111
114
  }
112
115
  return applicantId;
113
116
  }
114
- exports.getApplicantIdFromEmploymentId = getApplicantIdFromEmploymentId;
117
+ exports.getApplicantIdFromEmployment = getApplicantIdFromEmployment;
115
118
  /**
116
119
  * @description Get an applicantId from the event or the applicants.
117
120
  * @param {Income} income Income.
118
121
  * @param {PersonApplicant[]} applicants An array of LIXI applicants.
119
122
  * @returns {string | undefined} An applicantId or undefined.
120
123
  */
121
- function getApplicantId({ percentOwned, employmentId }, applicants = []) {
122
- return (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getApplicantIdFromEmploymentId(applicants, employmentId);
124
+ function getApplicantId({ percentOwned, employmentId, companyId }, applicants = []) {
125
+ return ((0, lodash_1.get)(percentOwned, 'owners[0].applicantId') ||
126
+ // for company applicant
127
+ getApplicantIdFromEmployment(applicants, employmentId, '@UniqueID') ||
128
+ // for selfemployed
129
+ getApplicantIdFromEmployment(applicants, companyId, '@x_Employer'));
123
130
  }
124
131
  exports.getApplicantId = getApplicantId;
125
132
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lendi/act-credit-decisions-transform",
3
- "version": "2.0.14",
3
+ "version": "2.0.16",
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",
@@ -22,7 +22,7 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@lendi/integrations-credit-protocol": "1.18.8",
25
- "@lendi/act-eac-integrations-protocol": "3.1.4",
25
+ "@lendi/act-eac-integrations-protocol": "3.1.6",
26
26
  "clean-deep": "^3.4.0",
27
27
  "date-fns": "2.19.0",
28
28
  "lodash": "^4.17.15"