mirror of
https://github.com/strapi/strapi.git
synced 2025-11-02 02:44:55 +00:00
content-manager: list content types on kind
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
dce6bd432c
commit
90408d5119
@ -1,12 +1,25 @@
|
||||
'use strict';
|
||||
|
||||
const { createModelConfigurationSchema } = require('./validation');
|
||||
const _ = require('lodash');
|
||||
|
||||
const {
|
||||
createModelConfigurationSchema,
|
||||
validateKind,
|
||||
} = require('./validation');
|
||||
|
||||
module.exports = {
|
||||
/**
|
||||
* Returns the list of available content types
|
||||
*/
|
||||
listContentTypes(ctx) {
|
||||
async listContentTypes(ctx) {
|
||||
const { kind } = ctx.query;
|
||||
|
||||
try {
|
||||
await validateKind(kind);
|
||||
} catch (error) {
|
||||
return ctx.send({ error }, 400);
|
||||
}
|
||||
|
||||
const service = strapi.plugins['content-manager'].services.contenttypes;
|
||||
|
||||
const contentTypes = Object.keys(strapi.contentTypes)
|
||||
@ -14,6 +27,13 @@ module.exports = {
|
||||
if (uid.startsWith('strapi::')) return false;
|
||||
if (uid === 'plugins::upload.file') return false;
|
||||
|
||||
if (
|
||||
kind &&
|
||||
_.get(strapi.contentTypes[uid], 'kind', 'collectionType') !== kind
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
})
|
||||
.map(uid => {
|
||||
|
||||
@ -1,3 +1,24 @@
|
||||
module.exports = {
|
||||
createModelConfigurationSchema: require('./model-configuration'),
|
||||
'use strict';
|
||||
|
||||
const yup = require('yup');
|
||||
|
||||
const createModelConfigurationSchema = require('./model-configuration');
|
||||
|
||||
const TYPES = ['singleType', 'collectionType'];
|
||||
|
||||
/**
|
||||
* Validates type kind
|
||||
*/
|
||||
const validateKind = kind => {
|
||||
return yup
|
||||
.string()
|
||||
.oneOf(TYPES)
|
||||
.nullable()
|
||||
.validate(kind);
|
||||
// .catch(error => Promise.reject(formatYupErrors(error)));
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
createModelConfigurationSchema,
|
||||
validateKind,
|
||||
};
|
||||
|
||||
@ -49,12 +49,16 @@ const deleteConfiguration = uid => {
|
||||
const formatContentType = contentType => {
|
||||
return {
|
||||
uid: contentType.uid,
|
||||
|
||||
name: _.get(contentType, ['info', 'name']),
|
||||
label: formatContentTypeLabel(
|
||||
_.get(contentType, ['info', 'name'], contentType.modelName)
|
||||
),
|
||||
isDisplayed: HIDDEN_CONTENT_TYPES.includes(contentType.uid) ? false : true,
|
||||
schema: formatContentTypeSchema(contentType),
|
||||
schema: {
|
||||
...formatContentTypeSchema(contentType),
|
||||
kind: contentType.kind || 'collectionType',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user