From ecd66fc4eed86f20875381b420d02d7cb546e18f Mon Sep 17 00:00:00 2001 From: Abdul Rahman Reza Date: Sun, 1 Dec 2024 00:26:57 +0700 Subject: [PATCH] update auth response --- src/controllers/auth.ts | 29 ++++++++++++++++++++++++----- src/helpers/orm.ts | 4 ++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/controllers/auth.ts b/src/controllers/auth.ts index 7c526a9..126404c 100644 --- a/src/controllers/auth.ts +++ b/src/controllers/auth.ts @@ -112,18 +112,27 @@ export class AuthController { static async getListRole(roles: any): Promise { 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]; diff --git a/src/helpers/orm.ts b/src/helpers/orm.ts index 8408fdb..be990c6 100644 --- a/src/helpers/orm.ts +++ b/src/helpers/orm.ts @@ -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: [], })