-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
43 lines (34 loc) · 965 Bytes
/
index.ts
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
declare var process: any;
const PORT = Number(process.env.PORT) || 8080;
import * as express from "express";
import * as bodyParser from "body-parser";
const {Datastore} = require('@google-cloud/datastore');
const app = express();
const datastore = new Datastore();
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.send("Hello, World!");
});
app.post("/schedule/", (req, res) => {
let data = req.body;
let time = data.time;
let email = data.email;
let msg = data.msg;
datastore.save({
key: datastore.key('schedule'),
data
})
res.send("Sending message '" + msg + "' to " + email + " at " + time);
});
app.get("/execute/", async (req, res) => {
const query = datastore
.createQuery('schedule')
.order('time', {descending: true})
.limit(10);
const result = await datastore.runQuery(query);
console.log()
res.send(result);
});
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});