repair: notification error

This commit is contained in:
2025-11-25 10:10:29 +07:00
parent fd07481fb0
commit 6de0d5d149
7 changed files with 63 additions and 174 deletions

View File

@@ -1,80 +0,0 @@
const NotificationService = require('../services/notification.service');
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
const { insertNotificationSchema, updateNotificationSchema } = require('../validate/notification.schema');
class NotificationController {
static async getAll(req, res) {
const queryParams = req.query;
const results = await NotificationService.getAllNotification(queryParams);
const response = await setResponsePaging(queryParams, results, 'Notification found')
res.status(response.statusCode).json(response);
}
static async getById(req, res) {
try {
const { id } = req.params;
const results = await NotificationService.getNotificationById(id);
const response = await setResponse(results, 'Notification retrieved successfully');
return res.status(response.statusCode).json(response);
} catch (err) {
console.error(" Notification Error:", err.message);
return res.status(500).json(setResponse(err, 'Failed to fetch notification', 500));
}
}
static async create(req, res) {
try {
const { error, value } = await checkValidate(insertNotificationSchema, req);
if (error) {
return res.status(400).json(setResponse(error, 'Validation failed', 400));
}
value.created_by = req.user?.user_id || 'system';
const results = await NotificationService.createNotification(value);
const response = await setResponse(results, 'Notification created successfully');
return res.status(response.statusCode).json(response);
} catch (err) {
console.error("Notification Error:", err.message);
return res.status(500).json(setResponse(err, 'Failed to create notification', 500));
}
}
static async update(req, res) {
try {
const { id } = req.params;
const { error, value } = await checkValidate(updateNotificationSchema, req);
if (error) {
return res.status(400).json(setResponse(error, 'Validation failed', 400));
}
value.updated_by = req.user?.user_id || 'system';
const results = await NotificationService.updateNotification(id, value);
const response = await setResponse(results, 'Notification updated successfully');
return res.status(response.statusCode).json(response);
} catch (err) {
console.error("Notification Error:", err.message);
return res.status(500).json(setResponse(err, 'Failed to update notification', 500));
}
}
static async delete(req, res) {
try {
const { id } = req.params;
const results = await NotificationService.deleteNotification(id, req.user?.user_id || 'system');
const response = await setResponse(results, 'Notification deleted successfully');
return res.status(response.statusCode).json(response);
} catch (err) {
console.error("Notification Error:", err.message);
return res.status(500).json(setResponse(err, 'Failed to delete notification', 500));
}
}
}
module.exports = NotificationController;

View File

@@ -0,0 +1,25 @@
const NotificationErrorService = require('../services/notification_error.service');
const { setResponse, setResponsePaging, checkValidate } = require('../helpers/utils');
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')
res.status(response.statusCode).json(response);
}
static async getById(req, res) {
const { id } = req.params;
const results = await NotificationErrorService.getNotificationById(id);
const response = await setResponse(results, 'Notification retrieved successfully');
return res.status(response.statusCode).json(response);
}
}
module.exports = NotificationErrorController;