@lendi/integrations-transform 1.6.0 → 1.6.3

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.
Files changed (89) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/lib/index.js +26 -10
  3. package/lib/logger.js +5 -2
  4. package/lib/schemas/public-application-event.json +7 -0
  5. package/lib/transform-events/generate-asset-liability-link.js +12 -8
  6. package/lib/transform-events/generate-credit-report-rebuilt.js +12 -8
  7. package/lib/transform-events/generate-employment.js +41 -37
  8. package/lib/transform-events/generate-required-document.d.ts +1 -2
  9. package/lib/transform-events/generate-required-document.js +41 -32
  10. package/lib/transform-events/transform-applicant.js +60 -53
  11. package/lib/transform-events/transform-application-workflow.js +9 -5
  12. package/lib/transform-events/transform-application.d.ts +6 -8
  13. package/lib/transform-events/transform-application.js +30 -25
  14. package/lib/transform-events/transform-asset-address.js +25 -19
  15. package/lib/transform-events/transform-asset.js +128 -118
  16. package/lib/transform-events/transform-expenses.js +39 -31
  17. package/lib/transform-events/transform-funding-position.js +32 -27
  18. package/lib/transform-events/transform-income.js +73 -65
  19. package/lib/transform-events/transform-liability.js +59 -55
  20. package/lib/transform-events/transform-percent-owned.js +7 -3
  21. package/lib/types/enum-mappings/alieo-frequency.js +22 -19
  22. package/lib/types/enum-mappings/asset-type.js +16 -13
  23. package/lib/types/enum-mappings/builder-type.js +8 -5
  24. package/lib/types/enum-mappings/construction-type.js +9 -6
  25. package/lib/types/enum-mappings/country-code.js +245 -242
  26. package/lib/types/enum-mappings/employment-basis.js +11 -8
  27. package/lib/types/enum-mappings/expense-frequency.js +10 -7
  28. package/lib/types/enum-mappings/funding-position.js +32 -29
  29. package/lib/types/enum-mappings/government-benefits.js +9 -6
  30. package/lib/types/enum-mappings/guarantor-relationship-type.js +15 -12
  31. package/lib/types/enum-mappings/housing-status.js +14 -11
  32. package/lib/types/enum-mappings/income-type.js +15 -12
  33. package/lib/types/enum-mappings/index.js +43 -27
  34. package/lib/types/enum-mappings/liability-payment-type.js +8 -5
  35. package/lib/types/enum-mappings/liability-type.js +20 -17
  36. package/lib/types/enum-mappings/living-expense.js +29 -26
  37. package/lib/types/enum-mappings/marital-status.js +11 -8
  38. package/lib/types/enum-mappings/postcode.js +13 -10
  39. package/lib/types/enum-mappings/preferred-repayment.js +9 -6
  40. package/lib/types/enum-mappings/proof-of-identity.js +9 -6
  41. package/lib/types/enum-mappings/property-expense-category.js +10 -7
  42. package/lib/types/enum-mappings/public-financial-asset.js +11 -8
  43. package/lib/types/enum-mappings/public-primary-purpose.js +8 -5
  44. package/lib/types/enum-mappings/public-property-status.js +10 -7
  45. package/lib/types/enum-mappings/public-property-type.js +22 -19
  46. package/lib/types/enum-mappings/residency-status.js +10 -7
  47. package/lib/types/enum-mappings/title-gender.js +12 -9
  48. package/lib/types/enum-mappings/title.js +12 -9
  49. package/lib/types/enum-mappings/to-be-purchased.js +7 -4
  50. package/lib/types/enum-mappings/to-be-used-as-security.js +7 -4
  51. package/lib/types/enum-mappings/transaction-type.js +8 -5
  52. package/lib/types/enum-mappings/verification.js +12 -9
  53. package/lib/types/events/applicant-delete.js +7 -4
  54. package/lib/types/events/application-workflow.js +13 -10
  55. package/lib/types/events/asset-delete.js +7 -4
  56. package/lib/types/events/asset-liability-relation-delete.js +7 -4
  57. package/lib/types/events/credit-report-retrieved.js +7 -4
  58. package/lib/types/events/employment-delete.js +5 -2
  59. package/lib/types/events/expense-delete.js +5 -2
  60. package/lib/types/events/funding-position.js +9 -6
  61. package/lib/types/events/income-delete.js +7 -4
  62. package/lib/types/events/liability-delete.js +5 -2
  63. package/lib/types/events/opportunity.js +9 -6
  64. package/lib/types/events/public-applicant.js +31 -28
  65. package/lib/types/events/public-application.d.ts +1 -0
  66. package/lib/types/events/public-application.js +29 -26
  67. package/lib/types/events/public-asset-liability-relation.js +7 -4
  68. package/lib/types/events/public-asset.js +29 -26
  69. package/lib/types/events/public-employment.js +21 -18
  70. package/lib/types/events/public-expense.js +11 -8
  71. package/lib/types/events/public-funding-position.js +5 -2
  72. package/lib/types/events/public-income.js +15 -12
  73. package/lib/types/events/public-liability.js +19 -16
  74. package/lib/types/events/public-required-document.js +17 -14
  75. package/lib/types/partial-application.js +2 -1
  76. package/lib/types/recursive-partial.js +2 -1
  77. package/lib/update-application/merge-application.js +6 -2
  78. package/lib/update-application/update-primary-applicant.js +17 -12
  79. package/lib/utils/address-tools.js +43 -33
  80. package/lib/utils/clean-up.js +7 -3
  81. package/lib/utils/formatYesNo.js +6 -2
  82. package/lib/utils/generate-address.js +26 -21
  83. package/lib/utils/get-financial-institution.js +8 -4
  84. package/lib/utils/is-asset-type.js +20 -13
  85. package/lib/utils/is-income-type.js +58 -45
  86. package/lib/utils/iso-date.js +6 -2
  87. package/lib/utils/normalise-date.js +5 -1
  88. package/lib/utils/round-decimal.js +5 -1
  89. package/package.json +4 -4
