2021-01-27 12:35:24 +01:00
|
|
|
'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
|
|
|
|
2021-01-27 12:35:24 +01:00
|
|
|
const { isoLocales } = require('../constants');
|
|
|
|
|
|
|
|
const allowedLocaleCodes = isoLocales.map(prop('code'));
|
|
|
|
|
|
|
|
const createLocaleSchema = yup
|
|
|
|
.object()
|
|
|
|
.shape({
|
|
|
|
name: yup
|
|
|
|
.string()
|
|
|
|
.max(50)
|
2021-03-02 18:32:07 +01:00
|
|
|
.nullable(),
|
2021-01-27 12:35:24 +01:00
|
|
|
code: yup
|
|
|
|
.string()
|
|
|
|
.oneOf(allowedLocaleCodes)
|
|
|
|
.required(),
|
2021-02-05 15:39:11 +01:00
|
|
|
isDefault: yup.boolean().required(),
|
2021-01-27 12:35:24 +01:00
|
|
|
})
|
|
|
|
.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(),
|
2021-01-27 12:35:24 +01:00
|
|
|
})
|
|
|
|
.noUnknown();
|
|
|
|
|
|
|
|
module.exports = {
|
2021-11-03 19:31:57 +01:00
|
|
|
validateCreateLocaleInput: validateYupSchema(createLocaleSchema),
|
|
|
|
validateUpdateLocaleInput: validateYupSchema(updateLocaleSchema),
|
2021-01-27 12:35:24 +01:00
|
|
|
};
|