-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
71 lines (56 loc) · 1.69 KB
/
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
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
import express from "express";
import { collection, doc, getDoc, where, query, getDocs } from "firebase/firestore";
import { db } from "./firebase";
require('dotenv').config()
const app = express();
const PORT = process.env.PORT || 4200;
app.set("view engine", "pug");
app.get("/teams/ticket/:id", async (req, res) => {
try{
let id = req.params.id;
if(id.trim().length === 0) {
res.sendStatus(400);
return;
}
let teamsRef = collection(db, "teams");
let q = query(teamsRef, where("number", "==", parseInt(id)));
let querySnap = await getDocs(q);
if(querySnap.empty){
res.sendStatus(404);
return;
}
let doc = querySnap.docs[0];
res.render("ticket", {
image_src: doc.get("ticket_url"),
team_name: doc.get("team_name"),
});
}catch(e){
console.error(e);
res.sendStatus(500);
}
})
app.get("/awareness-session/ticket/:id", async (req, res) => {
try{
let id = req.params.id;
if(id.trim().length === 0) {
res.sendStatus(400);
return;
}
let teamsRef = collection(db, "awareness_session");
let q = query(teamsRef, where("number", "==", parseInt(id)));
let querySnap = await getDocs(q);
if(querySnap.empty){
res.sendStatus(404);
return;
}
let doc = querySnap.docs[0];
res.render("awareness", {
image_src: doc.get("ticket_url"),
});
}catch(e){
res.sendStatus(500);
}
})
app.listen(PORT, () => {
console.log(`Listening on ${PORT}`);
})