윤준석

ADD: function getting Users by keyword

......@@ -73,6 +73,29 @@ database.getKeywordsByUserId = async function(userId) {
return result
}
database.getUsersByKeyword = async function(keyword) {
const users = await User.findAll({
attributes: ['userId'],
where: {
'$keyword.keyword$': keyword
},
include: [{
attributes: [],
model: Keyword,
as: 'keyword'
}],
raw: true
})
let result = []
for (let i = 0; i < users.length; i++) {
result.push(users[i].userId)
}
return result
}
database.getAllUsers = async function() {
const users = await User.findAll({
......
......@@ -14,6 +14,7 @@ sequelize.sync({ force: false })
database.getKeywordsByUserId("junseok")
database.deleteKeyword("phobyjun", "rtx3080")
database.getAllUsers()
database.getUsersByKeyword("rtx3060")
})
.catch((err) => {
console.log('database connection failed');
......