-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifyTicketReqBody.js
52 lines (37 loc) · 1.22 KB
/
verifyTicketReqBody.js
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
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* This file will contain the middlewares for validating the ticket request body
*/
const constants = require("../utils/constants");
validateTicketRequestBody = async (req, res, next) => {
//Validating the userName
if (!req.body.title) {
res.status(400).send({
message: "Failed! Title is not provided !"
});
return;
}
if (!req.body.description) {
res.status(400).send({
message: "Failed! Description is not provided !"
});
return;
}
next();
};
validateTicketStatus = async (req, res, next) => {
//Validateing the user type
const status = req.body.status;
const statusTypes = [constants.ticketStatus.open, constants.ticketStatus.closed, constants.ticketStatus.inProgress, constants.ticketStatus.blocked]
if (status && !statusTypes.includes(status)) {
res.status(400).send({
message: "status provided is invalid. Possible values CLOSED | BLOCKED | IN_PROGESS | OPEN "
});
return;
}
next();
}
const verifyTicketRequestBody = {
validateTicketRequestBody: validateTicketRequestBody,
validateTicketStatus: validateTicketStatus
};
module.exports = verifyTicketRequestBody