forked from ariabisri/ews_redmine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (32 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const schedule = require('node-schedule');
require('dotenv').config();
const db = require('./db');
const wa = require('./sendwa');
const today = new Date(Date.now());
const tomorrow = new Date(today);
tomorrow.setDate(tomorrow.getDate()+1);
tom = `${tomorrow.getFullYear()}-${(tomorrow.getMonth() + 1).toString().padStart(2, '0')}-${tomorrow.getDate().toString().padStart(2, '0')}`;
console.log("application running ..")
// console.log(tom)
// schedule job
schedule.scheduleJob(' 35 22 * * *', function(){
console.log('job start...')
async function sch()
{
const dt = await db.find('issue_logs', tom);
if (dt.length)
{
// dt.forEach(d => ns= wa.send(`${d.payload.user_terkait.hp}`, 'Redmine', 'issue besok due date'));
// console.log(d)
dt.forEach(async function(d) {
ns = await wa.send(`${d.payload.user_terkait.hp}`, 'Redmine', `Reminder: Due date issue [${d.payload.issue_id}]: ${d.payload.issue_subject}, project [${d.payload.project.project_name}] pada tanggal ${d.payload.due_date}`);
d.payload.status_notifikasi.ews = ns;
await db.update('issue_logs',d._id, d.payload.status_notifikasi)
// console.log(d)
});
}else{
console.log('tidak ada issue yang due date nya besok');
}
}
sch()
});