forked from rspacjer/notyfication-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck-items.js
36 lines (31 loc) · 826 Bytes
/
check-items.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
#!/usr/bin/env node
var pg = require('pg');
var sendgrid = require('sendgrid')(
process.env.SENDGRID_USERNAME,
process.env.SENDGRID_PASSWORD
);
pg.connect(process.env.DATABASE_URL, function(err, client, done) {
var handleError = function(err) {
if(!err) return false;
done(client);
next(err);
return true;
};
client.query('SELECT * FROM todos', function(err, result) {
if(handleError(err, client, done)) return;
if (result.rows.length > 0) {
sendgrid.send({
to: '[email protected]',
from: '[email protected]',
subject: 'There are some items to do',
text: 'You have items to do'
}, function(err, json) {
if (err) {
console.error(err);
}
done();
pg.end();
});
}
});
});