Skip to content

Commit

Permalink
Refactor the import legacy persist logic (#1387)
Browse files Browse the repository at this point in the history
* 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
jonathangoulding and Cruikshanks authored Oct 11, 2024
1 parent 7c863e3 commit 57f4e3f
Show file tree
Hide file tree
Showing 12 changed files with 1,184 additions and 776 deletions.
6 changes: 3 additions & 3 deletions app/services/import/legacy/process-licence.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

const LicenceStructureValidator = require('../../../validators/import/licence-structure.validator.js')
const PersistLicenceService = require('../persist-licence.service.js')
const PersistImportService = require('../persist-import.service.js')
const ProcessLicenceReturnLogsService = require('../../jobs/return-logs/process-licence-return-logs.service.js')
const TransformAddressesService = require('./transform-addresses.service.js')
const TransformCompanyAddressesService = require('./transform-company-addresses.service.js')
const TransformCompaniesService = require('./transform-companies.service.js')
const TransformCompanyAddressesService = require('./transform-company-addresses.service.js')
const TransformContactsService = require('./transform-contacts.service.js')
const TransformLicenceService = require('./transform-licence.service.js')
const TransformLicenceVersionPurposeConditionsService = require('./transform-licence-version-purpose-conditions.service.js')
Expand Down Expand Up @@ -50,7 +50,7 @@ async function go (licenceRef) {
LicenceStructureValidator.go(transformedLicence)

// Either insert or update the licence in WRLS
const licenceId = await PersistLicenceService.go(transformedLicence, transformedCompanies)
const licenceId = await PersistImportService.go(transformedLicence, transformedCompanies)

if (wrlsLicenceId) {
await ProcessLicenceReturnLogsService.go(wrlsLicenceId)
Expand Down
38 changes: 38 additions & 0 deletions app/services/import/persist-import.service.js
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
}
257 changes: 0 additions & 257 deletions app/services/import/persist-licence.service.js

This file was deleted.

Loading

0 comments on commit 57f4e3f

Please sign in to comment.