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:
Joonas Palosuo
2021-04-08 23:39:31 +03:00
committed by GitHub
parent 93f8b7720c
commit 9c621c6e20

View File

@@ -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) {