Spaces:
Sleeping
Sleeping
Download src/middleware/validate.js from shard-c6/green-guard-api: direct link, hf CLI and curl.
- Browser
- Download file 555 Bytes
-
https://huggingface.co/spaces/shard-c6/green-guard-api/resolve/main/src/middleware/validate.js
- Command line
-
hf download hf://spaces/shard-c6/green-guard-api/src/middleware/validate.js
-
curl -L -o validate.js https://huggingface.co/spaces/shard-c6/green-guard-api/resolve/main/src/middleware/validate.js
555 Bytes
| const { validationResult } = require('express-validator'); | |
| const { error } = require('../utils/response'); | |
| /** | |
| * Runs express-validator checks and returns 400 with error details if invalid. | |
| * Usage: router.post('/route', [...validators], validate, controller); | |
| */ | |
| function validate(req, res, next) { | |
| const errors = validationResult(req); | |
| if (!errors.isEmpty()) { | |
| const messages = errors.array().map((e) => `${e.path}: ${e.msg}`); | |
| return error(res, messages.join('; '), 400, 'VALIDATION_ERROR'); | |
| } | |
| next(); | |
| } | |
| module.exports = validate; | |