error: Joi.objectId is not a function TypeError: Joi.objectId is not a function
The other cases in the project where I am using .objectId are still working. I know that objectId is a separate npm package and that’s why we add it in the validation.js in the startup but I can’t seem to work out why it isn’t working inside of the rentals.js file.
There is a small change in Joi syntax which Mosh taught and what is currently there in Joi documentaion.
I have used the latest syntax, refer Joi documentation, ref: joi.dev - 17.5.0 API Reference
the above code will not work if you use .required() next to Joi.objectId.
without using required the code works fine, and it looks like in this case required in inbuilt in Joi-objectid.
Try removing .required() and change the Joi syntax, this should work for you.
I think something changed in the last 2 years here is a currently working solution
function validateReturn(req) {
const schema = Joi.object ({
customerId: Joi.string().hex().length(24),
movieId: Joi.string().hex().length(24)