Cast to ObjectId failed for value “{ id: 61141a8345c9ba4338f2af20 }” (type Object) at path “_id” for model “LeaveTypes”

hello fellas i was trying to create HRM project using node and mongodb (mongoose) with leave management so for the leave i have created two documents 1. for leavetypes i.e anualLeave , maternityLeave and so on and the other one of taking care of the leave requests taken by the employees so here is my schemas and api requests


// leave schema embedded in leaveTypeSchema
const mongoose = require(“mongoose”);
const Joi = require(“joi-browser”);
Joi.objectId = require(“joi-objectid”)(Joi);

const { branchSchema } = require("./branch");
const { employeeSchema } = require("./employee");
const { leaveTypesSchema } = require("./leaveType");

const leaveSchema = mongoose.Schema({
branch: {
type: branchSchema,
required: true,
},
employee: {
type: employeeSchema,
required: true,
},
leaveType: {
type: [leaveTypesSchema],
required: true,
},
daysRequested: {
type: Number,
required: true,
},

fromDate: {
type: Date,
required: true,
},
endDate: {
type: Date,
required: true,
},
availableDays: {
type: Number,
},
});

const Leave = mongoose.model(“leave”, leaveSchema);

//validation

function validateLeave(leave) {
const schema = {
branchId: Joi.objectId().required(),
employeeId: Joi.objectId().required(),
leaveType: Joi.object()
.keys({
anualLeave: Joi.object()
.keys({
id: Joi.objectId().required(),
})
.required(),
})
.required(),
daysRequested: Joi.number().required(),
fromDate: Joi.date().required(),
endDate: Joi.date().required(),
};
return Joi.validate(leave, schema);
}

module.exports.Leave = Leave;
module.exports.Validate = validateLeave;

//route to post leave requests from employees

router.post("/", async (req, res) => {
// validate
const { error } = Validate(req.body);
if (error) return res.status(400).send(error.details[0].message);
// check if branch is valid
let branch = await Branch.findById(req.body.branchId);
if (!branch) return res.status(400).send(“Invalid Branch”);
// check if employee is valid
let employee = await Employee.findById(req.body.employeeId);
if (!employee) return res.status(400).send(“Invalid employee”);
// check if leaveType is valid
let leaveType = await LeaveType.findById({
id: ObjectID(req.body.leaveType.anualLeave.id),
});
if (!leaveType) return res.status(400).send(“invalid leave Type”);
// post the leave request

const leave = new Leave({
branch: {
_id: branch._id,
name: branch.name,
},

employee: {

_id: employee._id,
fullName: employee.fullName,
phoneNumber: employee.phoneNumber,
branch: {
_id: branch._id,
name: branch.name,
},
jobTitle: employee.jobTitle,
salary: employee.salary,
},
leaveType: [
{
anualLeave: {
id: leaveType.anualLeave.id,
},
},
],
daysRequested: req.body.daysRequested,
fromDate: req.body.fromDate,
endDate: req.body.endDate,

});
await leave.save();
res.send(leave);