-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (34 loc) · 1.35 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
/* eslint-disable indent */
require('dotenv').config()
const schedule = require('node-schedule')
const config = require('./config')
const fetchTransactions = (params) => require('./lib/fetch')(params)
const mailTransactions = (transactions, template, recipient) =>
require('./lib/mailer')(transactions, template, recipient)
const app =
process.env.NODE_ENV !== 'development'
? async () => {
schedule.scheduleJob({ hour: 10, minute: 0, second: 0 }, async () => {
const transactions = await fetchTransactions('sinceYesterday')
mailTransactions(transactions, 'daily', [config.emailRecipient1])
})
schedule.scheduleJob('1 10 1 * *', async () => {
const transactions = await fetchTransactions(
'sinceFirstDateOfThePreviousMonth'
)
mailTransactions(transactions, 'monthly', [config.emailRecipient1])
})
schedule.scheduleJob('2 10 * * 1', async () => {
const transactions = await fetchTransactions(
'sinceMondayOfThePreviousWeek'
)
mailTransactions(transactions, 'weekly', [config.emailRecipient1])
})
}
: async () => {
const transactions = await fetchTransactions(
'sinceMondayOfThePreviousWeek'
)
mailTransactions(transactions, 'weekly', [config.emailRecipient1])
}
app()