mirror of
https://github.com/directus/directus.git
synced 2026-01-31 09:18:22 -05:00
Add support for read hooks on items (#6341)
* Add emitter on item read * Add performance warning to docs * Make result instead of query the payload
This commit is contained in:
@@ -303,6 +303,17 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
throw new ForbiddenException();
|
||||
}
|
||||
|
||||
emitAsyncSafe(`${this.eventScope}.read`, {
|
||||
event: `${this.eventScope}.read`,
|
||||
accountability: this.accountability,
|
||||
collection: this.collection,
|
||||
item: key,
|
||||
action: 'read',
|
||||
payload: results,
|
||||
schema: this.schema,
|
||||
database: getDatabase(),
|
||||
});
|
||||
|
||||
return results[0];
|
||||
}
|
||||
|
||||
@@ -329,6 +340,18 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
|
||||
};
|
||||
|
||||
const results = await this.readByQuery(queryWithKeys, opts);
|
||||
|
||||
emitAsyncSafe(`${this.eventScope}.read`, {
|
||||
event: `${this.eventScope}.read`,
|
||||
accountability: this.accountability,
|
||||
collection: this.collection,
|
||||
item: keys,
|
||||
action: 'read',
|
||||
payload: results,
|
||||
schema: this.schema,
|
||||
database: getDatabase(),
|
||||
});
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user