Commit facece9b authored by Piyaphorn Arphornsri's avatar Piyaphorn Arphornsri

add db

parent 477af52a
/node_modules
\ No newline at end of file
module.exports = {
hostname: 'localhost',
username: 'piyaphorn',
password: 'zxcasdqwe',
database_name: 'b_beauty_project'
}
\ No newline at end of file
const User = require('../../models/user');
exports.getUserById = async (req, res) => {
try {
const userId = req.params.id;
const user = await User.findOne({
where: { id: userId }
});
res.status(200).send(user);
} catch (err) {
console.log(err)
res.sendStatus(401);
}
}
exports.register = async (req, res) => {
try {
const data = req.body;
await User.create(data)
res.status(200).send("Token");
} catch (err) {
console.log(err)
res.sendStatus(401);
}
}
\ No newline at end of file
const Sequelize = require('sequelize');
const config = require('./config');
const db = {};
const connect = new Sequelize(config.database_name, config.username, config.password, {
host: config.hostname,
dialect: 'mysql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
}
})
db.sequelize = connect
db.Sequelize = Sequelize
module.exports = db
\ No newline at end of file
var mysql = require("mysql");
var con = mysql.createConnection({
host: "localhost",
user: "root",
password: "",
database: "b_beauty_project"
});
con.connect(function(err) {
if (err) throw err;
console.log("Connected!");
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
bookingID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
userID: {
type: Sequelize.INTEGER
},
shopID: {
type: Sequelize.INTEGER
},
listID: {
type: Sequelize.INTEGER
},
bookingDete: {
type: Sequelize.STRING
},
bookingTime: {
type: Sequelize.STRING
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
listID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
slistName: {
type: Sequelize.STRING
},
listprice: {
type: Sequelize.INTEGER
},
listTime: {
type: Sequelize.STRING
},
shopID: {
type: Sequelize.INTEGER
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
promotionID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
promotionDete: {
type: Sequelize.STRING
},
shopID: {
type: Sequelize.INTEGER
},
promotionDetail: {
type: Sequelize.STRING
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
reviewsID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
reviewsTopic: {
type: Sequelize.INTEGER
},
reviewsMessage: {
type: Sequelize.STRING
},
reviewsPoint: {
type: Sequelize.INTEGER
},
reviewsPic: {
type: Sequelize.STRING
},
shopID: {
type: Sequelize.INTEGER
},
userID: {
type: Sequelize.INTEGER
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
shopID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
shopName: {
type: Sequelize.INTEGER
},
shopTimeopen: {
type: Sequelize.STRING
},
shopTimeClose: {
type: Sequelize.STRING
},
shopAddress: {
type: Sequelize.STRING
},
shopTel: {
type: Sequelize.STRING
},
shopDetial: {
type: Sequelize.STRING
},
shopMap: {
type: Sequelize.STRING
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define(
"users",
{
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
name: {
type: Sequelize.STRING
},
email: {
type: Sequelize.STRING
},
password: {
type: Sequelize.STRING
},
photo: {
type: Sequelize.STRING
},
},
);
\ No newline at end of file
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
userShopOwnerID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
userShopOwnerName: {
type: Sequelize.INTEGER
},
userShopOwnerEmail: {
type: Sequelize.STRING
},
userShopOwnerPassword: {
type: Sequelize.STRING
},
userShopOwnerAddress: {
type: Sequelize.STRING
}
});
const Sequelize = require("sequelize");
const db = require("../../db");
module.exports = db.sequelize.define("users", {
userbeauticianID: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
userbeauticianName: {
type: Sequelize.INTEGER
},
userbeauticianEmail: {
type: Sequelize.STRING
},
userbeauticianPassword: {
type: Sequelize.STRING
},
userbeauticianAddres: {
type: Sequelize.STRING
},
shopID: {
type: Sequelize.STRING
}
});
This diff is collapsed.
{
"name": "backend",
"version": "1.0.0",
"description": "",
"main": "server.js",
"dependencies": {
"body-parser": "^1.19.0",
"cors": "^2.8.5",
"express": "^4.17.1",
"mysql2": "^2.1.0",
"sequelize": "^5.21.3",
"util": "^0.12.1"
},
"devDependencies": {
"nodemon": "^2.0.2"
},
"scripts": {
"start": "node server.js",
"start-dev": "nodemon server.js"
},
"author": "",
"license": "ISC"
}
const express = require('express');
const router = express.Router();
const authController = require('../../controllers/auth');
router.get('/get', (req, res) => {
res.json({"test": "Test get"});
});
router.get('/getUserById/:id', authController.getUserById);
router.post('/register', authController.register);
module.exports = router;
\ No newline at end of file
const auth = require('./auth');
module.exports = {
auth
}
\ No newline at end of file
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.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