Skip to content

Commit

Permalink
Allow ObjectId type
Browse files Browse the repository at this point in the history
  • Loading branch information
kamal0808 committed May 25, 2021
1 parent 71b2a8c commit 74cfb71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ module.exports = function joiObjectId(Joi, message) {
message = defaultMessage;
}
return function objectId() {
return Joi.string().regex(/^[0-9a-fA-F]{24}$/, message);
return Joi.alternatives(
Joi.string().regex(/^[0-9a-fA-F]{24}$/, message),
Joi.object().keys({
id: Joi.any(),
_bsontype: Joi.allow('ObjectId')
})
);
};
};
}

8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"test": "mocha -A"
},
"author": "Aaron Heckmann <aaron.heckmann+github@gmail.com>",
"author": "Kamal Khatwani <kamalkhatwani69@gmail.com>",
"license": "MIT",
"devDependencies": {
"@hapi/joi": "^16.0.1",
Expand All @@ -15,10 +15,10 @@
"dependencies": {},
"repository": {
"type": "git",
"url": "git+https://github.com/mkg20001/joi-objectid.git"
"url": "git+https://github.com/kamal0808/joi-objectid.git"
},
"bugs": {
"url": "https://github.com/mkg20001/joi-objectid/issues"
"url": "https://github.com/kamal0808/joi-objectid/issues"
},
"homepage": "https://github.com/mkg20001/joi-objectid#readme"
"homepage": "https://github.com/kamal0808/joi-objectid#readme"
}

0 comments on commit 74cfb71

Please sign in to comment.