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 21:43:47 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
aba9519e8e8ebacb45307b1d151f18007e82084f
aba9519e
1 parent
bafb6253
ADD: get Keywords by user id function
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
server/apis/database.js
server/app.js
server/models/index.js
server/apis/database.js
View file @
aba9519
...
...
@@ -27,3 +27,25 @@ database.addKeyword = async function(keyword, userId) {
}
})
}
database
.
getKeywordsByUserId
=
async
function
(
userId
)
{
const
keywords
=
await
Keyword
.
findAll
({
attributes
:
[
'keyword'
],
where
:
{
'$user.userId$'
:
userId
},
include
:
[{
attributes
:
[],
model
:
User
,
as
:
'user'
}],
raw
:
true
})
let
result
=
[]
for
(
let
i
=
0
;
i
<
keywords
.
length
;
i
++
)
{
result
.
push
(
keywords
[
i
].
keyword
)
}
return
result
}
...
...
server/app.js
View file @
aba9519
...
...
@@ -10,7 +10,8 @@ const database = require("./apis/database");
sequelize
.
sync
({
force
:
false
})
.
then
(()
=>
{
console
.
log
(
'database connection complete'
);
database
.
addKeyword
(
"rtx3080"
,
"phobyjun"
)
database
.
addKeyword
(
"rtx3060"
,
"junseok"
)
database
.
getKeywordsByUserId
(
"junseok"
)
})
.
catch
((
err
)
=>
{
console
.
log
(
'database connection failed'
);
...
...
server/models/index.js
View file @
aba9519
...
...
@@ -38,7 +38,7 @@ db.user = require("./user")(sequelize, Sequelize);
db
.
keyword
=
require
(
"./keyword"
)(
sequelize
,
Sequelize
);
db
.
userKeyword
=
sequelize
.
define
(
'user_keywords'
);
db
.
user
.
belongsToMany
(
db
.
keyword
,
{
through
:
db
.
userKeyword
});
db
.
keyword
.
belongsToMany
(
db
.
user
,
{
through
:
db
.
userKeyword
});
db
.
user
.
belongsToMany
(
db
.
keyword
,
{
through
:
db
.
userKeyword
,
as
:
'keyword'
});
db
.
keyword
.
belongsToMany
(
db
.
user
,
{
through
:
db
.
userKeyword
,
as
:
'user'
});
module
.
exports
=
db
;
...
...
Please
register
or
login
to post a comment