Skip to content

Commit 6c5f636

Browse files
authored
fix(mixin): pass the extra values via options (#142)
* fix(mixin): pass the extra values via options dynamically pass extra values to add to audit log model GH-141 * fix(ci-cd): updated the documentation update the readme GH-141
1 parent 8c480b0 commit 6c5f636

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ export class GroupRepository extends AuditRepositoryMixin<
220220
}
221221
```
222222

223-
You can pass any extra attributes to save into audit table using the `IAuditMixinOptions` parameter of mixin function.
223+
You can pass any extra attributes to save into audit table using the `IAuditMixinOptions` parameter of mixin function. You can also pass some dynamic values to the extra columns of the audit-log table via the method options.
224+
225+
```ts
226+
const groupAuditOpts: IAuditMixinOptions = {
227+
actionKey: 'Group_Logs',
228+
extra: 'static value',
229+
};
230+
```
231+
232+
```ts
233+
repo.create(data, {extra: 'random calculated value'});
234+
```
235+
236+
So the method options will have a priority over repository mixin options.
224237

225238
Make sure you provide `getCurrentUser` and `getAuditLogRepository` Getter functions in constructor.
226239

docs/README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,20 @@ export class GroupRepository extends AuditRepositoryMixin<
220220
}
221221
```
222222

223-
You can pass any extra attributes to save into audit table using the `IAuditMixinOptions` parameter of mixin function.
223+
You can pass any extra attributes to save into audit table using the `IAuditMixinOptions` parameter of mixin function. You can also pass some dynamic values to the extra columns of the audit-log table via the method options.
224+
225+
```ts
226+
const groupAuditOpts: IAuditMixinOptions = {
227+
actionKey: 'Group_Logs',
228+
extra: 'static value',
229+
};
230+
```
231+
232+
```ts
233+
repo.create(data, {extra: 'random calculated value'});
234+
```
235+
236+
So the method options will have a priority over repository mixin options.
224237

225238
Make sure you provide `getCurrentUser` and `getAuditLogRepository` Getter functions in constructor.
226239

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/mixins/audit.mixin.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,13 @@ export function AuditRepositoryMixin<
4848
options?: AuditOptions,
4949
): AuditLog {
5050
const {before, after} = modification;
51-
const extras: Omit<IAuditMixinOptions, 'actionKey'> = {...opts};
51+
//dynamic will take precedence over static
52+
const extras: AnyObject = {
53+
...opts, // passing options to the model helps in adding custom and static values to it if needed
54+
...options, // passing options to the model helps in adding custom and dynamic values to it if needed
55+
};
5256
delete extras.actionKey;
57+
delete extras.noAudit;
5358
return new AuditLog({
5459
actedAt: new Date(),
5560
actor: this.getActor(user, options?.actorId),

0 commit comments

Comments
 (0)