-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (63 loc) · 1.9 KB
/
index.js
File metadata and controls
77 lines (63 loc) · 1.9 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
71
72
73
74
75
76
77
const express = require("express");
const {
updateCotdSheet,
updateCotdInfo,
updateCampaign,
getLeaderboard,
} = require("./controllers/sheetController");
const app = express();
app.use(express.json());
app.post("/cotd", async (req, res) => {
const { player, date, div, rank } = req.body;
if (!player || !date || !div || !rank) {
return res.status(400).json({ error: "Missing required parameters." });
}
try {
const result = await updateCotdSheet(player, date, div, rank);
res.json(result);
} catch (error) {
console.error("Error updating sheet: ", error);
res.status(500).json({ error: "Internal Server Error" });
}
});
app.post("/campaign", async (req, res) => {
const { player, track, time } = req.body;
if (!player || !track || !time) {
return res.status(400).json({ error: "Missing required parameters." });
}
try {
const result = await updateCampaign(player, track, time);
res.json(result);
} catch (error) {
console.error("Error updating sheet: ", error);
res.status(500).json({ error: "Internal Server Error" });
}
});
app.post("/cotdinfo", async (req, res) => {
const { track, type, date, playerCount } = req.body;
if (!track || !type || !date) {
return res.status(400).json({ error: "Missing required parameters." });
}
try {
const result = await updateCotdInfo(track, type, date, playerCount);
res.json(result);
} catch (error) {
console.error("Error updating sheet: ", error);
res.status(500).json({ error: "Internal Server Error" });
}
});
app.get("/lb", async (req, res) => {
try {
const result = await getLeaderboard();
res.json(result);
} catch (error) {
console.error("Error updating sheet: ", error);
res.status(500).json({ error: "Internal Server Error" });
}
});
app.get("/", (req, res) => {
res.send("ok");
});
app.listen(8080, () => {
console.log("Backend running on port 8080");
});