mirror of
https://github.com/strapi/strapi.git
synced 2025-12-26 14:44:31 +00:00
feature: replace emitEvent calls with new webhook store
This commit is contained in:
parent
506c495d91
commit
14ff035647
@ -10,7 +10,6 @@ const { sumDraftCounts } = require('./utils/draft');
|
||||
|
||||
const { hasDraftAndPublish } = strapiUtils.contentTypes;
|
||||
const { PUBLISHED_AT_ATTRIBUTE, CREATED_BY_ATTRIBUTE } = strapiUtils.contentTypes.constants;
|
||||
const { ENTRY_PUBLISH, ENTRY_UNPUBLISH } = strapiUtils.webhook.webhookEvents;
|
||||
|
||||
const omitPublishedAtField = omit(PUBLISHED_AT_ATTRIBUTE);
|
||||
|
||||
@ -254,7 +253,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const updatedEntity = await strapi.entityService.update(uid, entity.id, params);
|
||||
|
||||
await emitEvent(ENTRY_PUBLISH, updatedEntity, uid);
|
||||
await emitEvent(strapi.webhookStore.allowedEvents.get('ENTRY_PUBLISH'), updatedEntity, uid);
|
||||
|
||||
const mappedEntity = await this.mapEntity(updatedEntity, uid);
|
||||
|
||||
@ -283,7 +282,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const updatedEntity = await strapi.entityService.update(uid, entity.id, params);
|
||||
|
||||
await emitEvent(ENTRY_UNPUBLISH, updatedEntity, uid);
|
||||
await emitEvent(strapi.webhookStore.allowedEvents.get('ENTRY_UNPUBLISH'), updatedEntity, uid);
|
||||
|
||||
const mappedEntity = await this.mapEntity(updatedEntity, uid);
|
||||
|
||||
|
||||
@ -4,11 +4,7 @@ const _ = require('lodash');
|
||||
const delegate = require('delegates');
|
||||
const { InvalidTimeError, InvalidDateError, InvalidDateTimeError, InvalidRelationError } =
|
||||
require('@strapi/database').errors;
|
||||
const {
|
||||
webhook: webhookUtils,
|
||||
contentTypes: contentTypesUtils,
|
||||
sanitize,
|
||||
} = require('@strapi/utils');
|
||||
const { contentTypes: contentTypesUtils, sanitize } = require('@strapi/utils');
|
||||
const { ValidationError } = require('@strapi/utils').errors;
|
||||
const { isAnyToMany } = require('@strapi/utils').relations;
|
||||
const { transformParamsToQuery } = require('@strapi/utils').convertQueryParams;
|
||||
@ -31,9 +27,6 @@ const transformLoadParamsToQuery = (uid, field, params = {}, pagination = {}) =>
|
||||
};
|
||||
};
|
||||
|
||||
// TODO: those should be strapi events used by the webhooks not the other way arround
|
||||
const { ENTRY_CREATE, ENTRY_UPDATE, ENTRY_DELETE } = webhookUtils.webhookEvents;
|
||||
|
||||
const databaseErrorsToTransform = [
|
||||
InvalidTimeError,
|
||||
InvalidDateTimeError,
|
||||
@ -162,7 +155,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
||||
entity = await this.findOne(uid, entity.id, wrappedParams);
|
||||
}
|
||||
|
||||
await this.emitEvent(uid, ENTRY_CREATE, entity);
|
||||
await this.emitEvent(uid, strapi.webhookStore.allowedEvents.get('ENTRY_CREATE'), entity);
|
||||
|
||||
return entity;
|
||||
},
|
||||
@ -213,7 +206,7 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
||||
entity = await this.findOne(uid, entity.id, wrappedParams);
|
||||
}
|
||||
|
||||
await this.emitEvent(uid, ENTRY_UPDATE, entity);
|
||||
await this.emitEvent(uid, strapi.webhookStore.allowedEvents.get('ENTRY_UPDATE'), entity);
|
||||
|
||||
return entity;
|
||||
},
|
||||
@ -238,7 +231,11 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
||||
await db.query(uid).delete({ where: { id: entityToDelete.id } });
|
||||
await deleteComponents(uid, componentsToDelete, { loadComponents: false });
|
||||
|
||||
await this.emitEvent(uid, ENTRY_DELETE, entityToDelete);
|
||||
await this.emitEvent(
|
||||
uid,
|
||||
strapi.webhookStore.allowedEvents.get('ENTRY_DELETE'),
|
||||
entityToDelete
|
||||
);
|
||||
|
||||
return entityToDelete;
|
||||
},
|
||||
@ -266,7 +263,11 @@ const createDefaultImplementation = ({ strapi, db, eventHub, entityValidator })
|
||||
);
|
||||
|
||||
// Trigger webhooks. One for each entity
|
||||
await Promise.all(entitiesToDelete.map((entity) => this.emitEvent(uid, ENTRY_DELETE, entity)));
|
||||
await Promise.all(
|
||||
entitiesToDelete.map((entity) =>
|
||||
this.emitEvent(uid, strapi.webhookStore.allowedEvents.get('ENTRY_DELETE'), entity)
|
||||
)
|
||||
);
|
||||
|
||||
return deletedEntities;
|
||||
},
|
||||
|
||||
@ -17,13 +17,10 @@ const {
|
||||
sanitize,
|
||||
nameToSlug,
|
||||
contentTypes: contentTypesUtils,
|
||||
webhook: webhookUtils,
|
||||
errors: { ApplicationError, NotFoundError },
|
||||
file: { bytesToKbytes },
|
||||
} = require('@strapi/utils');
|
||||
|
||||
const { MEDIA_UPDATE, MEDIA_CREATE, MEDIA_DELETE } = webhookUtils.webhookEvents;
|
||||
|
||||
const { FILE_MODEL_UID } = require('../constants');
|
||||
const { getService } = require('../utils');
|
||||
|
||||
@ -347,7 +344,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const res = await strapi.entityService.update(FILE_MODEL_UID, id, { data: fileValues });
|
||||
|
||||
await this.emitEvent(MEDIA_UPDATE, res);
|
||||
await this.emitEvent(strapi.webhookStore.allowedEvents.get('MEDIA_UPDATE'), res);
|
||||
|
||||
return res;
|
||||
},
|
||||
@ -363,7 +360,7 @@ module.exports = ({ strapi }) => ({
|
||||
|
||||
const res = await strapi.query(FILE_MODEL_UID).create({ data: fileValues });
|
||||
|
||||
await this.emitEvent(MEDIA_CREATE, res);
|
||||
await this.emitEvent(strapi.webhookStore.allowedEvents.get('MEDIA_CREATE'), res);
|
||||
|
||||
return res;
|
||||
},
|
||||
@ -400,7 +397,7 @@ module.exports = ({ strapi }) => ({
|
||||
where: { id: file.id },
|
||||
});
|
||||
|
||||
await this.emitEvent(MEDIA_DELETE, media);
|
||||
await this.emitEvent(strapi.webhookStore.allowedEvents.get('MEDIA_DELETE'), media);
|
||||
|
||||
return strapi.query(FILE_MODEL_UID).delete({ where: { id: file.id } });
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user