@@ -1,24 +1,27 @@
1
- import { Custom6TypeList, NonRealEstateAssetTypeList, OtherAssetTypeList, ResidentialTypeList, YesNoList, OccupancyList, } from '@lendi/integrations-credit-protocol/types/lixi-internal-request';
2
- import { paths } from '@lendi/integrations-credit-protocol/utils/application-paths';
3
- import { Custom1CategoryTypeNameList, Custom2PropertyTypeNameList, } from '@lendi/integrations-protocol/lib/types/lixi-internal-request';
4
- import { v4 as uuidv4 } from 'uuid';
5
- import { isEmpty, set } from 'lodash';
6
- import { logger } from '../logger';
7
- import { assetTypeMapping, financialAssetMapping, incomeExpenseFrequencyMapping, livingExpenseMapping, primaryPurposeMapping, propertyExpenseCategoryMapping, propertyStatusMapping, propertyTypeMapping, toBePurchasedMapping, toBeUsedAsSecurityMapping, } from '../types/enum-mappings';
8
- import { AssetType, PropertyExpenseType, ZoneType, } from '../types/events/public-asset';
9
- import { Frequency } from '../types/events/public-expense';
10
- import { getFinancialInstitution } from '../utils/get-financial-institution';
11
- import { isFinancialAsset, isMotorVehicle, isOtherAsset, isRealEstateAsset } from '../utils/is-asset-type';
12
- import { roundDecimal } from '../utils/round-decimal';
13
- import { transformAddress } from './transform-asset-address';
14
- import { transformPercentOwned } from './transform-percent-owned';
15
- import { builderTypeMapping } from '../types/enum-mappings/builder-type';
16
- import { constructionTypeMapping } from '../types/enum-mappings/construction-type';
17
- import { booleanMapping } from '..';
18
- export const propertyTypeNameList = Object.values(Custom2PropertyTypeNameList);
19
- export const residentialTypeList = Object.values(ResidentialTypeList);
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.normalizeAmounts = exports.determineOccupancy = exports.generatePropertyExpenses = exports.generateLivingExpenses = exports.getAssetMapping = exports.getPropertyType = exports.transformAsset = exports.residentialTypeList = exports.propertyTypeNameList = void 0;
4
+ const lixi_internal_request_1 = require("@lendi/integrations-credit-protocol/types/lixi-internal-request");
5
+ const application_paths_1 = require("@lendi/integrations-credit-protocol/utils/application-paths");
6
+ const lixi_internal_request_2 = require("@lendi/integrations-protocol/lib/types/lixi-internal-request");
7
+ const uuid_1 = require("uuid");
8
+ const lodash_1 = require("lodash");
9
+ const logger_1 = require("../logger");
10
+ const enum_mappings_1 = require("../types/enum-mappings");
11
+ const public_asset_1 = require("../types/events/public-asset");
12
+ const public_expense_1 = require("../types/events/public-expense");
13
+ const get_financial_institution_1 = require("../utils/get-financial-institution");
14
+ const is_asset_type_1 = require("../utils/is-asset-type");
15
+ const round_decimal_1 = require("../utils/round-decimal");
16
+ const transform_asset_address_1 = require("./transform-asset-address");
17
+ const transform_percent_owned_1 = require("./transform-percent-owned");
18
+ const builder_type_1 = require("../types/enum-mappings/builder-type");
19
+ const construction_type_1 = require("../types/enum-mappings/construction-type");
20
+ const __1 = require("..");
21
+ exports.propertyTypeNameList = Object.values(lixi_internal_request_2.Custom2PropertyTypeNameList);
22
+ exports.residentialTypeList = Object.values(lixi_internal_request_1.ResidentialTypeList);
20
23
  // will add this path to protocol
