chentsulin / koa-context-validator

A robust context validator for koajs. Use Joi behind the scenes.
MIT License
54 stars 3 forks source link

I'm getting this error: TypeError: validator is not a function #32

Open juanpablopiano opened 2 years ago

juanpablopiano commented 2 years ago

I'm using this library to validate the body of the request using koa-router library. This is the code of one of the routes

import Router from 'koa-router';
import { getOneMovieController, getAllMoviesController, updatePlotController } from '../Controllers/movie.js';
import validator from 'koa-context-validator';
import { updatePlotSchema } from '../Validations/movie.js';

const router = new Router({
    prefix: '/api/v1/movie',
});

// Get one movie Route
router.get('/get-one/:title', getOneMovieController);

// Get all movies Route
router.get('/get-all', getAllMoviesController);

// Update a movie plot Route
router.post('/update-plot', validator(updatePlotSchema), updatePlotController);

export default router;

The part where I'm trying to use the validator function with the updatePlotSchema is giving me this error as in the validate funcion does not exist

fewbadboy commented 6 months ago

log the validator, the validator.default is the default export. use validator.default to call, can resolve this problem.

why the ES6 export default in here can't work 😭