[RESOLVED]
My final code:
const { ValidationError } = require('@strapi/utils').errors;
const validateSimpleModule = (event) => {
const { params } = event;
const { data } = params;
// eslint-disable-next-line camelcase
const { main_title, main_description, cta, subtitle } = data;
// eslint-disable-next-line camelcase
if (main_title && cta) {
// eslint-disable-next-line camelcase
if (!main_description) {
throw new ValidationError(
`Não é possível salvar o conteúdo dessa forma!`,
);
}
}
// eslint-disable-next-line camelcase
if (main_title) {
// eslint-disable-next-line camelcase
if (!main_description || !cta || !subtitle) {
throw new ValidationError(
`Não é possível salvar o conteúdo dessa forma!`,
);
}
}
};
module.exports = {
async bootstrap({ strapi }) {
// In order to resolve 502 problems in internal elb(between elb and target group), setting headers to 61 to 65 seconds.
strapi.server.httpServer.keepAliveTimeout = 61 * 1000;
strapi.server.httpServer.headersTimeout = 65 * 1000;
// Listen lifecyles
strapi.db.lifecycles.subscribe({
models: ['simple-module.simple-module'], // listen only this model
async beforeCreate(event) {
validateSimpleModule(event);
},
async beforeUpdate(event) {
validateSimpleModule(event);
},
});
},
};