I have a search query running on nodejs modal as I put below. I am getting users from this query to my app as JSON data like this.
{id, username, name, sirname, birthdate, weight, height, photo}
{id, username, name, sirname, birthdate, weight, height, photo}
But I need to get users talents from an other table . So my JSON data must be like this.
{
id: 1 {talentone : 'good', talenttwo : 'bad', talentthree : 'good'},
username, name, sirname, birthdate, weight, height, photo}
{
id:2 {talentone : 'good', talenttwo : 'bad', talentthree : 'good'},
username, name, sirname, birthdate, weight, height, photo}
id:3 {talentone : 'good', talenttwo : 'bad', talentthree : 'good'},
username, name, sirname, birthdate, weight, height, photo}
My talents table: id - userId, talentName, talentRate
My user search query and nodejs code :
Searchtalent.getAll =(searchtalent, result) => {
sql.query(`SELECT id, username, name, sirname, birthdate, weight, height, photo FROM users WHERE
user_type = 'sportsman'
AND (birthdate BETWEEN '${searchtalent.birthdatefirst}' AND '${searchtalent.birthdatelast}')
AND (weight BETWEEN ${searchtalent.wfirst} AND ${searchtalent.wsecond})
AND (height BETWEEN ${searchtalent.hfirst} AND ${searchtalent.hsecond})
AND lang LIKE '%${searchtalent.lang}%'
AND gender LIKE '%${searchtalent.gender}%'
AND username LIKE '%${searchtalent.username}%'
AND name LIKE '%${searchtalent.name}%'
AND sirname LIKE '%${searchtalent.sirname}%'
AND branch LIKE '%${searchtalent.branch}%'
AND branch_status LIKE '%${searchtalent.branch_status}%'
AND city LIKE '%${searchtalent.city}%'
AND foot LIKE '%${searchtalent.foot}%'
AND hand LIKE '%${searchtalent.hand}%'
AND first_position LIKE '%${searchtalent.first_position}%'
AND second_position LIKE '%${searchtalent.second_position}%'
AND nationality LIKE '%${searchtalent.nationality}%'
LIMIT 50` ,(err, res) => {
if (err) {
console.log("error: ", err);
result(err, null);
return;
}
if (res.length) {
console.log("found users: ", searchtalent);
result(null, res);
return;
}
// not found users with the id
result({ kind: "not_found" }, null);
});
};