111 lines
3.0 KiB
JavaScript
111 lines
3.0 KiB
JavaScript
const {
|
|
getAllNotificationErrorLogDb,
|
|
getNotificationErrorLogByIdDb,
|
|
getNotificationErrorLogByNotificationErrorIdDb,
|
|
createNotificationErrorLogDb,
|
|
updateNotificationErrorLogDb,
|
|
deleteNotificationErrorLogDb
|
|
} = require('../db/notification_error_log.db');
|
|
|
|
const { getUserByIdDb } = require('../db/user.db');
|
|
const { ErrorHandler } = require('../helpers/error');
|
|
|
|
class NotificationErrorLogService {
|
|
// Get all Notification Error Logs
|
|
static async getAllNotificationErrorLog() {
|
|
try {
|
|
const results = await getAllNotificationErrorLogDb();
|
|
|
|
results.data.map(element => {
|
|
});
|
|
|
|
return results;
|
|
} catch (error) {
|
|
throw new ErrorHandler(error.statusCode, error.message);
|
|
}
|
|
}
|
|
|
|
// Get Notification Error Log by ID
|
|
static async getNotificationErrorLogById(id) {
|
|
try {
|
|
const result = await getNotificationErrorLogByIdDb(id);
|
|
|
|
if (!result) {
|
|
throw new ErrorHandler(404, 'Notification Error Log not found');
|
|
}
|
|
|
|
return result;
|
|
} catch (error) {
|
|
throw new ErrorHandler(error.statusCode, error.message);
|
|
}
|
|
}
|
|
|
|
// Create Notification Error Log
|
|
static async createNotificationErrorLog(data, userId) {
|
|
try {
|
|
if (!data || typeof data !== 'object') data = {};
|
|
|
|
let createdBy = null;
|
|
let contactPhone = data.contact_phone || null;
|
|
|
|
if (userId) {
|
|
try {
|
|
const user = await getUserByIdDb(userId);
|
|
|
|
if (user && user.user_id) {
|
|
createdBy = Number(user.user_id);
|
|
} else {
|
|
createdBy = null;
|
|
contactPhone = userId;
|
|
}
|
|
} catch (dbError) {
|
|
createdBy = null;
|
|
contactPhone = userId;
|
|
}
|
|
}
|
|
|
|
const store = {
|
|
notification_error_id: data.notification_error_id,
|
|
contact_phone: contactPhone,
|
|
notification_error_log_description: data.notification_error_log_description,
|
|
created_by: createdBy
|
|
};
|
|
|
|
const result = await createNotificationErrorLogDb(store);
|
|
|
|
return result;
|
|
} catch (error) {
|
|
throw new ErrorHandler(error.statusCode, error.message);
|
|
}
|
|
}
|
|
|
|
// Get Notification Error Log by notification_error_id
|
|
static async getNotificationErrorLogByNotificationErrorId(notificationErrorId) {
|
|
try {
|
|
const results = await getNotificationErrorLogByNotificationErrorIdDb(notificationErrorId);
|
|
|
|
return results;
|
|
} catch (error) {
|
|
throw new ErrorHandler(error.statusCode, error.message);
|
|
}
|
|
}
|
|
|
|
// Soft delete Notification Error Log
|
|
static async deleteNotificationErrorLog(id, userId) {
|
|
try {
|
|
const dataExist = await getNotificationErrorLogByIdDb(id);
|
|
|
|
if (!dataExist) {
|
|
throw new ErrorHandler(404, 'Notification Error Log not found');
|
|
}
|
|
|
|
const result = await deleteNotificationErrorLogDb(id, userId);
|
|
|
|
return result;
|
|
} catch (error) {
|
|
throw new ErrorHandler(error.statusCode, error.message);
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = NotificationErrorLogService; |