Skip to content

Instantly share code, notes, and snippets.

@b-m-9
Created December 13, 2019 02:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save b-m-9/04fcacb8548d4ac2d010c80d25e9a7ac to your computer and use it in GitHub Desktop.
Save b-m-9/04fcacb8548d4ac2d010c80d25e9a7ac to your computer and use it in GitHub Desktop.
api_plugin for api-nodejs
const mongoose = require('mongoose');
module.exports = (API) => {
class _ObjectId {
constructor(len, options) {
this.name = 'ObjectID';
}
valid(v) {
if (!v || v === '' || typeof v !== 'string' || !mongoose.Types.ObjectId.isValid(v))
return {
success: false,
error: 'Value is not ObjectId'
};
return {success: true, value: v};
}
}
API.types.ObjectId = () => {
return new _ObjectId();
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment