Toggle navigation
Toggle navigation
This project
Loading...
Sign in
윤준석
/
mamuri-bot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
윤준석
2022-05-24 01:41:42 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aa356ec83445a9bff352ba0ff17d93e49342021f
aa356ec8
1 parent
3653d890
ADD: keyword model
ADD: database connection and migration
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
3 deletions
server/app.js
server/models/index.js
server/models/keyword.js
server/models/user.js
server/app.js
View file @
aa356ec
...
...
@@ -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
)
...
...
server/models/index.js
View file @
aa356ec
...
...
@@ -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
;
...
...
server/models/keyword.js
0 → 100644
View file @
aa356ec
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
server/models/user.js
View file @
aa356ec
...
...
@@ -2,12 +2,12 @@ module.exports = (sequelize, DataTypes) => {
return
sequelize
.
define
(
"user"
,
{
id
:
{
type
:
DataTypes
.
INT
,
type
:
DataTypes
.
INT
EGER
,
autoIncrement
:
true
,
primaryKey
:
true
},
userId
:
{
type
:
DataTypes
.
INT
,
type
:
DataTypes
.
INT
EGER
,
allowNull
:
false
}
})
...
...
Please
register
or
login
to post a comment