-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
87 lines (63 loc) · 2.36 KB
/
app.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
// connect to mongodb atlas
require("./config/database").connect();
const express = require("express");
// import controller
const userController = require("./controller/user.controller");
const itemController = require("./controller/item.controller");
const cartController = require("./controller/cart.controller");
const histController = require("./controller/history.controller");
const app = express();
// https://www.geeksforgeeks.org/express-js-express-json-function/
app.use(express.json());
const cors = require("cors");
app.use(cors());
const bodyParser = require("body-parser");
app.use(bodyParser.json());
app.use(
bodyParser.urlencoded({
extended: false,
})
);
//////////////////////////////////////////////////////////
// create user
app.post("/users/create", userController.createUser);
// update user
app.post("/users/:id", userController.updateUser);
// get all user
app.get("/users", userController.getAllUsers);
// get one user
app.get("/users/:uid", userController.getOneUser);
// login
app.post("/login", userController.login);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// get all items
app.get("/items", itemController.getAllItems);
// get one item
app.get("/items/id/:id", itemController.getOneItem);
// get all item in cart
app.get("/items/get/allitemincart", itemController.getAllItemInCart);
// search item
app.get("/items/category/:category", itemController.searchItems);
// search item2
app.get("/items/keyword/:keyword", itemController.searchItemsbyKeyword);
// promotion item
app.get("/items/promotion", itemController.promotionItems);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// get all carts
app.get("/carts", cartController.getAllCarts);
// get one carts
app.get("/carts/:uid", cartController.getOneCart);
// update carts
app.post("/carts/:uid", cartController.updateCart);
//////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// get all history
app.get("/history", histController.getAllHistory);
// get user history
app.get("/history/id/:uid", histController.getUserHistory);
// create history
app.post("/history/purchased", histController.createHistory);
//////////////////////////////////////////////////////////
module.exports = app;