Skip to content

Instantly share code, notes, and snippets.

@Eventyret
Created March 29, 2023 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Eventyret/139df505cab60ce0c449a4802f33f6bf to your computer and use it in GitHub Desktop.
Save Eventyret/139df505cab60ce0c449a4802f33f6bf to your computer and use it in GitHub Desktop.
Validation Lifcylehook
const utils = require("@strapi/utils");
const { ApplicationError } = utils.errors;
const isDisconnecting = (disconnectArray, entityValue) => {
return disconnectArray.length && entityValue !== null;
};
module.exports = {
async beforeUpdate(event) {
const { data, where } = event.params;
const entity = await strapi.entityService.findOne(event.model.uid, where.id, {
populate: { owner: true },
});
if (data.owner) {
if (isDisconnecting(data.owner.disconnect, entity.owner) || entity.owner === null) {
throw ApplicationError("Test");
}
}
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment