mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 10:23:34 +00:00
Fix sanitizeEntity
This commit is contained in:
parent
87d79388c1
commit
c1369c7960
@ -9,9 +9,11 @@ const createRouteScopeGenerator = namespace => route => {
|
||||
if (typeof route.handler === 'string') {
|
||||
const [controller, action] = route.handler.split('.');
|
||||
|
||||
_.defaultsDeep(route.config, {
|
||||
auth: {
|
||||
scope: `${prefix}${controller}.${toLower(action)}`,
|
||||
_.defaultsDeep(route, {
|
||||
config: {
|
||||
auth: {
|
||||
scope: `${prefix}${controller}.${toLower(action)}`,
|
||||
},
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
@ -60,7 +60,9 @@ describe('Sanitize Entity', () => {
|
||||
attributes: {
|
||||
...userModel.attributes,
|
||||
article: {
|
||||
collection: 'article',
|
||||
type: 'relation',
|
||||
relation: 'oneToOne',
|
||||
target: 'article',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@ -48,8 +48,10 @@ const sanitizeEntity = (dataSource, options) => {
|
||||
}
|
||||
|
||||
// Relations
|
||||
const relation = attribute && (attribute.model || attribute.collection || attribute.component);
|
||||
if (relation) {
|
||||
const isRelation = attribute && attribute.type === 'relation';
|
||||
if (isRelation) {
|
||||
const relation = attribute && attribute.target;
|
||||
|
||||
if (_.isNil(value)) {
|
||||
return { ...acc, [key]: value };
|
||||
}
|
||||
@ -69,23 +71,18 @@ const sanitizeEntity = (dataSource, options) => {
|
||||
};
|
||||
|
||||
let sanitizeFn;
|
||||
if (relation === '*') {
|
||||
if (attribute.relation && attribute.relation.toLowerCase().includes('morph')) {
|
||||
sanitizeFn = entity => {
|
||||
if (_.isNil(entity) || !_.has(entity, '__contentType')) {
|
||||
if (_.isNil(entity) || !_.has(entity, '__type')) {
|
||||
return entity;
|
||||
}
|
||||
|
||||
return sanitizeEntity(entity, {
|
||||
model: strapi.getModel(entity.__contentType),
|
||||
...baseOptions,
|
||||
});
|
||||
return sanitizeEntity(entity, { model: strapi.getModel(entity.__type), ...baseOptions });
|
||||
};
|
||||
} else {
|
||||
sanitizeFn = entity =>
|
||||
sanitizeEntity(entity, {
|
||||
model: strapi.getModel(relation, attribute.plugin),
|
||||
...baseOptions,
|
||||
});
|
||||
sanitizeFn = entity => {
|
||||
return sanitizeEntity(entity, { model: strapi.getModel(relation), ...baseOptions });
|
||||
};
|
||||
}
|
||||
|
||||
const nextVal = Array.isArray(value) ? value.map(sanitizeFn) : sanitizeFn(value);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user