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,10 +1,7 @@
const {
getAllNotificationDb,
getNotificationByIdDb,
insertNotificationDb,
updateNotificationDb,
deleteNotificationDb,
} = require('../db/notification.db');
} = require('../db/notification_error.db');
const {
getErrorCodeByIdDb,
@@ -98,49 +95,6 @@ class NotificationService {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async createNotification(data) {
try {
if (!data || typeof data !== 'object') data = {};
const result = await insertNotificationDb(data);
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async updateNotification(id, data) {
try {
if (!data || typeof data !== 'object') data = {};
const dataExist = await getNotificationByIdDb(id);
if (!dataExist || (Array.isArray(dataExist) && dataExist.length < 1)) {
throw new ErrorHandler(404, 'Notification not found');
}
const result = await updateNotificationDb(id, data);
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
static async deleteNotification(id, userId) {
try {
const dataExist = await getNotificationByIdDb(id);
if (!dataExist || (Array.isArray(dataExist) && dataExist.length < 1)) {
throw new ErrorHandler(404, 'Notification not found');
}
const result = await deleteNotificationDb(id, userId);
return result;
} catch (error) {
throw new ErrorHandler(error.statusCode, error.message);
}
}
}
module.exports = NotificationService;