import { errors } from “@strapi/utils”;
import { CollectionStatus } from “…/…/…/…/vars”;
const { ApplicationError, NotFoundError } = errors;
export default {
async beforeCreate(event) {
//todo add validation before create for mandatory field
},
async beforeDelete(event) {
const { params } = event;
const entry = await strapi.entityService.findOne(
“api::csdd-one-sim-parameter-td-authorization.csdd-one-sim-parameter-td-authorization”,
params.where.id,
{}
);
if (!entry) {
//handle if already deleted
throw new NotFoundError(
`Entry ID: ${params.where.id} not found / already deleted!`
);
} else if (entry.status === CollectionStatus.SUBMITTED) {
throw new ApplicationError(
`Entry with status: ${CollectionStatus.SUBMITTED} cannot be deleted!`,
{}
);
}
},
};
i got same problem, here’s my code i want trigger form validation on lifecycle before create how to do it?