fix 204 issues and use strapi.db.getModelByAssoc

Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
Alexandre Bodin 2020-06-01 12:01:12 +02:00
parent ba8509eac8
commit 7c8d51d15d
4 changed files with 9 additions and 11 deletions

View File

@ -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) {

View File

@ -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,
};

View File

@ -55,6 +55,10 @@ module.exports = {
entities = await contentManagerService.fetchAll({ model }, ctx.request.query);
}
if (!entities) {
return ctx.notFound();
}
ctx.body = entities;
},

View File

@ -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();