21
- const constructionDetailsPath = `${paths.RealEstateAsset}.ConstructionDetails`;
24
+ const constructionDetailsPath = `${application_paths_1.paths.RealEstateAsset}.ConstructionDetails`;
22
25
  const constructionDetailsMapping = {
23
26
  builderType: `${constructionDetailsPath}.@BuilderType`,
24
27
  buildPriceAmount: `${constructionDetailsPath}.@BuildPriceAmount`,
@@ -34,42 +37,42 @@ const constructionDetailsMapping = {
34
37
  * @param {Payload} asset - A partial public asset.
35
38
  * @returns {PartialApplication} A partial InternalRequest.
36
39
  */
37
- export function transformAsset({ asset, applicationId, id }) {
40
+ function transformAsset({ asset, applicationId, id }) {
38
41
  var _a;
39
- const isPropertyAsset = isRealEstateAsset(asset);
40
- const idPath = isPropertyAsset ? `${paths.RealEstateAsset}.@UniqueID` : `${paths.NonRealEstateAsset}.@UniqueID`;
42
+ const isPropertyAsset = (0, is_asset_type_1.isRealEstateAsset)(asset);
43
+ const idPath = isPropertyAsset ? `${application_paths_1.paths.RealEstateAsset}.@UniqueID` : `${application_paths_1.paths.NonRealEstateAsset}.@UniqueID`;
41
44
  const addressId = `${id}-address`;
42
45
  const assetMapping = getAssetMapping(asset);
43
46
  const partialApplication = {};
44
- set(partialApplication, paths.ApplicationId, applicationId);
45
- set(partialApplication, idPath, id);
47
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
48
+ (0, lodash_1.set)(partialApplication, idPath, id);
46
49
  if (isPropertyAsset) {
47
- set(partialApplication, `${paths.RealEstateAsset}.@MultipleDwellings`, YesNoList.No);
48
- set(partialApplication, `${paths.RealEstateAsset}.@x_Address`, addressId);
50
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.RealEstateAsset}.@MultipleDwellings`, lixi_internal_request_1.YesNoList.No);
51
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.RealEstateAsset}.@x_Address`, addressId);
49
52
  }
50
53
  else {
51
- set(partialApplication, `${paths.NonRealEstateAsset}.@Type`, assetTypeMapping[asset.type]);
54
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.@Type`, enum_mappings_1.assetTypeMapping[asset.type]);
52
55
  }
53
- if (isFinancialAsset(asset)) {
54
- set(partialApplication, `${paths.NonRealEstateAsset}.@Type`, NonRealEstateAssetTypeList.FinancialAsset);
55
- set(partialApplication, `${paths.NonRealEstateAsset}.FinancialAsset.@Type`, financialAssetMapping[asset.type]);
56
+ if ((0, is_asset_type_1.isFinancialAsset)(asset)) {
57
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.@Type`, lixi_internal_request_1.NonRealEstateAssetTypeList.FinancialAsset);
58
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.FinancialAsset.@Type`, enum_mappings_1.financialAssetMapping[asset.type]);
56
59
  }
57
- if (isOtherAsset(asset)) {
58
- set(partialApplication, `${paths.NonRealEstateAsset}.@Type`, NonRealEstateAssetTypeList.Other);
60
+ if ((0, is_asset_type_1.isOtherAsset)(asset)) {
61
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.@Type`, lixi_internal_request_1.NonRealEstateAssetTypeList.Other);
59
62
  }
60
63
  switch (asset.type) {
61
- case AssetType.Vehicle:
62
- set(partialApplication, `${paths.NonRealEstateAsset}.@Type`, NonRealEstateAssetTypeList.MotorVehicleAndTransport);
64
+ case public_asset_1.AssetType.Vehicle:
65
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.@Type`, lixi_internal_request_1.NonRealEstateAssetTypeList.MotorVehicleAndTransport);
63
66
  break;
64
- case AssetType.HomeContents:
65
- set(partialApplication, `${paths.NonRealEstateAsset}.OtherAsset.@Type`, OtherAssetTypeList.HomeContents);
67
+ case public_asset_1.AssetType.HomeContents:
68
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.OtherAsset.@Type`, lixi_internal_request_1.OtherAssetTypeList.HomeContents);
66
69
  break;
67
- case AssetType.Gifts:
68
- set(partialApplication, `${paths.NonRealEstateAsset}.OtherAsset.@Description`, asset.description || 'Asset Gifts');
70
+ case public_asset_1.AssetType.Gifts:
71
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.OtherAsset.@Description`, asset.description || 'Asset Gifts');
69
72
  break;
70
- case AssetType.OtherAsset:
73
+ case public_asset_1.AssetType.OtherAsset:
71
74
  if (asset.description) {
72
- set(partialApplication, `${paths.NonRealEstateAsset}.OtherAsset.@Description`, asset.description);
75
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.NonRealEstateAsset}.OtherAsset.@Description`, asset.description);
73
76
  }
74
77
  break;
75
78
  }
@@ -79,167 +82,170 @@ export function transformAsset({ asset, applicationId, id }) {
79
82
  case 'contractDetails':
80
83
  const { contractDate } = value;
81
84
  if (contractDate)
82
- set(partialApplication, assetMapping.contractDate, contractDate);
85
+ (0, lodash_1.set)(partialApplication, assetMapping.contractDate, contractDate);
83
86
  break;
84
87
  case 'primaryPurpose':
85
- set(partialApplication, assetMapping[key], primaryPurposeMapping[value]);
88
+ (0, lodash_1.set)(partialApplication, assetMapping[key], enum_mappings_1.primaryPurposeMapping[value]);
86
89
  break;
87
90
  case 'toBePurchased':
88
- set(partialApplication, assetMapping[key], toBePurchasedMapping[value]);
91
+ (0, lodash_1.set)(partialApplication, assetMapping[key], enum_mappings_1.toBePurchasedMapping[value]);
89
92
  break;
90
93
  case 'propertyExpenses':
91
- if (!asset.percentOwned || isEmpty((_a = asset.percentOwned) === null || _a === void 0 ? void 0 : _a.owners)) {
94
+ if (!asset.percentOwned || (0, lodash_1.isEmpty)((_a = asset.percentOwned) === null || _a === void 0 ? void 0 : _a.owners)) {
92
95
  break;
93
96
  }
94
97
  const propertyExpenses = generatePropertyExpenses(value);
95
- set(partialApplication, `${paths.RealEstateAsset}.PropertyExpense`, propertyExpenses);
98
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.RealEstateAsset}.PropertyExpense`, propertyExpenses);
96
99
  const livingExpenses = generateLivingExpenses(asset.percentOwned, id, value);
97
- set(partialApplication, assetMapping[key], livingExpenses);
98
- set(partialApplication, `${paths.RealEstateAsset}.@Occupancy`, determineOccupancy(value));
100
+ (0, lodash_1.set)(partialApplication, assetMapping[key], livingExpenses);
101
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.RealEstateAsset}.@Occupancy`, determineOccupancy(value));
99
102
  break;
