mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
feat: add delete event emitting to fields service (#4840)
* feat: add delete event emitting to fields service * Inline event scope Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import { ForbiddenException, InvalidPayloadException } from '../exceptions';
|
||||
import { PayloadService } from '../services/payload';
|
||||
import getDefaultValue from '../utils/get-default-value';
|
||||
import cache from '../cache';
|
||||
import emitter, { emitAsyncSafe } from '../emitter';
|
||||
import SchemaInspector from '@directus/schema';
|
||||
import { toArray } from '../utils/to-array';
|
||||
import env from '../env';
|
||||
@@ -296,6 +297,17 @@ export class FieldsService {
|
||||
throw new ForbiddenException('Only admins can perform this action.');
|
||||
}
|
||||
|
||||
await emitter.emitAsync(`fields.delete.before`, {
|
||||
event: `fields.delete.before`,
|
||||
accountability: this.accountability,
|
||||
collection: collection,
|
||||
item: field,
|
||||
action: 'delete',
|
||||
payload: null,
|
||||
schema: this.schema,
|
||||
database: this.knex,
|
||||
});
|
||||
|
||||
await this.knex('directus_fields').delete().where({ collection, field });
|
||||
|
||||
if (
|
||||
@@ -333,6 +345,17 @@ export class FieldsService {
|
||||
if (cache && env.CACHE_AUTO_PURGE) {
|
||||
await cache.clear();
|
||||
}
|
||||
|
||||
emitAsyncSafe(`fields.delete`, {
|
||||
event: `fields.delete`,
|
||||
accountability: this.accountability,
|
||||
collection: collection,
|
||||
item: field,
|
||||
action: 'delete',
|
||||
payload: null,
|
||||
schema: this.schema,
|
||||
database: this.knex,
|
||||
});
|
||||
}
|
||||
|
||||
public addColumnToTable(table: Knex.CreateTableBuilder, field: RawField | Field, alter: Column | null = null) {
|
||||
|
||||
Reference in New Issue
Block a user