윤준석

ADD: function getting Users by keyword

...@@ -73,6 +73,29 @@ database.getKeywordsByUserId = async function(userId) { ...@@ -73,6 +73,29 @@ database.getKeywordsByUserId = async function(userId) {
73 return result 73 return result
74 } 74 }
75 75
76 +database.getUsersByKeyword = async function(keyword) {
77 +
78 + const users = await User.findAll({
79 + attributes: ['userId'],
80 + where: {
81 + '$keyword.keyword$': keyword
82 + },
83 + include: [{
84 + attributes: [],
85 + model: Keyword,
86 + as: 'keyword'
87 + }],
88 + raw: true
89 + })
90 +
91 + let result = []
92 + for (let i = 0; i < users.length; i++) {
93 + result.push(users[i].userId)
94 + }
95 +
96 + return result
97 +}
98 +
76 database.getAllUsers = async function() { 99 database.getAllUsers = async function() {
77 100
78 const users = await User.findAll({ 101 const users = await User.findAll({
......
...@@ -14,6 +14,7 @@ sequelize.sync({ force: false }) ...@@ -14,6 +14,7 @@ sequelize.sync({ force: false })
14 database.getKeywordsByUserId("junseok") 14 database.getKeywordsByUserId("junseok")
15 database.deleteKeyword("phobyjun", "rtx3080") 15 database.deleteKeyword("phobyjun", "rtx3080")
16 database.getAllUsers() 16 database.getAllUsers()
17 + database.getUsersByKeyword("rtx3060")
17 }) 18 })
18 .catch((err) => { 19 .catch((err) => {
19 console.log('database connection failed'); 20 console.log('database connection failed');
......