Validation Error: schema[parameter].validateAsync is not a function

I’m trying to create an API in express. When I call the same, I’m getting the above error.
I went through the GitHub links below which contain solutions to similar problems but none of them have worked for me. Below is my code which I hope is useful,

API:

http://localhost:4040/v1/trips/get-all-filtered?offset=0&limit=10&from=2021-01-28T00:00:00.175Z&to=2021-02-04T00:00:00.175Z&technicians=0faaa22e-d672-44f5-a30a-3b2e5298a967&status=trip_ended

Schema: (trip.validator.js)

const Joi = require('joi');

getAllFiltered: {
    query: Joi.object({
      offset: Joi.string(),
      limit: Joi.string(),
      from: Joi.string(),
      to: Joi.string(),
      technicians: Joi.array().items(Joi.string()),
      status: Joi.string(),
      enterprise_id: Joi.string(),
      payment_status: Joi.string().valid('pending', 'invoiced', 'paid')
    })
  }

Route: (trips.route.js)

let router = require('express').Router();
const { validate } = require('express-validation');
const tripValidation = require('../validators/trip.validator');
const tripController = require('../controllers/trip.controller');
const AuthMiddleware = require('../middlewares/auth.middleware')

router.get('/get-all-filtered', 
  [
    AuthMiddleware.isAuthorized,
    validate(tripValidation.getAllFiltered)
  ], 
  (req, res) => {
    tripController.getAllFiltered(req, res)
  }
)

Links:
https://github.com/AndrewKeig/express-validation/issues/122
https://github.com/sideway/joi/issues/2164

Kindly help.

8 thoughts on “Validation Error: schema[parameter].validateAsync is not a function”

  1. So, I figured out what was the problem. For some reason, the API endpoint was clashing with another. I just moved the API route from the bottom to the top and that seemed to fix the issue.

    Reply

Leave a Comment