Fix sanitize bug with mongo objectid and use lower-case for getModel

This commit is contained in:
Alexandre Bodin 2019-10-04 11:38:54 +02:00
parent 5bc4a0b424
commit 444ce89b19
2 changed files with 7 additions and 4 deletions

View File

@ -5,6 +5,8 @@ module.exports = function sanitizeEntity(data, { model, withPrivate = false }) {
let plainData = typeof data.toJSON === 'function' ? data.toJSON() : data;
if (typeof plainData !== 'object') return plainData;
const attributes = model.attributes;
return Object.keys(plainData).reduce((acc, key) => {
const attribute = attributes[key];

View File

@ -413,11 +413,12 @@ class Strapi extends EventEmitter {
}
getModel(modelKey, plugin) {
let key = modelKey.toLowerCase();
return plugin === 'admin'
? _.get(strapi.admin, ['models', modelKey], undefined)
: _.get(strapi.plugins, [plugin, 'models', modelKey]) ||
_.get(strapi, ['models', modelKey]) ||
_.get(strapi, ['groups', modelKey]) ||
? _.get(strapi.admin, ['models', key], undefined)
: _.get(strapi.plugins, [plugin, 'models', key]) ||
_.get(strapi, ['models', key]) ||
_.get(strapi, ['groups', key]) ||
undefined;
}