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