add: notif error log

This commit is contained in:
2025-11-25 11:59:44 +07:00
parent 44107c9753
commit 78a813e9ec
6 changed files with 193 additions and 25 deletions

View File

@@ -1,23 +1,13 @@
const pool = require("../config");
const createNotificationErrorLogDb = async (data) => {
const store = {
notification_error_id: data.notification_error_id,
contact_id: data.contact_id,
notification_error_log_description: data.notification_error_log_description,
created_by: data.created_by
};
const { query: queryText, values } = pool.buildDynamicInsert("notification_error_log", store);
const result = await pool.query(queryText, values);
return result.recordset[0];
};
const getAllNotificationErrorLogDb = async () => {
const queryText = `
SELECT
a.*
a.*,
b.contact_name,
b.contact_type
FROM notification_error_log a
LEFT JOIN contact b ON a.contact_id = b.contact_id
WHERE a.deleted_at IS NULL
ORDER BY a.notification_error_log_id DESC
`;
@@ -28,23 +18,37 @@ const getAllNotificationErrorLogDb = async () => {
const getNotificationErrorLogByIdDb = async (id) => {
const queryText = `
SELECT
a.*
a.*,
b.contact_name,
b.contact_type
FROM notification_error_log a
LEFT JOIN contact b ON a.contact_id = b.contact_id
WHERE a.notification_error_log_id = $1 AND a.deleted_at IS NULL
`;
const result = await pool.query(queryText, [id]);
return result.recordset[0];
};
const updateNotificationErrorLogDb = async (id, data) => {
const store = { ...data };
const whereData = {
notification_error_log_id: id
};
const getNotificationErrorLogByNotificationErrorIdDb = async (notificationErrorId) => {
const queryText = `
SELECT
a.*,
b.contact_name,
b.contact_type
FROM notification_error_log a
LEFT JOIN contact b ON a.contact_id = b.contact_id
WHERE a.notification_error_id = $1 AND a.deleted_at IS NULL
ORDER BY a.created_at DESC
`;
const result = await pool.query(queryText, [notificationErrorId]);
return result.recordset;
};
const { query: queryText, values } = pool.buildDynamicUpdate("notification_error_log", store, whereData);
await pool.query(`${queryText} AND deleted_at IS NULL`, values);
return true;
const createNotificationErrorLogDb = async (store) => {
const { query: queryText, values } = pool.buildDynamicInsert("notification_error_log", store);
const result = await pool.query(queryText, values);
const insertedId = result.recordset[0]?.inserted_id;
return insertedId ? await getNotificationErrorLogByIdDb(insertedId) : null;
};
const deleteNotificationErrorLogDb = async (id, deletedBy) => {
@@ -58,9 +62,9 @@ const deleteNotificationErrorLogDb = async (id, deletedBy) => {
};
module.exports = {
createNotificationErrorLogDb,
getAllNotificationErrorLogDb,
getNotificationErrorLogByIdDb,
updateNotificationErrorLogDb,
getNotificationErrorLogByNotificationErrorIdDb,
createNotificationErrorLogDb,
deleteNotificationErrorLogDb,
};