mirror of
https://github.com/strapi/strapi.git
synced 2025-11-08 14:19:40 +00:00
Fix PR feedback
This commit is contained in:
parent
18ff464d6c
commit
85397769ed
@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/models",
|
"path": "/models",
|
||||||
"handler": "ContentTypeBuilder.models",
|
"handler": "ContentTypeBuilder.getModels",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
@ -11,7 +11,7 @@
|
|||||||
{
|
{
|
||||||
"method": "GET",
|
"method": "GET",
|
||||||
"path": "/models/:model",
|
"path": "/models/:model",
|
||||||
"handler": "ContentTypeBuilder.model",
|
"handler": "ContentTypeBuilder.getModel",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
@ -19,7 +19,7 @@
|
|||||||
{
|
{
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"path": "/models",
|
"path": "/models",
|
||||||
"handler": "ContentTypeBuilder.create",
|
"handler": "ContentTypeBuilder.createModel",
|
||||||
"config": {
|
"config": {
|
||||||
"policies": []
|
"policies": []
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,14 +4,14 @@ const fs = require('fs');
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
|
||||||
module.exports = {
|
const Service = require('../services/ContentTypeBuilder');
|
||||||
models: async ctx => {
|
|
||||||
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
getModels: async ctx => {
|
||||||
ctx.send({ models: Service.getModels() });
|
ctx.send({ models: Service.getModels() });
|
||||||
},
|
},
|
||||||
|
|
||||||
model: async ctx => {
|
getModel: async ctx => {
|
||||||
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
||||||
const { model } = ctx.params;
|
const { model } = ctx.params;
|
||||||
|
|
||||||
@ -20,8 +20,7 @@ module.exports = {
|
|||||||
ctx.send({ model: Service.getModel(model) });
|
ctx.send({ model: Service.getModel(model) });
|
||||||
},
|
},
|
||||||
|
|
||||||
create: async ctx => {
|
createModel: async ctx => {
|
||||||
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
|
||||||
const { name, attributes = [] } = ctx.request.body;
|
const { name, attributes = [] } = ctx.request.body;
|
||||||
|
|
||||||
if (!name) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.name.missing' }] }]);
|
if (!name) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.name.missing' }] }]);
|
||||||
@ -52,7 +51,7 @@ module.exports = {
|
|||||||
return ctx.badRequest(null, [{ messages: clearRelationsErrors }]);
|
return ctx.badRequest(null, [{ messages: clearRelationsErrors }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRelations = Service.createRelations(name, attributes);
|
const createRelationsErrors = Service.createRelations(name, attributes);
|
||||||
|
|
||||||
if (createRelationsErrors) {
|
if (createRelationsErrors) {
|
||||||
return ctx.badRequest(null, [{ messages: createRelationsErrors }]);
|
return ctx.badRequest(null, [{ messages: createRelationsErrors }]);
|
||||||
@ -70,7 +69,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateModel: async ctx => {
|
updateModel: async ctx => {
|
||||||
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
|
||||||
const { model } = ctx.params;
|
const { model } = ctx.params;
|
||||||
const { name, attributes = [] } = ctx.request.body;
|
const { name, attributes = [] } = ctx.request.body;
|
||||||
|
|
||||||
@ -99,7 +97,7 @@ module.exports = {
|
|||||||
return ctx.badRequest(null, [{ messages: clearRelationsErrors }]);
|
return ctx.badRequest(null, [{ messages: clearRelationsErrors }]);
|
||||||
}
|
}
|
||||||
|
|
||||||
const createRelations = Service.createRelations(model, attributes);
|
const createRelationsErrors = Service.createRelations(model, attributes);
|
||||||
|
|
||||||
if (createRelationsErrors) {
|
if (createRelationsErrors) {
|
||||||
return ctx.badRequest(null, [{ messages: createRelationsErrors }]);
|
return ctx.badRequest(null, [{ messages: createRelationsErrors }]);
|
||||||
@ -117,7 +115,6 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
deleteModel: async ctx => {
|
deleteModel: async ctx => {
|
||||||
const Service = strapi.plugins['content-type-builder'].services.contenttypebuilder;
|
|
||||||
const { model } = ctx.params;
|
const { model } = ctx.params;
|
||||||
|
|
||||||
if (!_.get(strapi.models, model)) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.unknow' }] }]);
|
if (!_.get(strapi.models, model)) return ctx.badRequest(null, [{ messages: [{ id: 'request.error.model.unknow' }] }]);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user