Commit d94ba383 authored by Piyaphorn Arphornsri's avatar Piyaphorn Arphornsri

add db

parent 3e455993
const List = require("../../models/list");
const config = require("../../config");
createToken = id => {
return JWT.sign({ id }, config.JWT_SECRET);
};
exports.addlist = async (req, res) => {
try {
const addlistData = req.body;
......@@ -25,7 +21,7 @@ exports.getList = async (req, res) => {
try {
let list = await List.findAll();
res.status(200).send(list);
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
......@@ -35,12 +31,12 @@ exports.getList = async (req, res) => {
exports.deletelist = async (req, res) => {
try {
const listId = req.params.listId;
let list = await List.findOne({
await List.destroy({
where: {
id: listId
}
});
res.status(200).send(list.dataValues);
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
......@@ -55,7 +51,7 @@ exports.getListId = async (req, res) => {
id: listId
}
});
res.status(200).send(list.dataValues);
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
......
const Shop = require("../../models/shop");
const config = require("../../config");
createToken = id => {
return JWT.sign({ id }, config.JWT_SECRET);
exports.addShop = async (req, res) => {
try {
const addshopData = req.body;
console.log(addshopData);
await Shop.create(addshopData);
res.send("create");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.addShop = async (req, res) => {
try{
const shopData =req.body;
Shop.create(shopData);
}catch(err){
console.log(err);
res.sendStatus(401);
}
exports.getShop = async (req, res) => {
try {
let shop = await Shop.findAll();
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.deleteshop = async (req, res) => {
try {
const shopId = req.params.shopId;
await Shop.destroy({
where: {
id: shopId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.getShopId = async (req, res) => {
try {
const shopId = req.params.id;
let shop = await Shop.findOne({
where: {
id: shopId
}
});
res.status(200).send("success");
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
exports.updateShop = async (req, res) => {
try {
const shopData = req.body;
const id = req.params.id;
await Shop.update(shopData, { where: { id: id } });
res.status(200).send({ status: "done" });
} catch (err) {
console.log(err);
res.sendStatus(401);
}
};
......@@ -12,22 +12,22 @@ module.exports = db.sequelize.define("shops", {
type: Sequelize.INTEGER
},
timeopen: {
type: Sequelize.TIME
type: Sequelize.STRING
},
timeclose: {
type: Sequelize.TIME
type: Sequelize.STRING
},
address: {
type: Sequelize.STRING
type: Sequelize.TEXT
},
tel: {
type: Sequelize.STRING
},
detial: {
type: Sequelize.STRING
detail: {
type: Sequelize.TEXT
},
map: {
type: Sequelize.STRING
type: Sequelize.TEXT
},
type: {
type: Sequelize.ENUM(
......
const express = require("express");
const router = express.Router();
const authController = require("../../controllers/shop");
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.post("/shop", authController.shop);
module.exports = router;
......@@ -11,7 +11,7 @@ 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/shop', router.shop);
app.listen(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