Merge pull request #3012 from strapi/fix/events

Remove synchronous way of sending event
This commit is contained in:
Alexandre BODIN 2019-03-21 12:11:16 +01:00 committed by GitHub
commit a42c2a483c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,17 +78,15 @@ module.exports = {
try {
fs.writeFileSync(modelFilePath, JSON.stringify(modelJSON, null, 2), 'utf8');
const response = () => {
ctx.send({ ok: true });
strapi.reload();
};
if (_.isEmpty(strapi.api)) {
strapi.emit('didCreateFirstContentType', response);
strapi.emit('didCreateFirstContentType');
} else {
strapi.emit('didCreateContentType', response);
strapi.emit('didCreateContentType');
}
ctx.send({ ok: true });
setImmediate(() => strapi.reload());
} catch (e) {
strapi.emit('didNotCreateContentType', e);
return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.write' }] }]);