-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
96 lines (67 loc) · 2.83 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
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
import 'dotenv/config.js';
import express from 'express';
import {
makeCreateUserController,
makeGetUserByIdController,
makeUpdateUserController,
makeDeleteUserController,
makeGetUserBalanceController,
} from './src/factories/controllers/user.js';
import {
makeCreateTransactionController,
makeDeleteTransactionController,
makeGetTransactionsByUserIdController,
makeUpdateTransactionController,
} from './src/factories/controllers/transaction.js';
const app = express();
app.use(express.json());
app.get('/api/users/:userId', async (req, res) => {
const getUserByIdController = makeGetUserByIdController();
const { statusCode, body } = await getUserByIdController.execute(req);
res.status(statusCode).send(body);
});
app.get('/api/users/:userId/balance', async (req, res) => {
const getUserBalanceController = makeGetUserBalanceController();
const { statusCode, body } = await getUserBalanceController.execute(req);
res.status(statusCode).send(body);
});
app.post('/api/users', async (req, res) => {
const createUserController = makeCreateUserController();
const { statusCode, body } = await createUserController.execute(req);
res.status(statusCode).send(body);
});
app.patch('/api/users/:userId', async (req, res) => {
const updateUserController = makeUpdateUserController();
const { statusCode, body } = await updateUserController.execute(req);
res.status(statusCode).send(body);
});
app.delete('/api/users/:userId', async (req, res) => {
const deleteUserController = makeDeleteUserController();
const { statusCode, body } = await deleteUserController.execute(req);
res.status(statusCode).send(body);
});
app.get('/api/transactions', async (req, res) => {
const getTransactionsByUserIdController =
makeGetTransactionsByUserIdController();
const { statusCode, body } =
await getTransactionsByUserIdController.execute(req);
res.status(statusCode).send(body);
});
app.post('/api/transactions', async (req, res) => {
const createTransactionController = makeCreateTransactionController();
const { statusCode, body } = await createTransactionController.execute(req);
res.status(statusCode).send(body);
});
app.patch('/api/transactions/:transactionId', async (req, res) => {
const updateTransactionController = makeUpdateTransactionController();
const { statusCode, body } = await updateTransactionController.execute(req);
res.status(statusCode).send(body);
});
app.delete('/api/transactions/:transactionId', async (req, res) => {
const deleteTransactionController = makeDeleteTransactionController();
const { statusCode, body } = await deleteTransactionController.execute(req);
res.status(statusCode).send(body);
});
app.listen(process.env.PORT, () =>
console.log(`Listening on port ${process.env.PORT}`),
);