fixes bug with removing internal fields

This commit is contained in:
James
2020-11-09 14:47:26 -05:00
parent 7154a1e35c
commit e12bdb320d

View File

@@ -1,10 +1,14 @@
const removeInternalFields = (incomingDoc) => {
const doc = { ...incomingDoc };
if (doc._id) delete doc._id;
if (doc.__v) delete doc.__v;
if (doc.salt) delete doc._salt;
if (doc.hash) delete doc._hash;
return doc;
};
const internalFields = ['_id', '__v', 'salt', 'hash'];
const removeInternalFields = (incomingDoc) => Object.entries(incomingDoc).reduce((newDoc, [key, val]) => {
if (internalFields.indexOf(key) > -1) {
return newDoc;
}
return {
...newDoc,
[key]: val,
};
}, {});
module.exports = removeInternalFields;