From dd3304d3cce9642d7a90367a69da3cbfb67c462e Mon Sep 17 00:00:00 2001 From: hmacr Date: Mon, 6 Jan 2025 15:18:31 +0530 Subject: [PATCH] type and rename --- server/models/base/Model.ts | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/server/models/base/Model.ts b/server/models/base/Model.ts index 2297b3c2a8..084c0a1748 100644 --- a/server/models/base/Model.ts +++ b/server/models/base/Model.ts @@ -31,7 +31,9 @@ type EventOverrideOptions = { }; type EventOptions = EventOverrideOptions & { - /** Whether to publish event to the job queue. */ + /** + * Whether to publish event to the job queue. Defaults to true when using any `withCtx` methods. + */ publish: boolean; }; @@ -50,14 +52,11 @@ class Model< /** * Validates this instance, and if the validation passes, persists it to the database. */ - public saveWithCtx( - ctx: APIContext, - eventOverrideOpts?: EventOverrideOptions - ) { + public saveWithCtx(ctx: APIContext, eventOpts?: EventOverrideOptions) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, }; @@ -71,12 +70,12 @@ class Model< public updateWithCtx( ctx: APIContext, keys: Partial, - eventOverrideOpts?: EventOverrideOptions + eventOpts?: EventOverrideOptions ) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, }; @@ -89,11 +88,11 @@ class Model< * Destroy the row corresponding to this instance. Depending on your setting for paranoid, the row will * either be completely deleted, or have its deletedAt timestamp set to the current time. */ - public destroyWithCtx(ctx: APIContext, eventOverrideOpts?: EventOptions) { + public destroyWithCtx(ctx: APIContext, eventOpts?: EventOverrideOptions) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, }; @@ -103,11 +102,11 @@ class Model< /** * Restore the row corresponding to this instance. Only available for paranoid models. */ - public restoreWithCtx(ctx: APIContext, eventOverrideOpts?: EventOptions) { + public restoreWithCtx(ctx: APIContext, eventOpts?: EventOverrideOptions) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, }; @@ -122,12 +121,12 @@ class Model< this: ModelStatic, ctx: APIContext, options: FindOrCreateOptions, CreationAttributes>, - eventOverrideOpts?: EventOptions + eventOpts?: EventOverrideOptions ) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, }; @@ -144,12 +143,12 @@ class Model< this: ModelStatic, ctx: APIContext, values?: CreationAttributes, - eventOverrideOpts?: EventOptions + eventOpts?: EventOverrideOptions ) { const hookContext: HookContext = { ...ctx.context, event: { - ...eventOverrideOpts, + ...eventOpts, publish: true, }, };