-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into rename-rtn-req-setup-folder-method
- Loading branch information
Showing
21 changed files
with
873 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/presenters/import/legacy/licence-document-role.presenter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict' | ||
|
||
/** | ||
* Maps legacy NALD licence data to the WRLS licence document role format | ||
* @module LicenceDocumentRolePresenter | ||
*/ | ||
|
||
/** | ||
* Maps legacy NALD licence data to the WRLS licence document role format | ||
* | ||
* @param {ImportLegacyLicenceDocumentRoleType} licenceDocumentRole - the legacy NALD licence | ||
* @param {string} licenceRef - the licence ref for the licence document | ||
* | ||
* @returns {object} the NALD licence data transformed into the WRLS licence document role format | ||
* ready for validation and persisting | ||
*/ | ||
function go (licenceDocumentRole, licenceRef) { | ||
return { | ||
addressId: licenceDocumentRole.address_id, | ||
companyId: licenceDocumentRole.company_id, | ||
contactId: licenceDocumentRole.contact_id, | ||
documentId: licenceRef, | ||
endDate: licenceDocumentRole.end_date, | ||
licenceRoleId: licenceDocumentRole.licence_role_id, | ||
startDate: licenceDocumentRole.start_date | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/services/import/legacy/fetch-licence-document-roles.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches the licence document roles data from the import data | ||
* @module FetchLicenceDocumentRolesService | ||
*/ | ||
|
||
const { db } = require('../../../../db/db.js') | ||
|
||
/** | ||
* Fetches the licence document roles data from the import data | ||
* | ||
* This will come from the licence versions and the licence roles. | ||
* | ||
* We are only interest in the returnsTo licence role from the import.NALD_LIC_ROLES | ||
* | ||
* @param {string} regionCode - The NALD region code | ||
* @param {string} licenceId - The NALD licence ID | ||
* | ||
* @returns {Promise<ImportLegacyLicenceDocumentRoleType[]>} | ||
*/ | ||
async function go (regionCode, licenceId) { | ||
const query = _query() | ||
|
||
const { rows } = await db.raw(query, [regionCode, licenceId]) | ||
|
||
return rows | ||
} | ||
|
||
function _query () { | ||
return ` | ||
SELECT | ||
lr.id as licence_role_id, | ||
TO_DATE(nlr."EFF_ST_DATE", 'DD/MM/YYY' ) as start_date, | ||
TO_DATE(NULLIF(nlr."EFF_END_DATE", 'null'), 'DD/MM/YYY' ) as end_date, | ||
concat_ws(':', nlr."FGAC_REGION_CODE", nlr."ACON_AADD_ID") as address_id, | ||
concat_ws(':', nlr."FGAC_REGION_CODE", nlr."ACON_APAR_ID") as company_id, | ||
( | ||
CASE | ||
WHEN np."APAR_TYPE" = 'ORG' | ||
THEN NULL | ||
ELSE concat_ws(':', nlr."FGAC_REGION_CODE", nlr."ACON_APAR_ID") | ||
END | ||
) as contact_id | ||
FROM import."NALD_LIC_ROLES" nlr | ||
INNER JOIN public.licence_roles lr | ||
ON lr.name = 'returnsTo' | ||
Inner JOIN import."NALD_PARTIES" np | ||
ON np."FGAC_REGION_CODE" = nlr."FGAC_REGION_CODE" | ||
AND np."ID" = nlr."ACON_APAR_ID" | ||
WHERE | ||
nlr."ALRT_CODE" = 'RT' | ||
AND nlr."FGAC_REGION_CODE" = ? | ||
AND nlr."AABL_ID" = ?; | ||
` | ||
} | ||
|
||
module.exports = { | ||
go | ||
} | ||
|
||
/** | ||
* Representation of a licence document fetched from the NALD data | ||
* @typedef {object} ImportLegacyLicenceDocumentRoleType | ||
* | ||
* @property { guid } licence_role_id - The licence role id from WRLS | ||
* @property { Date } start_date - EFF_ST_DATE | ||
* @property { Date } end_date - EFF_END_DATE | ||
* @property { string } address_id - used to link to the address (external id) | ||
* @property { string } company_id - used to link to the company (external id) | ||
* @property { string } contact_id - a person should have a contact id | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
app/services/import/legacy/transform-licence-document-roles.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
'use strict' | ||
|
||
/** | ||
* Transforms all NALD data into an object that matches the WRLS licence document role structure | ||
* @module ImportLegacyTransformLicenceDocumentRolesService | ||
*/ | ||
|
||
const FetchLicenceDocumentRolesService = require('./fetch-licence-document-roles.service.js') | ||
const ImportLicenceDocumentRoleValidator = require('../../../validators/import/licence-document-role.validator.js') | ||
const LicenceDocumentRolePresenter = require('../../../presenters/import/legacy/licence-document-role.presenter.js') | ||
|
||
/** | ||
* Transforms all NALD data into an object that matches the WRLS licence document role structure | ||
* | ||
* NALD does not have a concept of a licence document or licence document role it is a legacy WRLS construct | ||
* | ||
* @param {string} regionCode - The NALD region code for the licence being imported | ||
* @param {string} naldLicenceId - The NALD ID for the licence being imported | ||
* @param {object} transformedLicence - An object representing a valid WRLS licence | ||
* @param licenceRef | ||
* | ||
*/ | ||
async function go (regionCode, naldLicenceId, transformedLicence, licenceRef) { | ||
const naldLicenceDocumentRoles = await FetchLicenceDocumentRolesService.go(regionCode, naldLicenceId) | ||
|
||
for (const licenceDocumentRole of naldLicenceDocumentRoles) { | ||
const transformedLicenceDocumentRole = LicenceDocumentRolePresenter.go(licenceDocumentRole, licenceRef) | ||
|
||
ImportLicenceDocumentRoleValidator.go(transformedLicenceDocumentRole) | ||
|
||
transformedLicence.licenceDocument.licenceDocumentRoles.push(transformedLicenceDocumentRole) | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.