const mysql = require('../config/mysql');

module.exports.login = (username, password) => {
    return new Promise(async (resolve, reject) => {
        await mysql.db.query(`select u.id, u.username, u.password, concat(u.first_name, ' ', u.last_name) as name, u.status, group_concat(t.name) as type, t.piority from (select * from user as u where u.username = '${username.toLowerCase()}') as u join user_type as ut on u.id = ut.user_id join type as t on ut.type_id = t.id group by u.id`)
            .then(([result, fields]) => JSON.parse(JSON.stringify(result)))
            .then(result => resolve(result))
            .catch(error => reject(error));
    });
}