Fix undefined model case

This commit is contained in:
Alexandre Bodin 2023-06-27 09:34:47 +02:00
parent 8e1e7317a7
commit b13c272f11

View File

@ -53,6 +53,8 @@ const getTimestamps = (model: Model) => {
}; };
const getNonWritableAttributes = (model: Model) => { const getNonWritableAttributes = (model: Model) => {
if (!model) return [];
const nonWritableAttributes = _.reduce( const nonWritableAttributes = _.reduce(
model.attributes, model.attributes,
(acc, attr, attrName) => (attr.writable === false ? acc.concat(attrName) : acc), (acc, attr, attrName) => (attr.writable === false ? acc.concat(attrName) : acc),
@ -63,6 +65,8 @@ const getNonWritableAttributes = (model: Model) => {
}; };
const getWritableAttributes = (model: Model) => { const getWritableAttributes = (model: Model) => {
if (!model) return [];
return _.difference(Object.keys(model.attributes), getNonWritableAttributes(model)); return _.difference(Object.keys(model.attributes), getNonWritableAttributes(model));
}; };