feat: implement reminder functionality and enhance notification service with logging
This commit is contained in:
@@ -69,6 +69,7 @@ const getDeviceByIdDb = async (id) => {
|
||||
SELECT
|
||||
a.*,
|
||||
b.brand_name,
|
||||
a.reminder_at AT TIME ZONE 'UTC' AT TIME ZONE 'SE Asia Standard Time' AS reminder_at_local,
|
||||
COALESCE(a.device_code, '') + ' - ' + COALESCE(a.device_name, '') AS device_code_name
|
||||
FROM m_device a
|
||||
LEFT JOIN m_brands b ON a.brand_id = b.brand_id
|
||||
@@ -124,10 +125,25 @@ const deleteDeviceDb = async (id, deletedBy) => {
|
||||
return true;
|
||||
};
|
||||
|
||||
const getDeviceReminderChanelDb = async (id) => {
|
||||
const queryText = `
|
||||
SELECT
|
||||
a.*,
|
||||
b.brand_name,
|
||||
COALESCE(a.device_code, '') + ' - ' + COALESCE(a.device_name, '') AS device_code_name
|
||||
FROM m_device a
|
||||
LEFT JOIN m_brands b ON a.brand_id = b.brand_id
|
||||
WHERE a.listen_channel_reminder = $1 AND a.deleted_at IS NULL
|
||||
`;
|
||||
const result = await pool.query(queryText, [id]);
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllDevicesDb,
|
||||
getDeviceByIdDb,
|
||||
createDeviceDb,
|
||||
updateDeviceDb,
|
||||
deleteDeviceDb,
|
||||
getDeviceReminderChanelDb
|
||||
};
|
||||
|
||||
@@ -61,6 +61,25 @@ const getDeviceNotificationByIdDb = async (chanel_id) => {
|
||||
return result.recordset[0];
|
||||
};
|
||||
|
||||
const getDeviceChannelReminder = async (chanel_reminder) => {
|
||||
const queryText = `
|
||||
SELECT
|
||||
brand_id,
|
||||
device_code,
|
||||
device_name,
|
||||
device_location,
|
||||
listen_channel,
|
||||
listen_channel_reminder,
|
||||
reminder_at,
|
||||
|
||||
FROM m_device
|
||||
WHERE listen_channel_reminder = $1
|
||||
AND deleted_at IS NULL
|
||||
`;
|
||||
const result = await pool.query(queryText, [chanel_reminder]);
|
||||
return result.recordset[0];
|
||||
};
|
||||
|
||||
|
||||
const getAllNotificationDb = async (searchParams = {}) => {
|
||||
let queryParams = [];
|
||||
@@ -202,12 +221,31 @@ const getUsersNotificationErrorDb = async (id) => {
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const getReminderNotificationErrorByYearlyDb = async (errorCode, chanel, year) => {
|
||||
const queryText = `
|
||||
SELECT a.*
|
||||
|
||||
FROM notification_error a
|
||||
|
||||
WHERE a.error_code_id = $1
|
||||
AND a.error_chanel = $2
|
||||
AND YEAR(a.created_at) = $3
|
||||
AND a.message_error_issue LIKE 'reminder%'
|
||||
AND a.deleted_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, [errorCode, chanel, year]);
|
||||
return result.recordset[0];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getNotificationByIdDb,
|
||||
getDeviceNotificationByIdDb,
|
||||
getAllNotificationDb,
|
||||
InsertNotificationErrorDb,
|
||||
updateNotificationErrorDb,
|
||||
getUsersNotificationErrorDb
|
||||
getUsersNotificationErrorDb,
|
||||
getDeviceChannelReminder,
|
||||
getReminderNotificationErrorByYearlyDb
|
||||
|
||||
};
|
||||
|
||||
@@ -179,6 +179,24 @@ const getSparepartsByIdsDb = async (sparepartIds) => {
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const getSparepartsByYearlyDb = async (yearly) => {
|
||||
|
||||
const queryText = `
|
||||
SELECT *
|
||||
FROM m_sparepart
|
||||
WHERE deleted_at IS NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM OPENJSON(sparepart_yearly)
|
||||
WHERE value = $1
|
||||
)
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, [yearly]);
|
||||
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllSparepartDb,
|
||||
getSparepartByIdDb,
|
||||
@@ -187,4 +205,5 @@ module.exports = {
|
||||
createSparepartDb,
|
||||
updateSparepartDb,
|
||||
deleteSparepartDb,
|
||||
getSparepartsByYearlyDb
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user