-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (50 loc) · 1.76 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
import express from 'express';
import cron from 'node-cron';
import { resetAppointments, createCustomer, login, setAppointment, getToken, getAllAppointments } from './services/queries.js'
import { authenticateToken } from './services/middleware.js';
import cors from 'cors';
const app = express();
const port = 3000;
app.use(cors())
cron.schedule('36 10 * * *', async () => {
console.log("it's time");
await resetAppointments();
});
app.use(express.urlencoded({ extended: true }))
app.use(express.json({ extended: true }))
app.get('/', async (req, res) => {
console.log(req.name);
res.send('Invalid route');
})
app.post('/signUp', async (req, res) => {
console.log(req.body);
createCustomer(req);
// res.send()
})
//TODO: Reorganize HTML table queries data API (Part B + C)
//Part 2, B - Admin login
app.get('/admin-login', async (req, res) => {
await getAllAppointments(res);
//const { customerName, appointmentTime} = req.body;
//console.log(res);
//console.log(req.body);
})
app.post('/login', async (req, res) => {
await login(req, res);
})
app.post('/set-appointment', authenticateToken, async (req, res) => {
let token = req.headers["x-api-token"];
//let token2 = req.headers.x-api-token[7];//unsure
//console.log("Header request: " + JSON.stringify(req.headers.x-api-token)); //? Debug
console.log("Header request token: " + JSON.stringify(token)); //? Debug
//console.log("Header request token2: " + JSON.stringify(token2)); //? Debug
console.log(JSON.stringify(req.body));
res.send(req.authenticateMessage);
await setAppointment(req.body, token);
})
app.get('/get-token', async (req, res) => { //? Temporary quick check token
await getToken(req,res);
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})