add: feature reminder custom device with cron-job
This commit is contained in:
@@ -63,7 +63,6 @@ const getAllDevicesDb = async (searchParams = {}) => {
|
||||
return { data: result.recordset, total };
|
||||
};
|
||||
|
||||
|
||||
const getDeviceByIdDb = async (id) => {
|
||||
const queryText = `
|
||||
SELECT
|
||||
@@ -116,12 +115,15 @@ const updateDeviceDb = async (id, data) => {
|
||||
};
|
||||
|
||||
const deleteDeviceDb = async (id, deletedBy) => {
|
||||
// Jika deletedBy adalah string, konversi ke integer atau gunakan default
|
||||
const deletedById = typeof deletedBy === 'string' ? parseInt(deletedBy) || 0 : deletedBy || 0;
|
||||
|
||||
const queryText = `
|
||||
UPDATE m_device
|
||||
SET deleted_at = CURRENT_TIMESTAMP, deleted_by = $1
|
||||
WHERE device_id = $2 AND deleted_at IS NULL
|
||||
`;
|
||||
await pool.query(queryText, [deletedBy, id]);
|
||||
await pool.query(queryText, [deletedById, id]);
|
||||
return true;
|
||||
};
|
||||
|
||||
@@ -153,6 +155,34 @@ const getDeviceReminderMonthlyDb = async (id) => {
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const getDeviceReminderCustomDb = 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
|
||||
`;
|
||||
const result = await pool.query(queryText, [id]);
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const updateDeviceReminderCustomDb = async (deviceId, startDate, endDate) => {
|
||||
const queryText = `
|
||||
UPDATE m_device
|
||||
SET start_date = $1,
|
||||
end_date = $2,
|
||||
updated_at = CURRENT_TIMESTAMP
|
||||
WHERE device_id = $3 AND deleted_at IS NULL
|
||||
`;
|
||||
await pool.query(queryText, [startDate, endDate, deviceId]);
|
||||
return getDeviceByIdDb(deviceId);
|
||||
};
|
||||
|
||||
|
||||
module.exports = {
|
||||
getAllDevicesDb,
|
||||
getDeviceByIdDb,
|
||||
@@ -160,5 +190,7 @@ module.exports = {
|
||||
updateDeviceDb,
|
||||
deleteDeviceDb,
|
||||
getDeviceReminderChanelDb,
|
||||
getDeviceReminderMonthlyDb
|
||||
};
|
||||
getDeviceReminderMonthlyDb,
|
||||
getDeviceReminderCustomDb,
|
||||
updateDeviceReminderCustomDb,
|
||||
};
|
||||
@@ -269,6 +269,22 @@ const getReminderNotificationErrorByMonthlyDb = async (errorCode, monthly, devic
|
||||
const result = await pool.query(queryText, [errorCode, monthly, deviceId]);
|
||||
return result.recordset[0];
|
||||
};
|
||||
|
||||
const getReminderNotificationErrorByCustomDb = async (errorCode, custom, deviceId) => {
|
||||
const queryText = `
|
||||
SELECT a.*
|
||||
FROM notification_error a
|
||||
WHERE a.error_code_id = $1
|
||||
AND a.created_at = $2
|
||||
AND a.message_error_issue LIKE '%device_id: ' + CAST($3 AS VARCHAR) + '%'
|
||||
AND a.is_active = 1
|
||||
AND a.deleted_at IS NULL
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, [errorCode, custom, deviceId]);
|
||||
return result.recordset[0];
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getNotificationByIdDb,
|
||||
getDeviceNotificationByIdDb,
|
||||
@@ -279,6 +295,7 @@ module.exports = {
|
||||
getDeviceChannelReminder,
|
||||
getReminderNotificationErrorByYearlyDb,
|
||||
getReminderNotificationErrorByMonthlyDb,
|
||||
getReminderNotificationErrorByCustomDb,
|
||||
updateNotificationErrorByChanelReminderDb
|
||||
|
||||
};
|
||||
|
||||
@@ -215,6 +215,24 @@ const getSparepartsByMonthlyDb = async (monthly) => {
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
const getSparepartsByCustomDb = async (custom) => {
|
||||
|
||||
const queryText = `
|
||||
SELECT *
|
||||
FROM m_sparepart
|
||||
WHERE deleted_at IS NULL
|
||||
AND EXISTS (
|
||||
SELECT 1
|
||||
FROM OPENJSON(sparepart_custom)
|
||||
WHERE value = $1
|
||||
)
|
||||
`;
|
||||
|
||||
const result = await pool.query(queryText, [custom]);
|
||||
|
||||
return result.recordset;
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
getAllSparepartDb,
|
||||
getSparepartByIdDb,
|
||||
@@ -224,5 +242,6 @@ module.exports = {
|
||||
updateSparepartDb,
|
||||
deleteSparepartDb,
|
||||
getSparepartsByYearlyDb,
|
||||
getSparepartsByMonthlyDb
|
||||
getSparepartsByMonthlyDb,
|
||||
getSparepartsByCustomDb
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user