Moved validation to the controller.
This commit is contained in:
1 parent
8409571d57
commit
55c1a1c233
2 files changed
+26
-32
No files matched your search
@@ -1,6 +1,5 @@
|
||||
import express from 'express';
|
||||
import { verifyJWT } from '../middleware/verifyJWT.js';
|
||||
import { triggerNotificationBodyValidation } from '../validation/joi.js';
|
||||
|
||||
class NotificationRoutes {
|
||||
constructor(notificationController) {
|
||||
@@ -9,33 +8,10 @@ class NotificationRoutes {
|
||||
this.initializeRoutes();
|
||||
}
|
||||
|
||||
validateRequest(schema) {
|
||||
return (req, res, next) => {
|
||||
const { error } = schema.validate(req.body, {
|
||||
abortEarly: false,
|
||||
stripUnknown: true
|
||||
});
|
||||
|
||||
if (error) {
|
||||
const errorMessage = error.details
|
||||
.map(detail => detail.message)
|
||||
.join(', ');
|
||||
|
||||
return res.status(400).json({
|
||||
success: false,
|
||||
msg: errorMessage
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
};
|
||||
}
|
||||
|
||||
initializeRoutes() {
|
||||
this.router.post(
|
||||
'/trigger',
|
||||
verifyJWT,
|
||||
this.validateRequest(triggerNotificationBodyValidation),
|
||||
this.notificationController.triggerNotification
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user