Showing
2 changed files
with
24 additions
and
0 deletions
... | @@ -28,7 +28,30 @@ database.addKeyword = async function(keyword, userId) { | ... | @@ -28,7 +28,30 @@ database.addKeyword = async function(keyword, userId) { |
28 | }) | 28 | }) |
29 | } | 29 | } |
30 | 30 | ||
31 | +database.deleteKeyword = async function(userId, keyword) { | ||
32 | + | ||
33 | + const u = await User.findOrCreate({ | ||
34 | + where: { | ||
35 | + userId: userId | ||
36 | + } | ||
37 | + }) | ||
38 | + | ||
39 | + const k = await Keyword.findOrCreate({ | ||
40 | + where: { | ||
41 | + keyword: keyword | ||
42 | + } | ||
43 | + }) | ||
44 | + | ||
45 | + await UserKeyword.destroy({ | ||
46 | + where: { | ||
47 | + userId: u[0].id, | ||
48 | + keywordId: k[0].id | ||
49 | + } | ||
50 | + }) | ||
51 | +} | ||
52 | + | ||
31 | database.getKeywordsByUserId = async function(userId) { | 53 | database.getKeywordsByUserId = async function(userId) { |
54 | + | ||
32 | const keywords = await Keyword.findAll({ | 55 | const keywords = await Keyword.findAll({ |
33 | attributes: ['keyword'], | 56 | attributes: ['keyword'], |
34 | where: { | 57 | where: { | ... | ... |
... | @@ -12,6 +12,7 @@ sequelize.sync({ force: false }) | ... | @@ -12,6 +12,7 @@ sequelize.sync({ force: false }) |
12 | console.log('database connection complete'); | 12 | console.log('database connection complete'); |
13 | database.addKeyword("rtx3060", "junseok") | 13 | database.addKeyword("rtx3060", "junseok") |
14 | database.getKeywordsByUserId("junseok") | 14 | database.getKeywordsByUserId("junseok") |
15 | + database.deleteKeyword("phobyjun", "rtx3080") | ||
15 | }) | 16 | }) |
16 | .catch((err) => { | 17 | .catch((err) => { |
17 | console.log('database connection failed'); | 18 | console.log('database connection failed'); | ... | ... |
-
Please register or login to post a comment