add: add notification

This commit is contained in:
2025-12-09 16:04:32 +07:00
parent d063478fc2
commit fb3061e0d1
5 changed files with 69 additions and 48 deletions

View File

@@ -1,12 +1,26 @@
const NotificationErrorService = require('../services/notification_error.service');
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
const NotificationErrorService = require("../services/notification_error.service");
const {
setResponse,
setResponsePaging,
checkValidate,
} = require("../helpers/utils");
const {
insertNotificationSchema,
updateNotificationSchema,
} = require("../validate/notification.schema");
class NotificationErrorController {
static async getAll(req, res) {
const queryParams = req.query;
const results = await NotificationErrorService.getAllNotification(queryParams);
const response = await setResponsePaging(queryParams, results, 'Notification found')
const results = await NotificationErrorService.getAllNotification(
queryParams
);
const response = await setResponsePaging(
queryParams,
results,
"Notification found"
);
res.status(response.statusCode).json(response);
}
@@ -15,11 +29,30 @@ class NotificationErrorController {
const { id } = req.params;
const results = await NotificationErrorService.getNotificationById(id);
const response = await setResponse(results, 'Notification retrieved successfully');
const response = await setResponse(
results,
"Notification retrieved successfully"
);
return res.status(response.statusCode).json(response);
}
static async create(req, res) {
const { error, value } = await checkValidate(insertNotificationSchema, req);
if (error) {
return res.status(400).json(setResponse(error, "Validation failed", 400));
}
value.userId = req.user.user_id;
const results = await NotificationErrorService.createNotificationError(
value
);
const response = await setResponse(results, "Notification created successfully");
return res.status(response.statusCode).json(response);
}
}
module.exports = NotificationErrorController;
module.exports = NotificationErrorController;