100
103
  case 'propertyStatus':
101
- set(partialApplication, assetMapping[key], propertyStatusMapping[value]);
104
+ (0, lodash_1.set)(partialApplication, assetMapping[key], enum_mappings_1.propertyStatusMapping[value]);
102
105
  break;
103
106
  case 'toBeUsedAsSecurity':
104
107
  if (isPropertyAsset)
105
- set(partialApplication, assetMapping[key], toBeUsedAsSecurityMapping[value]);
108
+ (0, lodash_1.set)(partialApplication, assetMapping[key], enum_mappings_1.toBeUsedAsSecurityMapping[value]);
106
109
  break;
107
110
  case 'propertyType':
108
111
  const propertyTypeMapping = getPropertyType(value);
109
112
  if (!propertyTypeMapping) {
110
- logger.warn({ message: `Unknown propertyType ${value} for asset ${id}`, applicationId });
113
+ logger_1.logger.warn({ message: `Unknown propertyType ${value} for asset ${id}`, applicationId });
111
114
  }
112
115
  const { path, value: mappedValue } = propertyTypeMapping;
113
- set(partialApplication, path, mappedValue);
116
+ (0, lodash_1.set)(partialApplication, path, mappedValue);
114
117
  break;
115
118
  case 'zoneType':
116
- if (asset.zoneType === ZoneType.Commercial) {
117
- set(partialApplication, `${paths.RealEstateAsset}.Commercial.@Type`, OtherAssetTypeList.Other);
118
- set(partialApplication, assetMapping[key], Custom6TypeList.Commercial);
119
+ if (asset.zoneType === public_asset_1.ZoneType.Commercial) {
120
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.RealEstateAsset}.Commercial.@Type`, lixi_internal_request_1.OtherAssetTypeList.Other);
121
+ (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom6TypeList.Commercial);
119
122
  }
120
123
  else {
121
- set(partialApplication, assetMapping[key], Custom6TypeList.Residential);
124
+ (0, lodash_1.set)(partialApplication, assetMapping[key], lixi_internal_request_1.Custom6TypeList.Residential);
122
125
  }
123
126
  break;
124
127
  case 'financialInstitution':
125
- if (isFinancialAsset(asset)) {
126
- const financialInstitution = getFinancialInstitution(value.toString());
127
- set(partialApplication, assetMapping[key], financialInstitution);
128
+ if ((0, is_asset_type_1.isFinancialAsset)(asset)) {
129
+ const financialInstitution = (0, get_financial_institution_1.getFinancialInstitution)(value.toString());
130
+ (0, lodash_1.set)(partialApplication, assetMapping[key], financialInstitution);
128
131
  }
129
132
  break;
130
133
  case 'year':
131
- set(partialApplication, assetMapping[key], value.toString());
134
+ (0, lodash_1.set)(partialApplication, assetMapping[key], value.toString());
132
135
  break;
133
136
  case 'address':
134
- set(partialApplication, assetMapping[key], transformAddress(value, addressId));
137
+ (0, lodash_1.set)(partialApplication, assetMapping[key], (0, transform_asset_address_1.transformAddress)(value, addressId));
135
138
  break;
136
139
  case 'isConstruction':
137
- set(partialApplication, assetMapping[key], booleanMapping(value));
140
+ (0, lodash_1.set)(partialApplication, assetMapping[key], (0, __1.booleanMapping)(value));
138
141
  break;
139
142
  case 'percentOwned':
140
- const percentOwned = transformPercentOwned(value);
143
+ const percentOwned = (0, transform_percent_owned_1.transformPercentOwned)(value);
141
144
  if (percentOwned) {
142
- set(partialApplication, assetMapping[key], percentOwned);
145
+ (0, lodash_1.set)(partialApplication, assetMapping[key], percentOwned);
143
146
  }
144
147
  break;
145
148
  case 'constructionDetails':
146
149
  for (const [key, constructionDetailsValue] of Object.entries(value)) {
147
150
  switch (key) {
148
151
  case 'builderType':
149
- set(partialApplication, constructionDetailsMapping[key], builderTypeMapping[constructionDetailsValue]);
152
+ (0, lodash_1.set)(partialApplication, constructionDetailsMapping[key], builder_type_1.builderTypeMapping[constructionDetailsValue]);
150
153
  break;
151
154
  case 'constructionType':
152
- set(partialApplication, constructionDetailsMapping[key], constructionTypeMapping[constructionDetailsValue]);
155
+ (0, lodash_1.set)(partialApplication, constructionDetailsMapping[key], construction_type_1.constructionTypeMapping[constructionDetailsValue]);
153
156
  break;
154
157
  case 'isFixedPriceContract':
155
- set(partialApplication, constructionDetailsMapping[key], booleanMapping(constructionDetailsValue));
158
+ (0, lodash_1.set)(partialApplication, constructionDetailsMapping[key], (0, __1.booleanMapping)(constructionDetailsValue));
156
159
  break;
157
160
  default:
158
- set(partialApplication, constructionDetailsMapping[key], constructionDetailsValue);
161
+ (0, lodash_1.set)(partialApplication, constructionDetailsMapping[key], constructionDetailsValue);
159
162
  break;
160
163
  }
161
164
  }
162
165
  break;
163
166
  case 'estimatedValue':
164
167
  if (asset.isConstruction) {
165
- set(partialApplication, constructionDetailsMapping[key], value);
168
+ (0, lodash_1.set)(partialApplication, constructionDetailsMapping[key], value);
166
169
  }
167
- set(partialApplication, assetMapping[key], value);
170
+ (0, lodash_1.set)(partialApplication, assetMapping[key], value);
168
171
  break;
169
172
  default:
170
- set(partialApplication, assetMapping[key], value);
173
+ (0, lodash_1.set)(partialApplication, assetMapping[key], value);
171
174
  break;
172
175
  }
173
176
  }
174
177
  }
175
178
  return partialApplication;
176
179
  }
180
+ exports.transformAsset = transformAsset;
177
181
  /**
178
182
  * @description Map the propertyType to a RealEstateAsset path and the value.
179
183
  * @param {PropertyType} propertyType - A propertyType.
180
184
  * @returns {PropertyTypeMapping | null} A path and value to be used for property type mapping.
181
185
  */
182
- export function getPropertyType(propertyType) {
183
- const value = propertyTypeMapping[propertyType];
184
- if (residentialTypeList.includes(value)) {
186
+ function getPropertyType(propertyType) {
187
+ const value = enum_mappings_1.propertyTypeMapping[propertyType];
188
+ if (exports.residentialTypeList.includes(value)) {
185
189
  return {
186
- path: `${paths.RealEstateAsset}.Residential`,
190
+ path: `${application_paths_1.paths.RealEstateAsset}.Residential`,
187
191
  value: {
188
192
  '@Type': value,
189
193
  },
190
194
  };
191
195
  }
192
- if (propertyTypeNameList.includes(value)) {
196
+ if (exports.propertyTypeNameList.includes(value)) {
193
197
  return {
194
- path: `${paths.RealEstateAsset}.PropertyType`,
198
+ path: `${application_paths_1.paths.RealEstateAsset}.PropertyType`,
195
199
  value: {
196
200
  '@PropertyTypeName': value,
197
- '@CategoryTypeName': Custom1CategoryTypeNameList.Residential,
201
+ '@CategoryTypeName': lixi_internal_request_2.Custom1CategoryTypeNameList.Residential,
198
202
  },
199
203
  };
200
204
  }
201
205
  return null;
202
206
  }
207
+ exports.getPropertyType = getPropertyType;
203
208
  /**
204
209
  * @description Get the asset transform mapping for various asset types.
205
210
  * @param {Asset} asset An Asset
206
211
  * @returns {Record<string, string>} Asset Transform Mapping.
207
212
  */
208
- export function getAssetMapping(asset) {
209
- let estimatedValue = `${paths.NonRealEstateAsset}.EstimatedValue.@Value`;
210
- let percentOwned = `${paths.NonRealEstateAsset}.PercentOwned`;
213
+ function getAssetMapping(asset) {
214
+ let estimatedValue = `${application_paths_1.paths.NonRealEstateAsset}.EstimatedValue.@Value`;
215
+ let percentOwned = `${application_paths_1.paths.NonRealEstateAsset}.PercentOwned`;
211
216
  const baseMapping = {
212
217
  estimatedValue,
213
218
  percentOwned,
214
219
  };
215
- if (isRealEstateAsset(asset)) {
216
- estimatedValue = `${paths.RealEstateAsset}.EstimatedValue.@Value`;
217
- percentOwned = `${paths.RealEstateAsset}.PercentOwned`;
220
+ if ((0, is_asset_type_1.isRealEstateAsset)(asset)) {
221
+ estimatedValue = `${application_paths_1.paths.RealEstateAsset}.EstimatedValue.@Value`;
222
+ percentOwned = `${application_paths_1.paths.RealEstateAsset}.PercentOwned`;
218
223
  return {
219
- address: paths.Address,
224
+ address: application_paths_1.paths.Address,
220
225
  contractDetails: 'contractDetails',
221
- contractDate: `${paths.RealEstateAsset}.ContractDetails.@ContractDate`,
226
+ contractDate: `${application_paths_1.paths.RealEstateAsset}.ContractDetails.@ContractDate`,
222
227
  estimatedValue,
223
228
  percentOwned,
224
- primaryPurpose: `${paths.RealEstateAsset}.@PrimaryPurpose`,
225
- propertyExpenses: paths.LivingExpenses,
226
- propertyStatus: `${paths.RealEstateAsset}.@Status`,
227
- propertyType: `${paths.RealEstateAsset}.Residential`,
228
- toBePurchased: `${paths.RealEstateAsset}.@Transaction`,
229
- toBeUsedAsSecurity: `${paths.RealEstateAsset}.@ToBeUsedAsSecurity`,
230
- zoneType: `${paths.RealEstateAsset}.Zoning.@Type`,
231
- isConstruction: `${paths.RealEstateAsset}.@Construction`,
232
- constructionDetails: `${paths.RealEstateAsset}.ConstructionDetails`,
229
+ primaryPurpose: `${application_paths_1.paths.RealEstateAsset}.@PrimaryPurpose`,
230
+ propertyExpenses: application_paths_1.paths.LivingExpenses,
231
+ propertyStatus: `${application_paths_1.paths.RealEstateAsset}.@Status`,
232
+ propertyType: `${application_paths_1.paths.RealEstateAsset}.Residential`,
233
+ toBePurchased: `${application_paths_1.paths.RealEstateAsset}.@Transaction`,
234
+ toBeUsedAsSecurity: `${application_paths_1.paths.RealEstateAsset}.@ToBeUsedAsSecurity`,
235
+ zoneType: `${application_paths_1.paths.RealEstateAsset}.Zoning.@Type`,
236
+ isConstruction: `${application_paths_1.paths.RealEstateAsset}.@Construction`,
237
+ constructionDetails: `${application_paths_1.paths.RealEstateAsset}.ConstructionDetails`,
233
238
  };
234
239
  }
235
- if (isMotorVehicle(asset)) {
236
- return Object.assign(Object.assign({}, baseMapping), { make: `${paths.NonRealEstateAsset}.MotorVehicle.@Make`, model: `${paths.NonRealEstateAsset}.MotorVehicle.@Model`, year: `${paths.NonRealEstateAsset}.MotorVehicle.@Year` });
240
+ if ((0, is_asset_type_1.isMotorVehicle)(asset)) {
241
+ return Object.assign(Object.assign({}, baseMapping), { make: `${application_paths_1.paths.NonRealEstateAsset}.MotorVehicle.@Make`, model: `${application_paths_1.paths.NonRealEstateAsset}.MotorVehicle.@Model`, year: `${application_paths_1.paths.NonRealEstateAsset}.MotorVehicle.@Year` });
237
242
  }
238
- if (isFinancialAsset(asset)) {
239
- return Object.assign(Object.assign({}, baseMapping), { financialInstitution: `${paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@FinancialInstitution`, financialInstitutionAccountNumber: `${paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@AccountNumber`, financialInstitutionBsb: `${paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@BSB` });
243
+ if ((0, is_asset_type_1.isFinancialAsset)(asset)) {
244
+ return Object.assign(Object.assign({}, baseMapping), { financialInstitution: `${application_paths_1.paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@FinancialInstitution`, financialInstitutionAccountNumber: `${application_paths_1.paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@AccountNumber`, financialInstitutionBsb: `${application_paths_1.paths.NonRealEstateAsset}.FinancialAsset.AccountNumber.@BSB` });
240
245
  }
241
246
  return baseMapping;
242
247
  }
248
+ exports.getAssetMapping = getAssetMapping;
243
249
  /**
244
250
  * Creates living expense items from a propertyExpense object.
245
251
  *
@@ -250,17 +256,17 @@ export function getAssetMapping(asset) {
250
256
  * @param assetId
251
257
  * @param propertyExpenses
252
258
  */
253
- export function generateLivingExpenses(percentOwned, assetId, propertyExpenses) {
259
+ function generateLivingExpenses(percentOwned, assetId, propertyExpenses) {
254
260
  let livingExpenses = [];
255
261
  const filteredPropertyExpenses = propertyExpenses.filter((expense) => expense.amount !== undefined);
256
262
  percentOwned.owners.forEach((owner) => {
257
263
  const expenses = filteredPropertyExpenses.map((expense) => {
258
264
  normalizeAmounts(expense);
259
265
  return {
260
- '@Amount': roundDecimal(expense.amount * owner.percent),
261
- '@Category': livingExpenseMapping[expense.type],
262
- '@Frequency': incomeExpenseFrequencyMapping[expense.frequency],
263
- '@UniqueID': `${uuidv4()}--${assetId}`,
266
+ '@Amount': (0, round_decimal_1.roundDecimal)(expense.amount * owner.percent),
267
+ '@Category': enum_mappings_1.livingExpenseMapping[expense.type],
268
+ '@Frequency': enum_mappings_1.incomeExpenseFrequencyMapping[expense.frequency],
269
+ '@UniqueID': `${(0, uuid_1.v4)()}--${assetId}`,
264
270
  PercentResponsible: {
265
271
  Owner: [
266
272
  {
@@ -275,50 +281,54 @@ export function generateLivingExpenses(percentOwned, assetId, propertyExpenses)
275
281
  });
276
282
  return livingExpenses;
277
283
  }
284
+ exports.generateLivingExpenses = generateLivingExpenses;
278
285
  /**
279
286
  * Creates PropertyExpense array on RealEstateAsset from the same array on the event.
280
287
  *
281
288
  * @param propertyExpenses
282
289
  */
283
- export function generatePropertyExpenses(propertyExpenses) {
290
+ function generatePropertyExpenses(propertyExpenses) {
284
291
  return propertyExpenses
285
292
  .filter((expense) => expense.amount !== undefined)
286
293
  .map((expense) => {
287
294
  normalizeAmounts(expense);
288
295
  return {
289
296
  '@Amount': expense.amount,
290
- '@Category': propertyExpenseCategoryMapping[expense.type],
291
- '@Frequency': incomeExpenseFrequencyMapping[expense.frequency],
297
+ '@Category': enum_mappings_1.propertyExpenseCategoryMapping[expense.type],
298
+ '@Frequency': enum_mappings_1.incomeExpenseFrequencyMapping[expense.frequency],
292
299
  };
293
300
  });
294
301
  }
302
+ exports.generatePropertyExpenses = generatePropertyExpenses;
295
303
  /**
296
304
  * Determines the occupancy based on the list of property expense types available.
297
305
  *
298
306
  * @param propertyExpenses
299
307
  */
300
- export function determineOccupancy(propertyExpenses) {
308
+ function determineOccupancy(propertyExpenses) {
301
309
  const propertyExpenseCategoryList = propertyExpenses.map((expense) => expense.type);
302
- if (propertyExpenseCategoryList.includes(PropertyExpenseType.InvestmentPropertyRunningCosts)) {
303
- return OccupancyList.NonOwner;
310
+ if (propertyExpenseCategoryList.includes(public_asset_1.PropertyExpenseType.InvestmentPropertyRunningCosts)) {
311
+ return lixi_internal_request_1.OccupancyList.NonOwner;
304
312
  }
305
- else if (propertyExpenseCategoryList.includes(PropertyExpenseType.PrimaryResidenceRunningCosts && PropertyExpenseType.SecondaryResidenceRunningCosts)) {
306
- return OccupancyList.OwnerSecondary;
313
+ else if (propertyExpenseCategoryList.includes(public_asset_1.PropertyExpenseType.PrimaryResidenceRunningCosts && public_asset_1.PropertyExpenseType.SecondaryResidenceRunningCosts)) {
314
+ return lixi_internal_request_1.OccupancyList.OwnerSecondary;
307
315
  }
308
- else if (propertyExpenseCategoryList.some((item) => item !== PropertyExpenseType.SecondaryResidenceRunningCosts &&
309
- item === PropertyExpenseType.PrimaryResidenceRunningCosts)) {
310
- return OccupancyList.OwnerPrimary;
316
+ else if (propertyExpenseCategoryList.some((item) => item !== public_asset_1.PropertyExpenseType.SecondaryResidenceRunningCosts &&
317
+ item === public_asset_1.PropertyExpenseType.PrimaryResidenceRunningCosts)) {
318
+ return lixi_internal_request_1.OccupancyList.OwnerPrimary;
311
319
  }
312
320
  }
321
+ exports.determineOccupancy = determineOccupancy;
313
322
  /**
314
323
  * Calculates the correct amount and frequency.
315
324
  *
316
325
  * @param expense
317
326
  */
318
- export function normalizeAmounts(expense) {
319
- if (expense.frequency === Frequency.Quarterly) {
320
- expense.frequency = Frequency.Yearly;
327
+ function normalizeAmounts(expense) {
328
+ if (expense.frequency === public_expense_1.Frequency.Quarterly) {
329
+ expense.frequency = public_expense_1.Frequency.Yearly;
321
330
  expense.amount *= 4;
322
331
  }
323
332
  return expense;
324
333
  }
334
+ exports.normalizeAmounts = normalizeAmounts;
@@ -1,24 +1,27 @@
1
- import { paths } from '@lendi/integrations-protocol/lib/utils/application-paths';
2
- import { get, set, sumBy } from 'lodash';
3
- import { frequencyMapping, livingExpenseMapping } from '../types/enum-mappings/';
4
- import { ExpenseType, Frequency } from '../types/events/public-expense';
5
- export const otherCommitmentExpenseTypes = [
6
- ExpenseType.Board,
7
- ExpenseType.ChildAndSpousalMaintenance,
8
- ExpenseType.Rent,
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLivingExpenseEstimate = exports.isOtherCommitment = exports.normaliseExpenseAmount = exports.transformExpense = exports.transformExpenses = exports.otherCommitmentExpenseTypes = void 0;
4
+ const application_paths_1 = require("@lendi/integrations-protocol/lib/utils/application-paths");
5
+ const lodash_1 = require("lodash");
6
+ const enum_mappings_1 = require("../types/enum-mappings/");
7
+ const public_expense_1 = require("../types/events/public-expense");
8
+ exports.otherCommitmentExpenseTypes = [
9
+ public_expense_1.ExpenseType.Board,
10
+ public_expense_1.ExpenseType.ChildAndSpousalMaintenance,
11
+ public_expense_1.ExpenseType.Rent,
9
12
  ];
10
13
  const propertyExpenseCategories = [
11
- ExpenseType.InvestmentPropertyRunningCosts,
12
- ExpenseType.BodyCorporateFeesStrataFeesAndLandTax,
13
- ExpenseType.SecondaryResidenceRunningCosts,
14
- ExpenseType.PrimaryResidenceRunningCosts,
14
+ public_expense_1.ExpenseType.InvestmentPropertyRunningCosts,
15
+ public_expense_1.ExpenseType.BodyCorporateFeesStrataFeesAndLandTax,
16
+ public_expense_1.ExpenseType.SecondaryResidenceRunningCosts,
17
+ public_expense_1.ExpenseType.PrimaryResidenceRunningCosts,
15
18
  ];
16
19
  /**
17
20
  * @description Transforms expense items on the application from the event.
18
21
  * @returns {PartialApplication} A PartialApplication returned by transforming the expense event.
19
22
  * @param expense
20
23
  */
21
- export function transformExpenses(expense) {
24
+ function transformExpenses(expense) {
22
25
  const partialApplication = {};
23
26
  const { applicantId, applicationId, expenses = [], id } = expense;
24
27
  if (expenses.every((expense) => expense.amount === undefined || expense.amount === null)) {
@@ -29,8 +32,8 @@ export function transformExpenses(expense) {
29
32
  const livingExpenseEstimate = filteredLivingExpensesWithAmount.find(isLivingExpenseEstimate);
30
33
  const otherCommitments = filteredLivingExpensesWithAmount.filter(isOtherCommitment);
31
34
  const expenseBreakdown = filteredLivingExpensesWithAmount.filter((item) => !(isOtherCommitment(item) || isLivingExpenseEstimate(item)));
32
- const livingExpenseEstimateExists = get(livingExpenseEstimate || {}, 'amount', 0) > 0;
33
- const expenseBreakdownAmountSum = sumBy(expenseBreakdown, 'amount');
35
+ const livingExpenseEstimateExists = (0, lodash_1.get)(livingExpenseEstimate || {}, 'amount', 0) > 0;
36
+ const expenseBreakdownAmountSum = (0, lodash_1.sumBy)(expenseBreakdown, 'amount');
34
37
  let lixiLivingExpenses;
35
38
  // unless all individual expenses have a value of 0 and a living estimate exists, transform them without question.
36
39
  if (expenseBreakdownAmountSum === 0 && livingExpenseEstimateExists) {
@@ -41,15 +44,16 @@ export function transformExpenses(expense) {
41
44
  lixiLivingExpenses = expenseBreakdown.map((expense, index) => transformExpense(expense, applicantId, index, id));
42
45
  }
43
46
  const lixiCommitmentExpenses = otherCommitments.map((expense, index) => transformExpense(expense, applicantId, index, id));
44
- set(partialApplication, paths.ApplicationId, applicationId);
45
- set(partialApplication, `${paths.Household}.@UniqueID`, `${applicationId}-household`);
46
- set(partialApplication, `${paths.PersonApplicant}.@UniqueID`, applicantId);
47
- set(partialApplication, paths.OtherCommitments, lixiCommitmentExpenses);
47
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.ApplicationId, applicationId);
48
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.Household}.@UniqueID`, `${applicationId}-household`);
49
+ (0, lodash_1.set)(partialApplication, `${application_paths_1.paths.PersonApplicant}.@UniqueID`, applicantId);
50
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.OtherCommitments, lixiCommitmentExpenses);
48
51
  if (lixiLivingExpenses.length > 0) {
49
- set(partialApplication, paths.LivingExpenses, lixiLivingExpenses);
52
+ (0, lodash_1.set)(partialApplication, application_paths_1.paths.LivingExpenses, lixiLivingExpenses);
50
53
  }
51
54
  return partialApplication;
52
55
  }
56
+ exports.transformExpenses = transformExpenses;
53
57
  /**
54
58
  * transforms the living expense from the expense array on the event.
55
59
  *
@@ -62,13 +66,13 @@ export function transformExpenses(expense) {
62
66
  * @param index
63
67
  * @param id
64
68
  */
65
- export function transformExpense(expense, applicantId, index, id) {
69
+ function transformExpense(expense, applicantId, index, id) {
66
70
  return {
67
71
  '@Amount': expense.amount,
68
- '@Category': livingExpenseMapping[expense.type],
72
+ '@Category': enum_mappings_1.livingExpenseMapping[expense.type],
69
73
  '@Description': expense.type,
70
74
  '@UniqueID': isOtherCommitment(expense) ? `${id}-commitment-${index}` : `${id}-living-expense-${index}`,
71
- '@Frequency': frequencyMapping[expense.frequency],
75
+ '@Frequency': enum_mappings_1.frequencyMapping[expense.frequency],
72
76
  PercentResponsible: {
73
77
  Owner: [
74
78
  {
@@ -79,15 +83,16 @@ export function transformExpense(expense, applicantId, index, id) {
79
83
  },
80
84
  };
81
85
  }
86
+ exports.transformExpense = transformExpense;
82
87
  /**
83
88
  * @description Normalises expense by amount to 0 if not provided and scales quarterly spending up to yearly.
84
89
  * @param {Expense} expense An expense
85
90
  * @returns {Expense} An normalised expense.
86
91
  */
87
- export function normaliseExpenseAmount(expense) {
88
- const { amount, frequency = Frequency.Yearly, type: expenseType } = expense;
89
- if (frequency === Frequency.Quarterly) {
90
- expense.frequency = Frequency.Yearly;
92
+ function normaliseExpenseAmount(expense) {
93
+ const { amount, frequency = public_expense_1.Frequency.Yearly, type: expenseType } = expense;
94
+ if (frequency === public_expense_1.Frequency.Quarterly) {
95
+ expense.frequency = public_expense_1.Frequency.Yearly;
91
96
  expense.amount *= 4;
92
97
  }
93
98
  if (!amount && !propertyExpenseCategories.includes(expenseType)) {
@@ -95,19 +100,22 @@ export function normaliseExpenseAmount(expense) {
95
100
  }
96
101
  return expense;
97
102
  }
103
+ exports.normaliseExpenseAmount = normaliseExpenseAmount;
98
104
  /**
99
105
  * @description Verify if expense is an OtherCommitment.
100
106
  * @param {Expense} expense Any Expense item.
101
107
  * @returns {boolean} Returns true if an expense type is one of other commitment expenses.
102
108
  */
103
- export function isOtherCommitment(expense) {
104
- return otherCommitmentExpenseTypes.includes(expense.type);
109
+ function isOtherCommitment(expense) {
110
+ return exports.otherCommitmentExpenseTypes.includes(expense.type);
105
111
  }
112
+ exports.isOtherCommitment = isOtherCommitment;
106
113
  /**
107
114
  * @description Check if expense type is LivingExpenseEstimate.
108
115
  * @param {Expense} expense An Expense item.
109
116
  * @returns {boolean} Returns true if an expense type is LivingExpenseEstimate
110
117
  */
111
- export function isLivingExpenseEstimate(expense) {
112
- return expense.type === ExpenseType.LivingExpensesEstimate;
118
+ function isLivingExpenseEstimate(expense) {
119
+ return expense.type === public_expense_1.ExpenseType.LivingExpensesEstimate;
113
120
  }
121
+ exports.isLivingExpenseEstimate = isLivingExpenseEstimate;