Skip to content

Commit

Permalink
Merge pull request #15 from mother/hydate-object-ids
Browse files Browse the repository at this point in the history
Hydrate ObjectIds when parsing cursor string
  • Loading branch information
asabhaney authored Aug 10, 2021
2 parents 0cbebfa + 2039e12 commit bf240c7
Show file tree
Hide file tree
Showing 4 changed files with 1,887 additions and 3,187 deletions.
4 changes: 3 additions & 1 deletion lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ exports.parseCursorStr = (cursorStr, schema) => {
// This could be made more modular in the future if there
// is a need to hydrate other types.
const schemaPath = schema.path(cursorKey)
if (typeof schemaPath === 'object' && schemaPath.instance === 'Date') {
if (typeof schemaPath === 'object' && schemaPath.instance === 'ObjectID') {
cursorObj[cursorKey] = new mongoose.Types.ObjectId(cursorObj[cursorKey])
} else if (typeof schemaPath === 'object' && schemaPath.instance === 'Date') {
cursorObj[cursorKey] = new Date(cursorObj[cursorKey])
}
})
Expand Down
Loading

0 comments on commit bf240c7

Please sign in to comment.