repair: sparepart controller & service
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user