-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
70 lines (50 loc) · 1.61 KB
/
index.js
File metadata and controls
70 lines (50 loc) · 1.61 KB
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
const express = require("express");
const getAuthSheets = require("./authentication/auth.js");
const bodyParser = require("body-parser");
const app = express();
// BodyParser
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
// Indica para o Express usar o EJS como View Engine
app.set('view engine', 'ejs');
// Indica para o Express onde ficarão os arquivos Estáticos
app.use(express.static('public'));
app.get("/", (req, res) => {
res.render('index.ejs');
});
app.get("/metadata", async (req, res) => {
const { googleSheets, auth, spreadsheetId } = await getAuthSheets();
const metadata = await googleSheets.spreadsheets.get({
auth,
spreadsheetId
});
res.send(metadata.data);
});
app.get("/getRows", async (req, res) => {
const { googleSheets, auth, spreadsheetId } = await getAuthSheets();
const getRows = await googleSheets.spreadsheets.values.get({
auth,
spreadsheetId,
range: "Leads",
valueRenderOption: "UNFORMATTED_VALUE",
dateTimeRenderOption: "FORMATTED_STRING"
});
res.send(getRows.data);
});
app.post("/addRow", async (req, res) => {
const { googleSheets, auth, spreadsheetId } = await getAuthSheets();
const { values } = req.body;
const row = await googleSheets.spreadsheets.values.append({
auth,
spreadsheetId,
range: "Leads",
valueInputOption: "USER_ENTERED",
resource: {
values: values,
},
});
res.send(row.data);
});
app.listen(3001, () => {
console.log("App rodando: http://localhost:3001 (Ctrl+Click)");
});