2020-05-22 12:58:14 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const { yup, formatYupErrors } = require('strapi-utils');
|
2020-05-27 13:15:52 +02:00
|
|
|
const { intergerOrString } = require('../../validation/common-validators');
|
2020-05-22 12:58:14 +02:00
|
|
|
|
|
|
|
const handleReject = error => Promise.reject(formatYupErrors(error));
|
|
|
|
|
|
|
|
const roleCreateUpdateSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
name: yup
|
|
|
|
.string()
|
|
|
|
.min(1)
|
|
|
|
.required(),
|
|
|
|
description: yup.string().required(),
|
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
const validateRoleCreateInput = async data => {
|
|
|
|
return roleCreateUpdateSchema
|
|
|
|
.validate(data, { strict: true, abortEarly: false })
|
|
|
|
.catch(handleReject);
|
|
|
|
};
|
|
|
|
|
|
|
|
const validateRoleUpdateInput = async data => {
|
|
|
|
return roleCreateUpdateSchema
|
|
|
|
.validate(data, { strict: true, abortEarly: false })
|
|
|
|
.catch(handleReject);
|
|
|
|
};
|
|
|
|
|
2020-05-27 13:15:52 +02:00
|
|
|
const validateRoleDeleteInput = async data => {
|
|
|
|
const roleDeleteSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
ids: yup
|
|
|
|
.array()
|
|
|
|
.of(intergerOrString)
|
|
|
|
.min(1)
|
|
|
|
.required(),
|
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
return roleDeleteSchema.validate(data, { strict: true, abortEarly: false }).catch(handleReject);
|
|
|
|
};
|
|
|
|
|
2020-05-22 12:58:14 +02:00
|
|
|
module.exports = {
|
|
|
|
validateRoleCreateInput,
|
|
|
|
validateRoleUpdateInput,
|
2020-05-27 13:15:52 +02:00
|
|
|
validateRoleDeleteInput,
|
2020-05-22 12:58:14 +02:00
|
|
|
};
|