add: reader in notification detail & update notification

This commit is contained in:
2025-12-18 11:39:24 +07:00
parent f2c8c3818d
commit 1aa7b1bc08
5 changed files with 88 additions and 6 deletions

View File

@@ -22,6 +22,7 @@ const getNotificationByIdDb = async (id) => {
return result.recordset[0];
};
const getAllNotificationDb = async (searchParams = {}) => {
let queryParams = [];
@@ -122,9 +123,48 @@ const getAllNotificationDb = async (searchParams = {}) => {
return { data: result.recordset, total };
};
const updateNotificationErrorDb = async (id, data) => {
const store = { ...data };
const whereData = { notification_error_id: id };
const { query: queryText, values } = pool.buildDynamicUpdate(
"notification_error",
store,
whereData
);
await pool.query(`${queryText} AND deleted_at IS NULL`, values);
return getNotificationByIdDb(id);
};
const getReaderNotificationErrorDb = async (id) => {
const queryText = `
SELECT
a.notification_error_user_id,
a.contact_phone,
a.contact_name,
a.is_send,
b.notification_error_id,
b.error_code_id
FROM notification_error_user a
LEFT JOIN notification_error b ON a.notification_error_id = b.notification_error_id
WHERE a.notification_error_id = $1
AND a.is_send = 1
AND a.deleted_at IS NULL
`;
const result = await pool.query(queryText, [id]);
return result.recordset;
};
module.exports = {
getNotificationByIdDb,
getAllNotificationDb,
InsertNotificationErrorDb
InsertNotificationErrorDb,
updateNotificationErrorDb,
getReaderNotificationErrorDb
};