fixes bug with removing internal fields
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user