-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidationHandler.js
More file actions
30 lines (26 loc) · 1.17 KB
/
ValidationHandler.js
File metadata and controls
30 lines (26 loc) · 1.17 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
const BaseHandler = require('./BaseHandler');
class ValidationHandler extends BaseHandler {
async handle(req, res, sendResponse) {
const { method, body } = req;
// Only validate creation/update payloads
if (method === 'POST' || method === 'PUT') {
if (body) {
if (body.title !== undefined && typeof body.title !== 'string') {
sendResponse(400, { error: 'Validation Error: Title must be a string' });
return false;
}
if (body.priority !== undefined && isNaN(Number(body.priority))) {
sendResponse(400, { error: 'Validation Error: Priority must be a valid number' });
return false;
}
if (body.dependencies !== undefined && !Array.isArray(body.dependencies)) {
sendResponse(400, { error: 'Validation Error: Dependencies must be an array of string IDs' });
return false;
}
}
}
// Validation passed! Pass responsibility.
return super.handle(req, res, sendResponse);
}
}
module.exports = ValidationHandler;