Skip to content

Commit

Permalink
Merge branch 'feat/files-events' into enhancements-6
Browse files Browse the repository at this point in the history
  • Loading branch information
t7tran committed Feb 16, 2024
2 parents 08f5586 + f21e678 commit 1e8c725
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions api/src/services/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ export class FilesService extends ItemsService {

// Is this file a replacement? if the file data already exists and we have a primary key
const isReplacement = existingFile !== null && primaryKey !== undefined;
const emitFilterOpts: MutationOptions & Record<string, any> = { emitEvents: false, emitFilters: true };

// If this is a new file upload, we need to generate a new primary key and DB record
if (isReplacement === false || primaryKey === undefined) {
primaryKey = await this.createOne(payload, { emitEvents: false });
primaryKey = await this.createOne(payload, emitFilterOpts);
}

const fileExtension =
Expand Down Expand Up @@ -201,7 +202,7 @@ export class FilesService extends ItemsService {
schema: this.schema,
});

await sudoService.updateOne(primaryKey, payload, { emitEvents: false });
await sudoService.updateOne(primaryKey, payload, emitFilterOpts);

if (opts?.emitEvents !== false) {
emitter.emitAction(
Expand Down
4 changes: 2 additions & 2 deletions api/src/services/items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
// Run all hooks that are attached to this event so the end user has the chance to augment the
// item that is about to be saved
const payloadAfterHooks =
opts.emitEvents !== false
(opts.emitEvents !== false || (opts as any).emitFilters !== false)
? await emitter.emitFilter(
this.eventScope === 'items'
? ['items.create', `${this.collection}.items.create`]
Expand Down Expand Up @@ -616,7 +616,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
// Run all hooks that are attached to this event so the end user has the chance to augment the
// item that is about to be saved
const payloadAfterHooks =
opts.emitEvents !== false
(opts.emitEvents !== false || (opts as any).emitFilters !== false)
? await emitter.emitFilter(
this.eventScope === 'items'
? ['items.update', `${this.collection}.items.update`]
Expand Down

0 comments on commit 1e8c725

Please sign in to comment.