-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (31 loc) · 1009 Bytes
/
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
const express = require("express");
const bodyParser = require("body-parser");
const errorHandling = require("./middleware/errorHandling");
const WithdrawalService = require("./services/withdrawalService");
require("dotenv").config();
const app = express();
const port = 3000;
const withdrawalService = new WithdrawalService();
app.use(bodyParser.json());
app.post("/withdrawals", async (req, res, next) => {
try {
const { serializable = false } = req.query;
const { amount, user } = req.body;
const executeUsingSerializableIsolationLevel = serializable === "true";
const newWithdrawal = await withdrawalService.handleWithdrawalRequest(
{
amount,
user,
},
executeUsingSerializableIsolationLevel
);
return res.status(201).json(newWithdrawal);
} catch (error) {
next(error);
}
});
app.use(errorHandling);
const server = app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
module.exports = { server, app };