From 7c8d51d15dabbc2d8e81c293bf20bb2725ee88a1 Mon Sep 17 00:00:00 2001 From: Alexandre Bodin Date: Mon, 1 Jun 2020 12:01:12 +0200 Subject: [PATCH] fix 204 issues and use strapi.db.getModelByAssoc Signed-off-by: Alexandre Bodin --- packages/strapi-connector-bookshelf/lib/populate.js | 10 +++++----- .../lib/utils/associations.js | 5 ----- .../controllers/ContentManager.js | 4 ++++ packages/strapi/lib/middlewares/boom/index.js | 1 - 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/strapi-connector-bookshelf/lib/populate.js b/packages/strapi-connector-bookshelf/lib/populate.js index 23c4773666..0f1e3af34e 100644 --- a/packages/strapi-connector-bookshelf/lib/populate.js +++ b/packages/strapi-connector-bookshelf/lib/populate.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const { getComponentAttributes, isComponent } = require('./utils/attributes'); -const { findModelByAssoc, isPolymorphic } = require('./utils/associations'); +const { isPolymorphic } = require('./utils/associations'); /** * Create utilities to populate a model on fetch @@ -54,7 +54,7 @@ const populateBareAssociations = (definition, { prefix = '' } = {}) => { } const path = `${prefix}${assoc.alias}`; - const assocModel = findModelByAssoc({ assoc }); + const assocModel = strapi.db.getModelByAssoc(assoc); const polyAssocs = assocModel.associations .filter(assoc => isPolymorphic({ assoc })) @@ -72,7 +72,7 @@ const populateBareAssociations = (definition, { prefix = '' } = {}) => { const formatAssociationPopulate = ({ assoc, prefix = '' }) => { const path = `${prefix}${assoc.alias}`; - const assocModel = findModelByAssoc({ assoc }); + const assocModel = strapi.db.getModelByAssoc(assoc); const polyAssocs = assocModel.associations .filter(assoc => isPolymorphic({ assoc })) @@ -176,7 +176,7 @@ const formatPopulateOptions = (definition, withRelated) => { if (!assoc) return acc; - tmpModel = findModelByAssoc({ assoc }); + tmpModel = strapi.db.getModelByAssoc(assoc); if (isPolymorphic({ assoc })) { const path = formatPolymorphicPopulate({ @@ -206,7 +206,7 @@ const formatPolymorphicPopulate = ({ assoc, prefix = '' }) => { // oneToMorph or manyToMorph side. // Retrieve collection name because we are using it to build our hidden model. - const model = findModelByAssoc({ assoc }); + const model = strapi.db.getModelByAssoc(assoc); return { [`${prefix}${assoc.alias}.${model.collectionName}`]: function(query) { diff --git a/packages/strapi-connector-bookshelf/lib/utils/associations.js b/packages/strapi-connector-bookshelf/lib/utils/associations.js index e0e0cf022d..477a50b8b1 100644 --- a/packages/strapi-connector-bookshelf/lib/utils/associations.js +++ b/packages/strapi-connector-bookshelf/lib/utils/associations.js @@ -1,14 +1,9 @@ 'use strict'; -const findModelByAssoc = ({ assoc }) => { - return strapi.db.getModelByAssoc(assoc); -}; - const isPolymorphic = ({ assoc }) => { return assoc.nature.toLowerCase().indexOf('morph') !== -1; }; module.exports = { - findModelByAssoc, isPolymorphic, }; diff --git a/packages/strapi-plugin-content-manager/controllers/ContentManager.js b/packages/strapi-plugin-content-manager/controllers/ContentManager.js index ca188d905a..e2319b98d5 100644 --- a/packages/strapi-plugin-content-manager/controllers/ContentManager.js +++ b/packages/strapi-plugin-content-manager/controllers/ContentManager.js @@ -55,6 +55,10 @@ module.exports = { entities = await contentManagerService.fetchAll({ model }, ctx.request.query); } + if (!entities) { + return ctx.notFound(); + } + ctx.body = entities; }, diff --git a/packages/strapi/lib/middlewares/boom/index.js b/packages/strapi/lib/middlewares/boom/index.js index 00a4a0d3f7..60b0019671 100644 --- a/packages/strapi/lib/middlewares/boom/index.js +++ b/packages/strapi/lib/middlewares/boom/index.js @@ -94,7 +94,6 @@ module.exports = strapi => { strapi.app.use(async (ctx, next) => { await next(); - // Empty body is considered as `notFound` response. if (_.isNil(ctx.body) && _.isNil(ctx.status)) { ctx.notFound();