41 lines
828 B
JavaScript
Raw Normal View History

'use strict';
const { prop } = require('lodash/fp');
2021-11-03 19:31:57 +01:00
const { yup, validateYupSchema } = require('@strapi/utils');
2021-10-20 17:30:05 +02:00
const { isoLocales } = require('../constants');
const allowedLocaleCodes = isoLocales.map(prop('code'));
const createLocaleSchema = yup
.object()
.shape({
name: yup
.string()
.max(50)
.nullable(),
code: yup
.string()
.oneOf(allowedLocaleCodes)
.required(),
2021-02-05 15:39:11 +01:00
isDefault: yup.boolean().required(),
})
.noUnknown();
const updateLocaleSchema = yup
.object()
.shape({
name: yup
.string()
.min(1)
.max(50)
2021-02-05 15:39:11 +01:00
.nullable(),
isDefault: yup.boolean(),
})
.noUnknown();
module.exports = {
2021-11-03 19:31:57 +01:00
validateCreateLocaleInput: validateYupSchema(createLocaleSchema),
validateUpdateLocaleInput: validateYupSchema(updateLocaleSchema),
};