Commit 7fff7e5b authored by Piyaphorn Arphornsri's avatar Piyaphorn Arphornsri

add db

parent 64ac1a89
const Booking = require("../../models/booking");
exports.addbooking = async (req, res) => {
try {
const addbookingData = req.body;
console.log(addbookingData);
await Booking.create(addbookingData);
res.send("create");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getBooking = async (req, res) => {
try {
let booking = await Booking.findAll();
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
const Review = require("../../models/reviews");
exports.addreview = async (req, res) => {
try {
const addreviewData = req.body;
console.log(addreviewData);
await Review.create(addreviewData);
res.send("create");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getReview = async (req, res) => {
try {
let review = await Review.findAll();
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.deleteReview = async (req, res) => {
try {
const reviewId = req.params.reviewId;
await Review.destroy({
where: {
id: reviewId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getReviewId = async (req, res) => {
try {
const reviewId = req.params.id;
let review = await Review.findOne({
where: {
id: reviewId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.updateReview = async (req, res) => {
try {
const reviewData = req.body;
const id = req.params.id;
await review.update(reviewData, { where: { id: id } });
res.status(200).send({ status: "done" });
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
......@@ -7,7 +7,7 @@ module.exports = db.sequelize.define("bookings", {
primaryKey: true,
autoIncrement: true
},
user: {
name: {
type: Sequelize.INTEGER,
references: 'users',
referencesKey: 'id'
......
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("reviwes", {
module.exports = db.sequelize.define("reviews", {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
......
const express = require("express");
const router = express.Router();
const bookingController = require("\../../controllers/booking");
router.post("/add", bookingController.addbooking);
router.get('/all', bookingController.getBooking);
module.exports = router;
const auth = require('./auth');
const list = require('./list');
const shop = require('./shop')
const promotion =require('./promotion');
const auth = require("./auth");
const list = require("./list");
const shop = require("./shop");
const promotion = require("./promotion");
const review = require("./review");
const booking = require("./booking");
module.exports = {
auth,
list,
shop,
promotion,
}
\ No newline at end of file
auth,
list,
shop,
promotion,
review,
booking
};
......@@ -7,8 +7,8 @@ const promotiomController = require("../../controllers/promotion");
router.post("/add",promotiomController.addpromotion);
router.get('/all',promotiomController.getPromotion);
router.delete('/delete/:promotionId',promotiomController.deletePromotion);
router.get('/getListId/:id',promotiomController.getPromotionId);
router.put('/updateList/id',promotiomController.updatePromotion);
router.get('/getPromotionId/:id',promotiomController.getPromotionId);
router.put('/updatePromotion/id',promotiomController.updatePromotion);
module.exports = router;
const express = require("express");
const router = express.Router();
const reviewController = require("../../controllers/review");
router.post("/add", reviewController.addreview);
router.get('/all', reviewController.getReview);
router.delete('/delete/:reviewId', reviewController.deleteReview);
router.get('/getReviewId/:id', reviewController.getReviewId);
router.put('/updateReview/id', reviewController.updateReview);
module.exports = router;
......@@ -6,8 +6,8 @@ const shopController = require("../../controllers/shop");
router.post("/add", shopController.addShop);
router.get('/all', shopController.getShop);
router.delete('/delete/:shopId',shopController.updateShop);
router.get('/getListId/:id',shopController.getShopId);
router.put('/updateList/id',shopController.updateShop);
router.get('/getShopId/:id',shopController.getShopId);
router.put('/updateshop/id',shopController.updateShop);
module.exports = router;
const express = require('express');
const router = require('./routers');
const cors = require('cors');
const bodyParser = require('body-parser');
const express = require("express");
const router = require("./routers");
const cors = require("cors");
const bodyParser = require("body-parser");
const port = process.env.PORT || 9000;
const app = express();
app.use(cors());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }))
app.use('/api/auth', router.auth);
app.use('/api/list', router.list);
app.use('/api/shop', router.shop);
app.use('/api/promotion', router.promotion);
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/api/auth", router.auth);
app.use("/api/list", router.list);
app.use("/api/shop", router.shop);
app.use("/api/promotion", router.promotion);
app.use("/api/review", router.review);
app.use("/api/booking", router.booking);
app.listen(port, () => {
console.log('Express server listening on port ' + port)
console.log("Express server listening on port " + port);
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment