fix(auth): return rooms on login
This commit is contained in:
@ -115,6 +115,12 @@ export class AuthController {
|
|||||||
hrms.level_name = user.employee.position?.name || null
|
hrms.level_name = user.employee.position?.name || null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const query = `SELECT r.id, r.room, r.code
|
||||||
|
FROM rooms r
|
||||||
|
INNER JOIN user_to_room utr ON utr.room_id = r.id
|
||||||
|
WHERE utr.user_id = $1 AND r.deleted_at IS NULL AND utr.deleted_at IS NULL`
|
||||||
|
const rooms = await OrmHelper.DB.query(query, [user.id])
|
||||||
|
|
||||||
var privateKey = fs.readFileSync("src/helpers/key/private.key")
|
var privateKey = fs.readFileSync("src/helpers/key/private.key")
|
||||||
|
|
||||||
var token = jwt.sign(
|
var token = jwt.sign(
|
||||||
@ -127,6 +133,7 @@ export class AuthController {
|
|||||||
id_role: role_id,
|
id_role: role_id,
|
||||||
roles: roles.roles,
|
roles: roles.roles,
|
||||||
hrms: hrms,
|
hrms: hrms,
|
||||||
|
rooms: rooms,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
privateKey,
|
privateKey,
|
||||||
@ -136,7 +143,7 @@ export class AuthController {
|
|||||||
delete user.password
|
delete user.password
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
user: { ...user, ...hrms },
|
user: { ...user, ...hrms, rooms },
|
||||||
role_name: roles.name,
|
role_name: roles.name,
|
||||||
roles_list: await AuthController.getListRole(roles.roles),
|
roles_list: await AuthController.getListRole(roles.roles),
|
||||||
token: {
|
token: {
|
||||||
|
|||||||
@ -1131,20 +1131,19 @@ export class UserController {
|
|||||||
where: { id: param.id },
|
where: { id: param.id },
|
||||||
});
|
});
|
||||||
|
|
||||||
// get all the rooms from the usertoroom
|
|
||||||
// const repo = OrmHelper.DB.getRepository(UserToRoom);
|
|
||||||
|
|
||||||
// const rooms = await repo.createQueryBuilder('utr')
|
|
||||||
// .select('utr.id_room')
|
|
||||||
// .where('utr.user_id = :id', { id: param.id })
|
|
||||||
// .getMany();
|
|
||||||
|
|
||||||
const repoHospital = OrmHelper.DB.getRepository(HospitalInformation);
|
const repoHospital = OrmHelper.DB.getRepository(HospitalInformation);
|
||||||
const hospital = await repoHospital.findOne({ where: { id: Not(IsNull()) } });
|
const hospital = await repoHospital.findOne({ where: { id: Not(IsNull()) } });
|
||||||
|
|
||||||
if (detail != null) {
|
if (detail != null) {
|
||||||
|
const query = `SELECT r.id, r.room, r.code
|
||||||
|
FROM rooms r
|
||||||
|
INNER JOIN user_to_room utr ON utr.room_id = r.id
|
||||||
|
WHERE utr.user_id = $1 AND r.deleted_at IS NULL AND utr.deleted_at IS NULL`
|
||||||
|
const rooms = await OrmHelper.DB.query(query, [detail.id])
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
...detail,
|
...detail,
|
||||||
|
rooms: rooms,
|
||||||
signature: detail.signature ?? null,
|
signature: detail.signature ?? null,
|
||||||
file_signature: detail.signature ? buildFileUrl(detail.signature) : null,
|
file_signature: detail.signature ? buildFileUrl(detail.signature) : null,
|
||||||
profile: detail.profile_picture ?? null,
|
profile: detail.profile_picture ?? null,
|
||||||
|
|||||||
Reference in New Issue
Block a user