-
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.
Fix for view licence abstraction conditions V2 (#853)
https://eaflood.atlassian.net/browse/WATER-4332 > @Cruikshanks stab at the problem! As part of the testing for the new view licence summary page, QA pointed out that the more complicated licences did not match the legacy system. We would see different results for the 'Abstraction conditions' section. The first thing we'd overlooked was the need to ensure we were only looking at the 'current' licence version. After more investigation, we then discovered that the permit licence JSON blob the legacy code is using is replicated in tables that already exist in the `water` schema. We found we could access the same data using these tables to get a matching result to the legacy view. This change adds a new service to fetch the abstraction data we need and updates the presenter to generate the distinct list of conditions to display.
- Loading branch information
1 parent
8117375
commit 1a0d96a
Showing
12 changed files
with
561 additions
and
446 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
68 changes: 68 additions & 0 deletions
68
app/services/licences/fetch-licence-abstraction-conditions.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,68 @@ | ||
'use strict' | ||
|
||
/** | ||
* Fetches a licence's abstraction conditions needed for the summary tab on the view '/licences/{id}` page | ||
* @module FetchLicenceAbstractionConditionsService | ||
*/ | ||
|
||
const LicenceVersionPurposeModel = require('../../models/licence-version-purpose.model.js') | ||
|
||
/** | ||
* Fetches a licence's abstraction conditions needed for the summary tab on the view '/licences/{id}` page | ||
* | ||
* Each time a licence is changed in the upstream NALD system a new 'version is generated, the latest of which becomes | ||
* the 'current' version. | ||
* | ||
* Linked to each version could be multiple purposes for the abstraction, for example, spray irrigation and mineral | ||
* washing. | ||
* | ||
* Then each purpose might have one or more conditions attached to it. Where things get complex is the same condition | ||
* can be attached to more than one purpose and we're trying to show a distinct list of abstraction conditions for the | ||
* licence. But we still need a count of them all! | ||
* | ||
* This service is able to determine the purposes for the current licence version and their conditions then extract the | ||
* display title for each one. The total number of results gives us the abstraction condition count we need. As there | ||
* may be duplicates in the titles we process the results to determine the distinct list needed. Finally, just in case | ||
* we also provide a distinct list of the purpose IDs :-) | ||
* | ||
* @param {string} licenceVersionId - The UUID for the 'current' licence version record of the licence being viewed | ||
* | ||
* @returns {Promise<Object>} An object containing the processed results for all the abstraction conditions for the | ||
* current version of the licence. It contains an array of distinct condition titles, the purpose IDs they were linked | ||
* to and the total count of conditions for the licence version. | ||
*/ | ||
async function go (licenceVersionId) { | ||
const results = await LicenceVersionPurposeModel.query() | ||
.distinct([ | ||
'licenceVersionPurposes.purposeId', | ||
'licenceVersionPurposeConditionTypes.displayTitle' | ||
]) | ||
.innerJoin('licenceVersionPurposeConditions', 'licenceVersionPurposes.id', 'licenceVersionPurposeConditions.licenceVersionPurposeId') | ||
.innerJoin('licenceVersionPurposeConditionTypes', 'licenceVersionPurposeConditions.licenceVersionPurposeConditionTypeId', 'licenceVersionPurposeConditionTypes.id') | ||
.where('licenceVersionPurposes.licenceVersionId', licenceVersionId) | ||
.orderBy([ | ||
{ column: 'licenceVersionPurposeConditionTypes.displayTitle', order: 'asc' } | ||
]) | ||
|
||
return _processResults(results) | ||
} | ||
|
||
function _processResults (results) { | ||
const allDisplayTitles = [] | ||
const allPurposeIds = [] | ||
|
||
results.forEach((result) => { | ||
allDisplayTitles.push(result.displayTitle) | ||
allPurposeIds.push(result.purposeId) | ||
}) | ||
|
||
return { | ||
conditions: [...new Set(allDisplayTitles)], | ||
purposeIds: [...new Set(allPurposeIds)], | ||
numberOfConditions: results.length | ||
} | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
65 changes: 0 additions & 65 deletions
65
app/services/licences/fetch-licence-version-purpose-condition.service.js
This file was deleted.
Oops, something went wrong.
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
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.