Compare commits

..

4 Commits

3 changed files with 54 additions and 55 deletions

View File

@@ -155,14 +155,15 @@ const getDeviceReminderMonthlyDb = async (id) => {
return result.recordset; return result.recordset;
}; };
const updateDeviceReminderMonthlyDb = async (deviceId, reminderMonthly) => { const updateDeviceReminderMonthlyDb = async (deviceId, reminderMonthly, period) => {
const queryText = ` const queryText = `
UPDATE m_device UPDATE m_device
SET reminder_at_monthly = $1, SET reminder_at_monthly = $1,
period = $2
updated_at = CURRENT_TIMESTAMP updated_at = CURRENT_TIMESTAMP
WHERE device_id = $2 AND deleted_at IS NULL WHERE device_id = $2 AND deleted_at IS NULL
`; `;
await pool.query(queryText, [reminderMonthly, deviceId]); await pool.query(queryText, [reminderMonthly, deviceId, period]);
return getDeviceByIdDb(deviceId); return getDeviceByIdDb(deviceId);
}; };

View File

@@ -1,8 +1,5 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const verifyToken = require("../middleware/verifyToken");
const verifyAccess = require("../middleware/verifyAccess");
const NotifikasiWaService = require('../services/notifikasi-wa.service'); const NotifikasiWaService = require('../services/notifikasi-wa.service');
router.post('/restart-wa', async (req, res) => { router.post('/restart-wa', async (req, res) => {
@@ -14,21 +11,21 @@ router.post('/restart-wa', async (req, res) => {
} }
}); });
router.post('/reminder-monthly/:id', verifyToken.verifyAccessToken, verifyAccess(), async (req, res) => { router.post('/reminder-monthly/:id', async (req, res) => {
try { try {
const { id } = req.params; const { id } = req.params;
const { reminder_at_monthly } = req.body; const {reminder_at_monthly, period} = req.body
const result = await NotifikasiWaService.onMonthlyReminder(id, reminder_at_monthly); const result = await NotifikasiWaService.onMonthlyReminder(id, reminder_at_monthly, period);
return res.status(200).json(result); return res.status(200).json(result);
} catch (error) { } catch (error) {
return res.status(500).json(error); return res.status(500).json(error);
} }
}); });
router.post('/reminder-custom/:id', verifyToken.verifyAccessToken, verifyAccess(), async (req, res) => { router.post('/reminder-custom/:id', async (req, res) => {
try { try {
const { id } = req.params; const { id } = req.params;
const { start_date, end_date } = req.body; const {start_date, end_date} = req.body;
const result = await NotifikasiWaService.onCustomReminder(id, start_date, end_date); const result = await NotifikasiWaService.onCustomReminder(id, start_date, end_date);
return res.status(200).json(result); return res.status(200).json(result);
} catch (error) { } catch (error) {
@@ -36,51 +33,52 @@ router.post('/reminder-custom/:id', verifyToken.verifyAccessToken, verifyAccess(
} }
}); });
// router.get('/cron/jobs', async (req, res) => { router.get('/cron/jobs', async (req, res) => {
// try { try {
// const activeJobs = NotifikasiWaService.getActiveCronJobs(); const activeJobs = NotifikasiWaService.getActiveCronJobs();
// return res.status(200).json({ return res.status(200).json({
// success: true, success: true,
// total: activeJobs.length, total: activeJobs.length,
// jobs: activeJobs jobs: activeJobs
// }); });
// } catch (error) { } catch (error) {
// return res.status(500).json({ return res.status(500).json({
// success: false, success: false,
// message: error.message message: error.message
// }); });
// } }
// }); });
// router.delete('/cron/jobs/:deviceId', async (req, res) => { router.delete('/cron/jobs/:deviceId', async (req, res) => {
// try { try {
// const { deviceId } = req.params; const { deviceId } = req.params;
// NotifikasiWaService.stopCronJob(deviceId); NotifikasiWaService.stopCronJob(deviceId);
// return res.status(200).json({ return res.status(200).json({
// success: true, success: true,
// message: `Cron job untuk device ${deviceId} dihentikan` message: `Cron job untuk device ${deviceId} dihentikan`
// }); });
// } catch (error) { } catch (error) {
// return res.status(500).json({ return res.status(500).json({
// success: false, success: false,
// message: error.message message: error.message
// }); });
// } }
// }); });
// router.delete('/cron/jobs', async (req, res) => { // Endpoint untuk menghentikan semua cron job
// try { router.delete('/cron/jobs', async (req, res) => {
// NotifikasiWaService.stopAllCronJobs(); try {
// return res.status(200).json({ NotifikasiWaService.stopAllCronJobs();
// success: true, return res.status(200).json({
// message: 'Semua cron job dihentikan' success: true,
// }); message: 'Semua cron job dihentikan'
// } catch (error) { });
// return res.status(500).json({ } catch (error) {
// success: false, return res.status(500).json({
// message: error.message success: false,
// }); message: error.message
// } });
// }); }
});
module.exports = router; module.exports = router;

View File

@@ -614,7 +614,7 @@ class NotifikasiWaService {
} }
async onMonthlyReminder(deviceId, reminderMonthly) { async onMonthlyReminder(deviceId, reminderMonthly, period) {
try { try {
const paramDb = { const paramDb = {