Skip to content

Commit

Permalink
Add createdAt to Version history modifiers (#1293)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4566

> Part of the work to display NALD mod log records as history in WRLS

We recently added a new `history()` modifier to the charge, licence, and return version models that allows us to pull through the mod log and, in some cases, user details when querying for a record. We then call `$` instance methods to determine who created a record or what the reason was.

We're using it in [Build new licence history page](#1182), but that change has highlighted that to make `$createdAt()` work, we have to ensure we include `createdAt` in the parent query's `select()`.

This should be dealt with in the `history()` modifier. This change makes it so!
  • Loading branch information
Cruikshanks authored Aug 29, 2024
1 parent be2030d commit 3784fa9
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/models/charge-version.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,26 @@ class ChargeVersionModel extends BaseModel {
/**
* Modifiers allow us to reuse logic in queries, eg. select the charge version, note, and/or all mod log records:
*
* ```javascript
* return ChargeVersionModel.query()
* .findById(chargeVersionId)
* .modify('history')
* ```
*
* See {@link https://vincit.github.io/objection.js/recipes/modifiers.html | Modifiers} for more details
*
* @returns {object}
*/
static get modifiers () {
return {
// history modifier fetches all the related records needed to determine history properties, for example, created
// at, and created by from the record, plus its note, change reason, and NALD mod logs (where they exist)
history (query) {
query
.select(['createdBy'])
.select([
'createdAt',
'createdBy'
])
.withGraphFetched('modLogs')
.modifyGraph('modLogs', (builder) => {
builder.select([
Expand Down
5 changes: 5 additions & 0 deletions app/models/licence-version.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,23 @@ class LicenceVersionModel extends BaseModel {
/**
* Modifiers allow us to reuse logic in queries, eg. select the licence version and all mod log records:
*
* ```javascript
* return LicenceVersionModel.query()
* .findById(licenceVersionId)
* .modify('history')
* ```
*
* See {@link https://vincit.github.io/objection.js/recipes/modifiers.html | Modifiers} for more details
*
* @returns {object}
*/
static get modifiers () {
return {
// history modifier fetches all the related records needed to determine history properties, for example, created
// at, created by, and notes from the record and its NALD mod logs (where they exist)
history (query) {
query
.select(['createdAt'])
.withGraphFetched('modLogs')
.modifyGraph('modLogs', (builder) => {
builder.select([
Expand Down
6 changes: 6 additions & 0 deletions app/models/return-version.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class ReturnVersionModel extends BaseModel {
// at, created by, and notes from the record, its user, and its NALD mod logs (where they exist)
history (query) {
query
.select([
'createdAt',
'createdBy',
'notes',
'reason'
])
.withGraphFetched('modLogs')
.modifyGraph('modLogs', (builder) => {
builder.select([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('Return Requirements - Fetch Return Version service', () => {

expect(result).to.equal({
createdAt: returnVersion.createdAt,
createdBy: user.id,
id: returnVersion.id,
multipleUpload: false,
notes: null,
Expand Down

0 comments on commit 3784fa9

Please sign in to comment.