add: feature reminder custom device with cron-job

This commit is contained in:
2026-06-23 21:59:02 +07:00
parent da8cdcb705
commit 8fd317083b
5 changed files with 692 additions and 137 deletions

View File

@@ -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,
};