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

@@ -14,11 +14,70 @@ router.post('/restart-wa', async (req, res) => {
router.post('/reminder-sparepart/:id', async (req, res) => {
try {
const { id } = req.params;
const result = await NotifikasiWaService.onMonthlySparepartReminder(id);
const result = await NotifikasiWaService.onMonthlyReminder(id);
return res.status(200).json(result);
} catch (error) {
return res.status(500).json(error);
}
});
router.post('/reminder-custom/:id', async (req, res) => {
try {
const { id } = req.params;
const {start_date, end_date} = req.body;
const result = await NotifikasiWaService.onCustomReminder(id, start_date, end_date);
return res.status(200).json(result);
} catch (error) {
return res.status(500).json(error);
}
});
router.get('/cron/jobs', async (req, res) => {
try {
const activeJobs = NotifikasiWaService.getActiveCronJobs();
return res.status(200).json({
success: true,
total: activeJobs.length,
jobs: activeJobs
});
} catch (error) {
return res.status(500).json({
success: false,
message: error.message
});
}
});
router.delete('/cron/jobs/:deviceId', async (req, res) => {
try {
const { deviceId } = req.params;
NotifikasiWaService.stopCronJob(deviceId);
return res.status(200).json({
success: true,
message: `Cron job untuk device ${deviceId} dihentikan`
});
} catch (error) {
return res.status(500).json({
success: false,
message: error.message
});
}
});
// Endpoint untuk menghentikan semua cron job
router.delete('/cron/jobs', async (req, res) => {
try {
NotifikasiWaService.stopAllCronJobs();
return res.status(200).json({
success: true,
message: 'Semua cron job dihentikan'
});
} catch (error) {
return res.status(500).json({
success: false,
message: error.message
});
}
});
module.exports = router;