ObjectId extension for the Joi validation library
const JoiExtensionObjectId = require('@ciruxx/joi-extension-objectid');
const Joi = require('joi').extend(JoiExtensionObjectId);
const schema = Joi.object({
objectIdKey: Joi.objectId()
});
const validatedData = await schema.validateAsync({
objectIdKey: "5fd777d57fcb54c356763034"
})
data.objectIdKey instanceof ObjectID // true!