2.0.1 • Published 4 years ago

joi-mongoose-objectid v2.0.1

Weekly downloads
3
License
MIT
Repository
-
Last release
4 years ago

joi-mongoose-objectid

Joi extension to validate MongoDB objectId with mongoose

use

joi-mongoose-objectid give you the Joi.objectId() function that validate the input with mongoose.Types.ObjectId.isValid(value).

It is a Joi extension so you should extends Joi with it. Then you can extend Joi with other extensions.

let Joi = require('@hapi/joi');
const joiObjectIdExtension = require('joi-mongoose-objectid');

Joi = Joi.extend((Joi) => joiObjectIdExtension);

const schema = Joi.object({
  id: Joi.objectId(),
  name: Joi.string().max(100),
  date: Joi.date()
});

schema.validate();

Installation

npm install joi-mongoose-objectid

OR

yarn add joi-mongoose-objectid

Tests

There is two simple tests on the test.js file. One for success and one for failure. To run tests :

npm run test

OR

yarn test

License

MIT

2.0.1

4 years ago

2.0.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago