-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (68 loc) · 2.22 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express');
const bodyParser = require('body-parser');
var cors = require('cors');
const app = express();
var google = require('./google.js');
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(cors());
app.get('/', (req, res) => {
res.send('Hello World!');
});
app.post('/in/:docId', (req, res) => {
google.createSpreadsheet(createToken(req.body), req.params.docId).then(response => {
google.clockIn(createToken(req.body), req.body.timestamp, response.body.docId).then(response => {
res.status(response.code).send(response.body);
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
});
app.post('/out/:docId', (req, res) => {
google.createSpreadsheet(createToken(req.body), req.params.docId).then(response => {
google.clockOut(createToken(req.body), req.body.timestamp, response.body.docId).then(response => {
res.status(response.code).send(response.body);
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
});
app.post('/export/:docId', (req, res) => {
google.createSpreadsheet(createToken(req.body), req.params.docId).then(response => {
google.exportTimesheet(createToken(req.body), req.body.shifts, response.body.docId).then(response => {
res.status(response.code).send(response.body);
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
});
app.post('/spreadsheet/create', (req, res) => {
google.createSpreadsheet(createToken(req.body), '-1').then(response => {
res.status(response.code).send(response.body);
}).catch(err => {
console.log(err);
res.status(err.code).send(err.message);
});
});
app.listen(3000, () => {
console.log('App listening on port 3000!');
});
function createToken(body) {
return {
access_token: body.access_token,
refresh_token: body.refresh_token,
token_type: body.token_type
};
}