-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (53 loc) · 1.61 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
const express = require("express");
const authenticate = require("./helpers/authenticate");
const createUser = require("./controllers/createUser");
const borrowBook = require("./controllers/borrowBook");
const checkBeforeBorrow = require("./controllers/checkBeforeBorrow");
const returnBook = require("./controllers/returnBook");
const searchBook = require("./controllers/searchBook");
const getBookInfo = require("./controllers/getBookInfo");
const { errorResObject } = require("./helpers/utils");
const app = express();
const port = process.env.PORT;
app.use(express.json());
app.post("/", authenticate, async (req, res) => {
try {
const { intent } = req.body;
if (intent.name === "사용자 등록하기") {
createUser(req, res);
return;
}
if (intent.name === "대출하기 - 대출 가능 여부 체크") {
checkBeforeBorrow(req, res);
return;
}
if (intent.name === "대출하기 - 대출 실행") {
borrowBook(req, res);
return;
}
if (intent.name === "반납하기 - 반납 가능 여부 체크") {
returnBook(req, res);
return;
}
if (intent.name === "반납하기 - 반납 실행") {
return;
}
if (intent.name === "검색하기 - 키워드") {
searchBook(req, res);
return;
}
if (intent.name === "검색하기 - 상세 정보") {
getBookInfo(req, res);
return;
}
if (intent.name === "검색하기 - 재검색") {
return;
}
} catch (err) {
console.log(err);
res.json(errorResObject);
}
});
app.listen(port, () => {
console.log(`Server listening at ${port}`);
});