-
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
Conversation
Jira ticket: CAMS-282
To create a historical record with an override, call the `createAuditRecord` as follows: | ||
|
||
```typescript | ||
const override = { updatedOn: someDate, updatedBy: someUser }; | ||
createAuditRecord<Foo>(someFoo, 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.
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.
// option 1
export function createAuditRecord<T extends Auditable>(args: {
record: Omit<T, 'updatedOn' | 'updatedBy'>,
session?: CamsSession,
override?: Partial<Auditable>,
}): T {
// do stuff
}
// option 2
export function createAuditRecord<T extends Auditable>(
record: Omit<T, 'updatedOn' | 'updatedBy'>,
options?: {
session?: CamsSession,
override?: Partial<Auditable>,
}): T {
// do stuff
}
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.
We want to be able to use zero, one, or both of two optional arguments. We modify the function signature to accept a single object containing the required `record` as well as the two situationally required `session` and `override` arguments. We also document the appropriate use with JSDocs. Jira ticket: CAMS-282 Co-authored-by: Arthur Morrow <[email protected]>
Purpose
We want to document the reason for the creation and proper use of
auditable.ts
.Major Changes
Add an ADR.