Skip to content

Commit

Permalink
Persist match and allocate issues and status (#772)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4378

During the refinement of future two-part tariff tickets, it was noted that the status of a licence could be changed by the user from a 'review' status to a 'ready' status. Before this was noted we were working out the licence status based on the issues the licence has with its returns and charge elements. This is done on every page where the licence status is being shown. Now that we know a status can be overwritten regardless of its issues, we now need to persist the licence status during the first time the engine works it out and show the persisted status instead of working it out each time. This will allow users to manually change the status.

The same thing applies to the charge elements. The status of the element is determined by the issues on it. This status at the moment is worked out every time it is displayed on a page. We have since learnt through refinement that a user can allocate volumes on the element and this will change the status from 'review' to 'ready'. This is regardless of the issues that remain on a charge element. So with this new information, it has made it clear that we now need to persist the initial status of the charge element to allow this to be overwritten when needed.

This opened up a lot of discussions about how we could refactor the review tables to work more effectively with how the two-part tariff engine works now. When we first built the tables we did so with the knowledge we had at the time. Now that we have worked on more tickets and started building actual pages we realised we could persist the data better.

TLDR: Review tables updated to add status and issues
  • Loading branch information
Jozzey authored Mar 11, 2024
1 parent 9f398e4 commit 5dde8aa
Show file tree
Hide file tree
Showing 73 changed files with 1,798 additions and 2,110 deletions.
6 changes: 3 additions & 3 deletions app/models/licence.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ class LicenceModel extends BaseModel {
to: 'regions.id'
}
},
reviewResults: {
reviewLicences: {
relation: Model.HasManyRelation,
modelClass: 'review-result.model',
modelClass: 'review-licence.model',
join: {
from: 'licences.id',
to: 'reviewResults.licenceId'
to: 'reviewLicences.licenceId'
}
},
workflows: {
Expand Down
31 changes: 0 additions & 31 deletions app/models/review-charge-element-result.model.js

This file was deleted.

16 changes: 16 additions & 0 deletions app/models/review-charge-element-return.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict'

/**
* Model for review_charge_elements_returns
* @module ReviewChargeElementReturnModel
*/

const BaseModel = require('./base.model.js')

class ReviewChargeElementReturnModel extends BaseModel {
static get tableName () {
return 'reviewChargeElementsReturns'
}
}

module.exports = ReviewChargeElementReturnModel
43 changes: 43 additions & 0 deletions app/models/review-charge-element.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
'use strict'

/**
* Model for review_charge_elements
* @module ReviewChargeElementModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class ReviewChargeElementModel extends BaseModel {
static get tableName () {
return 'reviewChargeElements'
}

static get relationMappings () {
return {
reviewChargeReference: {
relation: Model.BelongsToOneRelation,
modelClass: 'review-charge-reference.model',
join: {
from: 'reviewChargeElements.reviewChargeReferenceId',
to: 'reviewChargeReferences.id'
}
},
reviewReturns: {
relation: Model.ManyToManyRelation,
modelClass: 'review-return.model',
join: {
from: 'reviewChargeElements.id',
through: {
from: 'reviewChargeElementsReturns.reviewChargeElementId',
to: 'reviewChargeElementsReturns.reviewReturnId'
},
to: 'reviewReturns.id'
}
}
}
}
}

module.exports = ReviewChargeElementModel
39 changes: 39 additions & 0 deletions app/models/review-charge-reference.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

/**
* Model for review_charge_references
* @module ReviewChargeReferenceModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class ReviewChargeReferenceModel extends BaseModel {
static get tableName () {
return 'reviewChargeReferences'
}

static get relationMappings () {
return {
reviewChargeVersion: {
relation: Model.BelongsToOneRelation,
modelClass: 'review-charge-version.model',
join: {
from: 'reviewChargeReferences.reviewChargeVersionId',
to: 'reviewChargeVersions.id'
}
},
reviewChargeElements: {
relation: Model.HasManyRelation,
modelClass: 'review-charge-element.model',
join: {
from: 'reviewChargeReferences.id',
to: 'reviewChargeElements.reviewChargeReferenceId'
}
}
}
}
}

module.exports = ReviewChargeReferenceModel
39 changes: 39 additions & 0 deletions app/models/review-charge-version.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict'

/**
* Model for review_charge_versions
* @module ReviewChargeVersionModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class ReviewChargeVersionModel extends BaseModel {
static get tableName () {
return 'reviewChargeVersions'
}

static get relationMappings () {
return {
reviewLicence: {
relation: Model.BelongsToOneRelation,
modelClass: 'review-licence.model',
join: {
from: 'reviewChargeVersions.reviewLicenceId',
to: 'reviewLicences.id'
}
},
reviewChargeReferences: {
relation: Model.HasManyRelation,
modelClass: 'review-charge-reference.model',
join: {
from: 'reviewChargeVersions.id',
to: 'reviewChargeReferences.reviewChargeVersionId'
}
}
}
}
}

module.exports = ReviewChargeVersionModel
47 changes: 47 additions & 0 deletions app/models/review-licence.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict'

/**
* Model for review_licences
* @module ReviewLicenceModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class ReviewLicenceModel extends BaseModel {
static get tableName () {
return 'reviewLicences'
}

static get relationMappings () {
return {
licence: {
relation: Model.BelongsToOneRelation,
modelClass: 'licence.model',
join: {
from: 'reviewLicences.licenceId',
to: 'licences.id'
}
},
reviewChargeVersions: {
relation: Model.HasManyRelation,
modelClass: 'review-charge-version.model',
join: {
from: 'reviewLicences.id',
to: 'reviewChargeVersions.reviewLicenceId'
}
},
reviewReturns: {
relation: Model.HasManyRelation,
modelClass: 'review-return.model',
join: {
from: 'reviewLicences.id',
to: 'reviewReturns.reviewLicenceId'
}
}
}
}
}

module.exports = ReviewLicenceModel
47 changes: 0 additions & 47 deletions app/models/review-result.model.js

This file was deleted.

38 changes: 0 additions & 38 deletions app/models/review-return-result.model.js

This file was deleted.

50 changes: 50 additions & 0 deletions app/models/review-return.model.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
'use strict'

/**
* Model for review_returns
* @module ReviewReturnModel
*/

const { Model } = require('objection')

const BaseModel = require('./base.model.js')

class ReviewReturnModel extends BaseModel {
static get tableName () {
return 'reviewReturns'
}

// Defining which fields contain json allows us to insert an object without needing to stringify it first
static get jsonAttributes () {
return [
'purposes'
]
}

static get relationMappings () {
return {
reviewLicence: {
relation: Model.BelongsToOneRelation,
modelClass: 'review-licence.model',
join: {
from: 'reviewReturns.reviewLicenceId',
to: 'reviewLicences.id'
}
},
reviewChargeElements: {
relation: Model.ManyToManyRelation,
modelClass: 'review-charge-element.model',
join: {
from: 'reviewReturns.id',
through: {
from: 'reviewChargeElementsReturns.reviewReturnId',
to: 'reviewChargeElementsReturns.reviewChargeElementId'
},
to: 'reviewChargeElements.id'
}
}
}
}
}

module.exports = ReviewReturnModel
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function _prepareLicences (licences) {
}

preparedLicences.push({
id: licence.id,
id: licence.licenceId,
licenceRef: licence.licenceRef,
licenceHolder: licence.licenceHolder,
status: licence.status,
Expand Down
Loading

0 comments on commit 5dde8aa

Please sign in to comment.