-
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.
https://eaflood.atlassian.net/browse/WATER-4649 We need to replace the import service logic to import a licence from NALD. The current import service iterates all the companies (known as parties in the import.NALD_PARTIES table) and updates CRM_V2 tables. This change will use the nald licence id and region to update the company data. This means going forwards we will only import company when the licence is imported. We will insert this imported data in the relevant public views. This change focuses on the company data and not address or contacts tables which will be done after this work.
- Loading branch information
1 parent
a386f84
commit ef2f160
Showing
3 changed files
with
119 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches the company data from the import.NALD_PARTIES table for the licence ref | ||
* @module FetchCompanyService | ||
*/ | ||
|
||
const { db } = require('../../../../db/db.js') | ||
|
||
/** | ||
* Fetches the licence data from the import.NALD_PARTIES table for the licence ref | ||
* | ||
* @param {string} regionCode - The NALD region code | ||
* @param {string} licenceId - The NALD licence ID | ||
* | ||
* @returns {Promise<ImportLegacyLicenceType>} | ||
*/ | ||
async function go (regionCode, licenceId) { | ||
const query = _query() | ||
|
||
const { rows: [row] } = await db.raw(query, [regionCode, licenceId]) | ||
|
||
return row | ||
} | ||
|
||
function _query () { | ||
return ` | ||
SELECT | ||
CASE np."SALUTATION" | ||
WHEN 'null' THEN NULL | ||
ELSE np."SALUTATION" | ||
END AS salutation, | ||
CASE np."INITIALS" | ||
WHEN 'null' THEN NULL | ||
ELSE np."INITIALS" | ||
END AS initials, | ||
CASE np."FORENAME" | ||
WHEN 'null' THEN NULL | ||
ELSE np."FORENAME" | ||
END AS firstName, | ||
CASE np."NAME" | ||
WHEN 'null' THEN NULL | ||
ELSE np."NAME" | ||
END AS lastName, | ||
CASE np."APAR_TYPE" | ||
WHEN 'PER' THEN 'person' | ||
ELSE 'organisation' | ||
END AS type, | ||
TRIM(BOTH ' ' FROM ( | ||
CASE | ||
WHEN np."FORENAME" = 'null' AND np."INITIALS" = 'null' THEN np."NAME" | ||
ELSE CONCAT_WS(' ', | ||
CASE | ||
WHEN np."SALUTATION" = 'null' THEN NULL | ||
ELSE np."SALUTATION" | ||
END, | ||
CASE | ||
WHEN np."FORENAME" = 'null' THEN np."INITIALS" | ||
ELSE np."FORENAME" | ||
END, | ||
CASE | ||
WHEN np."NAME" = 'null' THEN NULL | ||
ELSE np."NAME" | ||
END | ||
) | ||
END | ||
)) AS fullName, | ||
CONCAT_WS(':', np."FGAC_REGION_CODE", np."ID") AS external_id | ||
FROM import."NALD_PARTIES" np | ||
WHERE np."FGAC_REGION_CODE" = ? AND np."ID" = ?; | ||
` | ||
} | ||
|
||
module.exports = { | ||
go | ||
} | ||
|
||
/** | ||
* @typedef {object} ImportLegacyLicenceType | ||
* | ||
* @property {string|null} salutation - The salutation of the person, or null if not applicable. | ||
* @property {string|null} firstName - The first name of the person, or null if not applicable. | ||
* @property {string|null} lastName - The last name of the person, or null if not applicable. | ||
* @property {string} effective_end_date - Indicates whether the entry is a 'person' or an 'organisation'. | ||
* @property {string|null} fullName - The full name, concatenated from salutation, forename/initials, and name. | ||
* @property {string} external_id - The external ID, formatted as 'FGAC_REGION_CODE: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
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,28 @@ | ||
'use strict' | ||
|
||
/** | ||
* Transforms NALD company data into a valid object that matches the WRLS structure | ||
* @module ImportLegacyTransformCompanyService | ||
*/ | ||
|
||
const FetchCompanyService = require('./fetch-company.service.js') | ||
|
||
/** | ||
* Transforms NALD company data into a validated object that matches the WRLS structure | ||
* | ||
* @param {string} regionCode - The NALD region code | ||
* @param {string} licenceId - The NALD licence ID | ||
* | ||
* @returns {Promise<object>} an object representing a valid WRLS licence | ||
*/ | ||
async function go (regionCode, licenceId) { | ||
const naldCompanyData = await FetchCompanyService.go(regionCode, licenceId) | ||
|
||
return { | ||
company: naldCompanyData | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |