-
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.
Add history attributes to LicenceVersionModel (#1271)
https://eaflood.atlassian.net/browse/WATER-4560 > Part of the work to display NALD mod log records as history in WRLS So, we are now importing mod logs from NALD and have added a model linked to charge, licence and return version models to allow us to retrieve them from the database. We are in the process of building [a new licence history page](#1182) and will need to create a view of the licence version in the future. Because of this, we believe adding a modifier and instance methods to the `LicenceVersionModel` that will handle fetching the mod logs and determining this information is valuable. This change updates the `LicenceVersionModel` with these properties. This is similar to the work we did in [Add history attributes to ReturnVersionModel](#1267).
- Loading branch information
1 parent
fd320a4
commit 197df43
Showing
4 changed files
with
403 additions
and
66 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 |
---|---|---|
|
@@ -56,7 +56,7 @@ class ReturnVersionModel extends BaseModel { | |
* log records: | ||
* | ||
* return ReturnVersionModel.query() | ||
* .findById(licenceId) | ||
* .findById(returnVersionId) | ||
* .modify('history') | ||
* | ||
* See {@link https://vincit.github.io/objection.js/recipes/modifiers.html | Modifiers} for more details | ||
|
@@ -92,7 +92,7 @@ class ReturnVersionModel extends BaseModel { | |
} | ||
|
||
/** | ||
* Determine which user created the 'source' record using history | ||
* Determine the created at date of the 'source' record using history | ||
* | ||
* > We recommend adding the `history` modifier to your query to support this determination | ||
* | ||
|
@@ -104,29 +104,22 @@ class ReturnVersionModel extends BaseModel { | |
* Unfortunately, NALD doesn't enforce it's creation. But as the NALD version records don't capture the who and when, | ||
* they are the best 'source' we have to determine this information for imported records. | ||
* | ||
* If a user record exists for this version then it was created in WRLS and it is the 'source'. It extracts the user | ||
* name, for example, `[email protected]`. | ||
* | ||
* If a user record doesn't exist, it falls back to attempting to extract the user ID from the first mod log record, | ||
* for example, `JSMITH`. If one exists it is the 'source'. | ||
* If there are mod logs for this record, it extracts the date from the first entry, for example, `2019-06-02`, and | ||
* returns it. Else, it falls back to using the return version's `createdAt` time stamp. | ||
* | ||
* If neither a user nor any mod logs exist it will return `null`. | ||
* > The NALD date takes priority, because all records will have a created at date. But in the case of imported | ||
* > records this will be when it was imported to WRLS, which can be some time after it was created in NALD. | ||
* | ||
* @returns {string} the user name of the user that created the 'source' record, else `null` if it cannot be | ||
* determined | ||
* @returns {Date} the date the 'source' record was created | ||
*/ | ||
$createdBy () { | ||
if (this.user) { | ||
return this.user.username | ||
} | ||
|
||
$createdAt () { | ||
const firstModLog = this._firstModLog() | ||
|
||
return firstModLog?.userId ?? null | ||
return firstModLog?.naldDate ?? this.createdAt | ||
} | ||
|
||
/** | ||
* Determine the created at date of the 'source' record using history | ||
* Determine which user created the 'source' record using history | ||
* | ||
* > We recommend adding the `history` modifier to your query to support this determination | ||
* | ||
|
@@ -138,18 +131,25 @@ class ReturnVersionModel extends BaseModel { | |
* Unfortunately, NALD doesn't enforce it's creation. But as the NALD version records don't capture the who and when, | ||
* they are the best 'source' we have to determine this information for imported records. | ||
* | ||
* If there are mod logs for this record, it extracts the date from the first entry, for example, `2019-06-02`, and | ||
* returns it. Else, it falls back to using the return version's `createdAt` time stamp. | ||
* If a user record exists for this version then it was created in WRLS and it is the 'source'. It extracts the user | ||
* name, for example, `[email protected]`. | ||
* | ||
* > The NALD date takes priority, because all records will have a created at date. But in the case of imported | ||
* > records this will be when it was imported to WRLS, which can be some time after it was created in NALD. | ||
* If a user record doesn't exist, it falls back to attempting to extract the user ID from the first mod log record, | ||
* for example, `JSMITH`. If one exists it is the 'source'. | ||
* | ||
* @returns {Date} the date the 'source' record was created | ||
* If neither a user nor any mod logs exist it will return `null`. | ||
* | ||
* @returns {string} the user name of the user that created the 'source' record, else `null` if it cannot be | ||
* determined | ||
*/ | ||
$createdAt () { | ||
$createdBy () { | ||
if (this.user) { | ||
return this.user.username | ||
} | ||
|
||
const firstModLog = this._firstModLog() | ||
|
||
return firstModLog?.naldDate ?? this.createdAt | ||
return firstModLog?.userId ?? null | ||
} | ||
|
||
/** | ||
|
Oops, something went wrong.