Created
March 29, 2023 11:38
-
-
Save Eventyret/139df505cab60ce0c449a4802f33f6bf to your computer and use it in GitHub Desktop.
Validation Lifcylehook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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