i am trying to validate my req.body from my api using Joi Property does not exist on type
here is my code
const idScheme = Joi.string().required();
const updatedBioScheme = Joi.object({
bio: Joi.string()
.min(3)
.required(),
});
export async function
updatedBio(req: Request, res: Response,) {
try {
const uid = req.query.uid;
const {err, val} = updatedBioScheme.validate(req.body);
const {error, value} = idScheme.validate(uid);
if (error) {
res.status(400).json({error: "Invalid uid parameter"});
return;
} else if (err) {
return res.status(400).json(err);
}
const userId = value;
const {bio}= val;
const inject = myContainer.get<ProfileServicesRepository>(TYPES.ProfileServices);
const data = await inject.updateBio(userId, bio);
if (data == undefined) {
return res.status(400).json({error: "User not available yet!!"});
}
return res.status(200).json({data, message: "Sucessful"});
} catch (error) {
return res.status(400).send({error, message: "error"});
}
}
i am getting the error from this const {err, val} = updatedBioScheme.validate(req.body);
2
Answers
i figure out the error, so i just to a value
According to Joi doc you have
value
,error
. Instead you try to extracterr
andval
which are non-existent on the object and TypeScript knows it.