add: reminder whatsapp sparepart monthly

This commit is contained in:
Muhammad Afif
2026-06-05 09:17:45 +07:00
parent 3d53bf4702
commit 40de826da9
6 changed files with 249 additions and 13 deletions

View File

@@ -139,11 +139,26 @@ const getDeviceReminderChanelDb = async (id) => {
return result.recordset;
};
const getDeviceReminderMonthlyDb = 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.device_id = $1 AND a.deleted_at IS NULL AND a.reminder_at_monthly IS NOT NULL
`;
const result = await pool.query(queryText, [id]);
return result.recordset;
};
module.exports = {
getAllDevicesDb,
getDeviceByIdDb,
createDeviceDb,
updateDeviceDb,
deleteDeviceDb,
getDeviceReminderChanelDb
getDeviceReminderChanelDb,
getDeviceReminderMonthlyDb
};

View File

@@ -255,6 +255,23 @@ const getReminderNotificationErrorByYearlyDb = async (errorCode, chanel, year) =
return result.recordset[0];
};
const getReminderNotificationErrorByMonthlyDb = async (errorCode, monthly) => {
const queryText = `
SELECT a.*
FROM notification_error a
WHERE a.error_code_id = $1
AND MONTH(a.created_at) = $2
AND a.message_error_issue LIKE 'reminder%'
AND a.is_active = 1
AND a.deleted_at IS NULL
`;
const result = await pool.query(queryText, [errorCode, monthly]);
return result.recordset[0];
};
module.exports = {
getNotificationByIdDb,
getDeviceNotificationByIdDb,
@@ -264,6 +281,7 @@ module.exports = {
getUsersNotificationErrorDb,
getDeviceChannelReminder,
getReminderNotificationErrorByYearlyDb,
getReminderNotificationErrorByMonthlyDb,
updateNotificationErrorByChanelReminderDb
};

View File

@@ -197,6 +197,24 @@ const getSparepartsByYearlyDb = async (yearly) => {
return result.recordset;
};
const getSparepartsByMonthlyDb = async (monthly) => {
const queryText = `
SELECT *
FROM m_sparepart
WHERE deleted_at IS NULL
AND EXISTS (
SELECT 1
FROM OPENJSON(sparepart_monthly)
WHERE value = $1
)
`;
const result = await pool.query(queryText, [monthly]);
return result.recordset;
};
module.exports = {
getAllSparepartDb,
getSparepartByIdDb,
@@ -205,5 +223,6 @@ module.exports = {
createSparepartDb,
updateSparepartDb,
deleteSparepartDb,
getSparepartsByYearlyDb
getSparepartsByYearlyDb,
getSparepartsByMonthlyDb
};