70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
const pool = require("../config");
|
|
|
|
const getAllNotificationErrorLogDb = async () => {
|
|
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.deleted_at IS NULL
|
|
ORDER BY a.notification_error_log_id DESC
|
|
`;
|
|
const result = await pool.query(queryText);
|
|
return result.recordset;
|
|
};
|
|
|
|
const getNotificationErrorLogByIdDb = async (id) => {
|
|
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_log_id = $1 AND a.deleted_at IS NULL
|
|
`;
|
|
const result = await pool.query(queryText, [id]);
|
|
return result.recordset[0];
|
|
};
|
|
|
|
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 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) => {
|
|
const queryText = `
|
|
UPDATE notification_error_log
|
|
SET deleted_at = CURRENT_TIMESTAMP, deleted_by = $1
|
|
WHERE notification_error_log_id = $2 AND deleted_at IS NULL
|
|
`;
|
|
await pool.query(queryText, [deletedBy, id]);
|
|
return true;
|
|
};
|
|
|
|
module.exports = {
|
|
getAllNotificationErrorLogDb,
|
|
getNotificationErrorLogByIdDb,
|
|
getNotificationErrorLogByNotificationErrorIdDb,
|
|
createNotificationErrorLogDb,
|
|
deleteNotificationErrorLogDb,
|
|
}; |