Created
April 9, 2017 08:57
-
-
Save oakfang/c1a52d96192852375cfe745ad2664c40 to your computer and use it in GitHub Desktop.
A function to ensure object id props of an object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import _ from 'lodash'; | |
import { ObjectId } from 'mongoose'; | |
import ensureObjectId from './utils'; | |
exports default function ensureObjectIdProps(obj, paths) { | |
paths.forEach(prop => { | |
const currentValue = _.get(obj, prop); | |
_.set(obj, prop, currentValue ? ensureObjectId(currentValue) : new ObjectId()); | |
}); | |
return obj; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment