Search code examples
javascripttypescriptbackendjoi

JavaScript Joi error Property does not exist on type


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);

enter image description here


Solution

  • i figure out the error, so i just to a value

     const {error: err, value: val} = updatedBioScheme.validate(req.body);