@lendi/integrations-transform 1.1.5 → 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.
@@ -39,22 +39,22 @@ export declare function isOtherIncomeWithDesc(incomeType: string): boolean;
39
39
  * @returns {boolean} True if either Full Doc or Low Doc Self Employed Income.
40
40
  */
41
41
  export declare function isFullDocOrLowDocIncome(incomeType: IncomeType): boolean;
42
- declare type EmploymentTypes = 'PAYG' | 'SelfEmployed' | 'NotEmployed';
43
42
  /**
44
- * @description Get the employment ids for an applicant for a specific employment type.
45
- * @param {PersonApplicant} applicant An applicant
46
- * @param {string} key Employment type key: PAYG or SelfEmployed.
47
- * @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
48
48
  */
49
- export declare function getEmploymentIds(applicant: PersonApplicant, key: EmploymentTypes): string[];
49
+ export declare const hasMatchingEmploymentId: (applicant: PersonApplicant, employmentId: string) => boolean;
50
50
  /**
51
- * @description Get applicantId from an array of applicants given an employmentId and employmentType.
52
- * @param {PersonApplicant[]} applicants An array of applicants.
53
- * @param {string} employmentId EmploymentId
54
- * @param {string} key Employment type: PAYG or SelfEmployed
55
- * @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
56
56
  */
57
- export declare function getStoredApplicantId(applicants: PersonApplicant[], employmentId: string, key: EmploymentTypes): string | undefined;
57
+ export declare function getApplicantIdFromEmploymentId(applicants: PersonApplicant[], employmentId: string): string | undefined;
58
58
  /**
59
59
  * @description Get an applicantId from the event or the applicants.
60
60
  * @param {Income} income Income.
@@ -69,4 +69,3 @@ export declare function getApplicantId({ percentOwned, employmentId }: Income, a
69
69
  * @returns {0 | < 0 | > 0} Returns a number to be used for sorting income.
70
70
  */
71
71
  export declare const sortBusinessIncome: ({ year: yearA }: IncomeBusinessDetails, { year: yearB }: IncomeBusinessDetails) => number;
72
- export {};
@@ -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,10 +123,7 @@ 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') ||
124
- getStoredApplicantId(applicants, employmentId, 'NotEmployed'));
126
+ return (0, lodash_1.get)(percentOwned, 'owners[0].applicantId') || getApplicantIdFromEmploymentId(applicants, employmentId);
125
127
  }
126
128
  exports.getApplicantId = getApplicantId;
127
129
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lendi/integrations-transform",
3
- "version": "1.1.5",
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",