mirror of
https://github.com/strapi/strapi.git
synced 2025-09-19 13:31:34 +00:00
fix 204 issues and use strapi.db.getModelByAssoc
Signed-off-by: Alexandre Bodin <bodin.alex@gmail.com>
This commit is contained in:
parent
ba8509eac8
commit
7c8d51d15d
@ -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) {
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -55,6 +55,10 @@ module.exports = {
|
||||
entities = await contentManagerService.fetchAll({ model }, ctx.request.query);
|
||||
}
|
||||
|
||||
if (!entities) {
|
||||
return ctx.notFound();
|
||||
}
|
||||
|
||||
ctx.body = entities;
|
||||
},
|
||||
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user