mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
25 lines
1.4 KiB
JavaScript
25 lines
1.4 KiB
JavaScript
/***********************************************************************************************************************************************************************
|
|
* File Name: validate.middleware.js
|
|
* Type of Program: Middleware
|
|
* Description: express-validator result checker.
|
|
* Pairs with validators/*.validator.js — those files define the rules,
|
|
* this file intercepts the request if any rule failed and returns 422.
|
|
* Author: rgrgogu
|
|
* Date Created: Oct. 6, 2025
|
|
***********************************************************************************************************************************************************************
|
|
* HOW TO USE:
|
|
* const { registerValidator } = require('../../validators/auth.validator');
|
|
* const { validate } = require('../../middleware/validate.middleware');
|
|
* router.post('/register', ...registerValidator, validate, handler);
|
|
***********************************************************************************************************************************************************************/
|
|
const { validationResult } = require('express-validator');
|
|
const R = require('../utils/response.util');
|
|
|
|
const validate = (req, res, next) => {
|
|
const errors = validationResult(req);
|
|
if (!errors.isEmpty())
|
|
return R.validationError(res, errors.array());
|
|
next();
|
|
};
|
|
|
|
module.exports = { validate }; |