Convly 5f01d9ebe1 Add permissions on upload controller
Signed-off-by: Convly <jean-sebastien.herbaux@epitech.eu>
2020-07-08 11:48:42 +02:00

28 lines
711 B
JavaScript

'use strict';
const { yup, formatYupErrors } = require('strapi-utils');
const fileInfoSchema = yup.object({
name: yup.string().nullable(),
alternativeText: yup.string().nullable(),
caption: yup.string().nullable(),
});
const uploadSchema = yup.object({
fileInfo: fileInfoSchema,
});
const multiUploadSchema = yup.object({
fileInfo: yup.array().of(fileInfoSchema),
});
const validateUploadBody = (data = {}, isMulti = false) => {
const schema = isMulti ? multiUploadSchema : uploadSchema;
return schema.validate(data, { abortEarly: false }).catch(err => {
throw strapi.errors.badRequest('ValidationError', { errors: formatYupErrors(err) });
});
};
module.exports = validateUploadBody;