mirror of
https://github.com/strapi/strapi.git
synced 2025-08-08 08:46:42 +00:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
'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,
|
|
};
|