Skip to content
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
wants to merge 2 commits into from

Conversation

jamesobrooks
Copy link
Contributor

@jamesobrooks jamesobrooks commented Sep 13, 2024

Purpose

We want to document the reason for the creation and proper use of auditable.ts.

Major Changes

Add an ADR.

@jamesobrooks jamesobrooks requested review from a team as code owners September 13, 2024 23:20
Comment on lines 30 to 35
To create a historical record with an override, call the `createAuditRecord` as follows:

```typescript
const override = { updatedOn: someDate, updatedBy: someUser };
createAuditRecord<Foo>(someFoo, override);
```
Copy link
Contributor Author

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).

Copy link
Contributor Author

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
}

Copy link
Contributor Author

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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant