-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
97 lines (75 loc) · 1.75 KB
/
index.js
File metadata and controls
97 lines (75 loc) · 1.75 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import express from 'express';
import jwt from 'jsonwebtoken';
import crypto from 'node:crypto';
const secretKey = crypto.randomBytes(64).toString('hex');
const app = express();
app.use(express.json());
const users = [];
const expenses = [
{
title: 'YouTube Subscription',
price: 9.99,
date: new Date('10-1-2025')
},
{
title: 'Amazon Prime',
price: 4.99,
date: new Date('10-28-2025')
},
{
title: 'Groceries',
price: 129.99,
date: new Date('11-2-2025')
},
{
title: 'Groceries',
price: 129.99,
date: new Date('11-1-2025')
},
{
title: 'Groceries',
price: 129.99,
date: new Date('11-3-2025')
},
{
title: 'Robinhood Gold',
price: 19.99,
date: new Date('9-1-2025')
},
];
const categories = new Set([
'groceries', 'leisure',
'electronics', 'utilities',
'clothing', 'health',
'others'
]);
const timeframes = new Set([
'past-week', 'last-month', 'last-three-month'
]);
app.post('/register', async (req, res) => {
const { email, password } = req.body;
});
app.post('/login', async (req, res) => {
const { email, password } = req.body;
});
app.post('/expenses', async (req, res) => {
});
app.get('/expenses', authenticate, async (req, res) => {
const { page, limit, ...filters } = req.query;
return res.status(200).json({ data: expenses });
});
app.get('/expenses/:id', async (req, res) => {
});
app.put('/expenses/:id', async (req, res) => {
});
app.delete('/expenses/:id', async (req, res) => {
});
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log(`Server started on http://localhost:${port}`);
});
function authenticate(req, res, next) {
const token = req.headers.authorization?.split(' ')[1];
console.log(token);
next();
}