-
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.
Refactor the import legacy persist logic (#1387)
* Refactor the import legacy persist logic We have recently introduced functionality to import data from NALD using for a licence and companies for that particular licence. This change will break out the persist functionality into logical groups of functionality. --------- Co-authored-by: Alan Cruikshanks <[email protected]>
- Loading branch information
1 parent
7c863e3
commit 57f4e3f
Showing
12 changed files
with
1,184 additions
and
776 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
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,38 @@ | ||
'use strict' | ||
|
||
/** | ||
* Creates or updates an imported licence and its child entities that have been transformed and validated | ||
* @module PersistImportService | ||
*/ | ||
|
||
const PersistLicenceService = require('./persist/persist-licence.service.js') | ||
const PersistLicenceVersionsService = require('./persist/persist-licence-versions.service.js') | ||
const PersistCompanyService = require('./persist/persist-company.service.js') | ||
const LicenceModel = require('../../models/licence.model.js') | ||
const { timestampForPostgres } = require('../../lib/general.lib.js') | ||
|
||
/** | ||
* Creates or updates an imported licence and its child entities that have been transformed and validated | ||
* | ||
* @param {object} transformedLicence - An object representing a valid WRLS licence | ||
* @param {object[]} transformedCompanies - an array of companies representing a WRLS company | ||
* | ||
* @returns {Promise<object>} | ||
*/ | ||
async function go (transformedLicence, transformedCompanies) { | ||
return LicenceModel.transaction(async (trx) => { | ||
const updatedAt = timestampForPostgres() | ||
|
||
const id = await PersistLicenceService.go(trx, updatedAt, transformedLicence) | ||
|
||
await PersistLicenceVersionsService.go(trx, updatedAt, transformedLicence, id) | ||
|
||
await PersistCompanyService.go(trx, updatedAt, transformedCompanies) | ||
|
||
return id | ||
}) | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.