-
Notifications
You must be signed in to change notification settings - Fork 1
/
sweepReminders.js
44 lines (37 loc) · 1.31 KB
/
sweepReminders.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
37
38
39
40
41
42
43
44
const dotenv = require("dotenv");
dotenv.config();
var moment = require("moment");
var db = require("./db.js");
var wishlist = require("./wishlist.js")();
var helpers = require("./helpers.js");
async function main() {
let now = moment().utc();
let lastReset = {};
lastReset.weekly = moment().utc().startOf('isoWeek').add({days: 1, hours: 17});
if (now.day() < 2 || now.day() == 2 && now.hour() < 17) {
lastReset.weekly = lastReset.weekly.add(-1, 'week');
}
lastReset.daily = moment().utc().startOf('day').add(17, "h");
if (now.hour() < 17) {
lastReset.daily = lastReset.daily.add(-1, 'day');
}
var categories = {weekly: [], daily: []};
for (let category in wishlist) {
categories[wishlist[category].frequency].push(category);
}
var deleteQuery = "DELETE FROM " + helpers.getReminderTable() + " " +
"WHERE keep = 0 AND (" +
"category IN (?) AND sent_date < ? OR " +
"category IN (?) AND sent_date < ?" +
")";
const sql = db.format(deleteQuery, [
categories.weekly, lastReset.weekly.format("YYYY-MM-DD HH:mm:ss"),
categories.daily, lastReset.daily.format("YYYY-MM-DD HH:mm:ss")
]);
console.log(sql);
await db.query(deleteQuery, [
categories.weekly, lastReset.weekly.format("YYYY-MM-DD HH:mm:ss"),
categories.daily, lastReset.daily.format("YYYY-MM-DD HH:mm:ss")
]);
}
module.exports = main;