Created
December 13, 2019 02:45
-
-
Save package71/04fcacb8548d4ac2d010c80d25e9a7ac to your computer and use it in GitHub Desktop.
api_plugin for api-nodejs
This file contains hidden or 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
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