update auth response
This commit is contained in:
@ -112,18 +112,27 @@ export class AuthController {
|
||||
static async getListRole(roles: any): Promise<any> {
|
||||
const repoMenu = OrmHelper.DB.getRepository(Menu);
|
||||
|
||||
const whereAttr = "id in (:id_menu)";
|
||||
const whereVal = roles;
|
||||
const whereAttr = [];
|
||||
const whereVal = {};
|
||||
|
||||
for (let k in roles) {
|
||||
let p = roles[k];
|
||||
|
||||
whereAttr.push('id = :id' + k);
|
||||
whereVal['id' + k] = p;
|
||||
}
|
||||
|
||||
const res_list = repoMenu.createQueryBuilder()
|
||||
.where(whereAttr, whereVal)
|
||||
.where(whereAttr.join(' or '), whereVal)
|
||||
.andWhere('id_parent is null')
|
||||
.orderBy('order', 'ASC');
|
||||
.orderBy('order_number', 'ASC');
|
||||
|
||||
let list_data_final = await res_list.getMany();
|
||||
|
||||
if (list_data_final.length > 0) {
|
||||
const res_list_all = await repoMenu.createQueryBuilder().andWhere('id_parent is not null').getMany();
|
||||
const res_list_all = await repoMenu.createQueryBuilder()
|
||||
.where(whereAttr.join(' or '), whereVal)
|
||||
.andWhere('id_parent is not null').getMany();
|
||||
|
||||
let list_child: any = {};
|
||||
for (let p of res_list_all) {
|
||||
@ -131,10 +140,20 @@ export class AuthController {
|
||||
list_child[p.id_parent] = [];
|
||||
}
|
||||
|
||||
delete p.status
|
||||
delete p.created_at
|
||||
delete p.updated_at
|
||||
delete p.deleted_at
|
||||
|
||||
list_child[p.id_parent].push(p);
|
||||
}
|
||||
|
||||
for (let f of list_data_final) {
|
||||
delete f.status
|
||||
delete f.created_at
|
||||
delete f.updated_at
|
||||
delete f.deleted_at
|
||||
|
||||
if (list_child[f.id]) {
|
||||
f.children = list_child[f.id];
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import config from 'config';
|
||||
import { DataSource } from "typeorm";
|
||||
import { User, UserActivity, UserRefreshToken, UserRole } from "entity";
|
||||
import { Menu, User, UserActivity, UserRefreshToken, UserRole } from "entity";
|
||||
import { ILogObj, Logger } from 'tslog';
|
||||
|
||||
export class OrmHelper {
|
||||
@ -20,7 +20,7 @@ export class OrmHelper {
|
||||
database: String(config.get("database.database")),
|
||||
synchronize: true,
|
||||
logging: true,
|
||||
entities: [User, UserRole, UserActivity, UserRefreshToken],
|
||||
entities: [User, UserRole, UserActivity, UserRefreshToken, Menu],
|
||||
subscribers: [],
|
||||
migrations: [],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user