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