forked from VirtusLab-Open-Source/strapi-plugin-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstrapi-server.js
42 lines (36 loc) · 1.47 KB
/
strapi-server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict';
const { isArray, isEmpty, isString } = require('lodash');
const server = require('./server');
const contentTypes = require('./content-types');
const { REGEX } = require('./server/utils/constants');
module.exports = () => ({
...server,
contentTypes,
config: {
...server.config,
default: ({ env }) => ({
...server.config.default,
}),
validator: (config) => {
// Check moderatorRoles values
const moderatorRolesValid = config.moderatorRoles
.filter(_ => !isString(_)).length === 0;
if (!moderatorRolesValid) {
throw new Error(`'moderatorRoles' must roles keys`);
}
// Check approvalFlow values
const approvalFlowValid = config.approvalFlow
.filter(_ => !REGEX.uid.test(_)).length === 0;
if (!approvalFlowValid) {
throw new Error(`'approvalFlow' must contain Content Types identifiers in the format like 'api::<collection name>.<content type name>'`);
}
// Check entryLabel keys and values
const entryLabelKeysValid = Object.keys(config.entryLabel)
.filter(_ => _ !== '*')
.filter(_ => !(REGEX.uid.test(_) && isArray(config.entryLabel[_]) && !isEmpty(config.entryLabel[_]))).length === 0;
if (!entryLabelKeysValid) {
throw new Error(`'entryLabel' must contain records in the format like 'api::<collection name>.<content type name>': ['Field1', 'field_2']`);
}
},
},
});