윤준석

ADD: keyword model

ADD: database connection and migration
......@@ -3,13 +3,28 @@ const line = require("@line/bot-sdk");
const setFlexMessage = require("./apis/setFlexMessage");
const fs = require("fs");
const { sequelize } = require('./models')
// Initialize DB connection
sequelize.sync({ force: false })
.then(() => {
console.log('database connection complete');
})
.catch((err) => {
console.log('database connection failed');
});
// Load .env configuration
require("dotenv").config();
const config = {
channelAccessToken: process.env.channelAccessToken,
channelSecret: process.env.channelSecret,
};
// Express app server initialization
const app = express();
// Create post request handler for chatbot
app.post("/webhook", line.middleware(config), (req, res) => {
Promise.all(req.body.events.map(handleEvent)).then((result) =>
res.json(result)
......
......@@ -34,6 +34,10 @@ Object.keys(db).forEach(modelName => {
db.sequelize = sequelize;
db.Sequelize = Sequelize;
db.user = require("./user")(sequelize, Sequelize)
db.user = require("./user")(sequelize, Sequelize);
db.keyword = require("./keyword")(sequelize, Sequelize);
db.user.belongsToMany(db.keyword, {through: 'user_keyword'});
db.keyword.belongsToMany(db.user, {through: 'user_keyword'});
module.exports = db;
......
module.exports = (sequelize, DataTypes) => {
return sequelize.define("keyword", {
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
keyword: {
type: DataTypes.STRING,
allowNull: false
}
})
}
\ No newline at end of file
......@@ -2,12 +2,12 @@ module.exports = (sequelize, DataTypes) => {
return sequelize.define("user", {
id: {
type: DataTypes.INT,
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true
},
userId: {
type: DataTypes.INT,
type: DataTypes.INTEGER,
allowNull: false
}
})
......