-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathcve-id.middleware.js
More file actions
36 lines (31 loc) · 1.04 KB
/
cve-id.middleware.js
File metadata and controls
36 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/**
* @module controller/cve-id/middleware
*/
const { validationResult } = require('express-validator')
const errors = require('./error')
const error = new errors.CveIdControllerError()
const utils = require('../../utils/utils')
function parseGetParams (req, res, next) {
utils.reqCtxMapping(req, 'query', ['page', 'state', 'cve_id_year', 'time_reserved.lt', 'time_reserved.gt', 'time_modified.lt', 'time_modified.gt'])
utils.reqCtxMapping(req, 'params', ['id'])
next()
}
function parsePostParams (req, res, next) {
utils.reqCtxMapping(req, 'query', ['state', 'amount', 'batch_type', 'short_name', 'cve_year', 'org'])
utils.reqCtxMapping(req, 'params', ['id', 'year'])
next()
}
function parseError (req, res, next) {
const err = validationResult(req).formatWith(({ location, msg, param, value, nestedErrors }) => {
return { msg: msg, param: param, location: location }
})
if (!err.isEmpty()) {
return res.status(400).json(error.badInput(err.array()))
}
next()
}
module.exports = {
parseGetParams,
parsePostParams,
parseError
}