mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
chore: relocate backend into apps/api ahead of monorepo merge
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
/***********************************************************************************************************************************************************************
|
||||
* 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 };
|
||||
Reference in New Issue
Block a user