-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (33 loc) · 1000 Bytes
/
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
37
38
39
import datasource from './util/datasource'
import sms from './src/sms'
import service from './src/service'
import interval from 'interval-promise'
const db = datasource()
const model = db.models.notifications
const controller = service(model)
async function main() {
try {
const notifications = await controller.getAllToSend(5);
if (notifications !== undefined && notifications.length > 0) {
console.log(`Sending ${notifications.length} SMS`)
for (let index = 0; index < notifications.length; index++) {
const notification = notifications[index];
await sms().send(notification)
.then(() => {
controller.updateToSended(notification.id)
})
.catch(err => {
console.log('Could not send.')
console.error(err)
})
}
} else {
console.log('No SMS to send.')
}
} catch (error) {
console.error(error)
}
}
interval(async () => {
await main()
}, 5000)