-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an ADR about the Auditable type and helper fn #899
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Auditable | ||
|
||
## Context | ||
|
||
A historical record needs to be kept related to certain data points in CAMS. This historical record involves tracking when a change was made, and by whom. We were previously managing this for orders and assignments in an ad hoc manner. To ensure consistency and to reduce boilerplate code, we need a way to provide this functionality through code common to all data types that require historical records. | ||
|
||
## Decision | ||
|
||
We have created the `Auditable` type which contains the common properties for history. We have also created the `createAuditRecord` function which provides default values for the properties and the ability to override if needed. Consider the example type—`Foo`—as follows: | ||
|
||
```typescript | ||
type Foo = Auditable & { | ||
prop1: string; | ||
prop2: number; | ||
} | ||
``` | ||
|
||
To create a historical record for an action initiated by a user, call the `createAuditRecord` as follows: | ||
|
||
```typescript | ||
createAuditRecord<Foo>(someFoo, userSession); | ||
``` | ||
|
||
To create a historical record for an action initiated by the system, call the `createAuditRecord` as follows: | ||
|
||
```typescript | ||
createAuditRecord<Foo>(someFoo); | ||
``` | ||
|
||
To create a historical record with an override, call the `createAuditRecord` as follows: | ||
|
||
```typescript | ||
const override = { updatedOn: someDate, updatedBy: someUser }; | ||
createAuditRecord<Foo>(someFoo, override); | ||
``` | ||
|
||
## Status | ||
|
||
Approved | ||
|
||
## Consequences | ||
|
||
Developers need to remember to make use of this type and the function, but it should reduce the amount of boilerplate/duplicate code we have to write to track history. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This highlights a problem with the current implementation. Because the parameters for
createAuditRecord
contain two optional parameters, we can actually only provide an override if we also provide a session. This could prove to be problematic if for some reason we need to create a record of a system-initiated change while also overriding the date (e.g. we need to use a date from DXTR or the court that is prior to the current date).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As written, this example would not work. We should probably convert the function to take a single object for arguments or the item and an object that contains the optional session and optional override.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I like option 1 better. Session and override seem fundamentally different so grouping just the two of them doesn't make much sense to me.