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({
|
2022-08-08 23:33:39 +02:00
|
|
|
name: yup.string().max(50).nullable(),
|
|
|
|
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({
|
2022-08-08 23:33:39 +02:00
|
|
|
name: yup.string().min(1).max(50).nullable(),
|
2021-02-05 15:39:11 +01:00
|
|
|
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
|
|
|
};
|