'use strict'; const { yup, formatYupErrors } = require('strapi-utils'); const handleReject = error => Promise.reject(formatYupErrors(error)); const roleCreateSchema = yup .object() .shape({ name: yup .string() .min(1) .required(), description: yup.string().nullable(), }) .noUnknown(); const roleUpdateSchema = yup .object() .shape({ name: yup.string().min(1), description: yup.string().nullable(), }) .noUnknown(); const roleDeleteSchema = yup .object() .shape({ ids: yup .array() .of(yup.strapiID()) .min(1) .required(), }) .noUnknown(); const validateRoleCreateInput = async data => { return roleCreateSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject); }; const validateRoleUpdateInput = async data => { return roleUpdateSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject); }; const validateRoleDeleteInput = async data => { return roleDeleteSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject); }; module.exports = { validateRoleCreateInput, validateRoleUpdateInput, validateRoleDeleteInput, };