From 2f525bae9516544373de70283833d6f727125f5f Mon Sep 17 00:00:00 2001 From: waruneeauy Date: Wed, 12 Jun 2024 13:21:15 +0700 Subject: [PATCH] add auth sync by menu --- src/controllers/AuthSysController.ts | 20 +++++++++---- src/entities/AuthSys.ts | 43 ++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/src/controllers/AuthSysController.ts b/src/controllers/AuthSysController.ts index 756bd368..c76868b2 100644 --- a/src/controllers/AuthSysController.ts +++ b/src/controllers/AuthSysController.ts @@ -27,11 +27,21 @@ export class AuthSysController extends Controller { @Get("list") public async listAuthSys() { - const getList = await this.authSysRepo.find(); - // if (!getList || getList.length === 0) { - // throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); - // } - return new HttpSuccess(getList); + const getList = await this.authSysRepo.find({ + select: ["id", "parentId", "sysName", "sysDescription", "order"], + }); + + const lists = getList + .filter((x) => x.parentId == null) + .map((item) => { + return { + ...item, + children: getList.filter((x) => x.parentId == item.id).sort((a, b) => a.order - b.order), + }; + }) + .sort((a, b) => a.order - b.order); + + return new HttpSuccess(lists); } @Get("{systemId}") diff --git a/src/entities/AuthSys.ts b/src/entities/AuthSys.ts index b331cba5..3626578f 100644 --- a/src/entities/AuthSys.ts +++ b/src/entities/AuthSys.ts @@ -1,12 +1,4 @@ -import { - Entity, - Column, - OneToMany, - CreateDateColumn, - UpdateDateColumn, - PrimaryColumn, -} from "typeorm"; -import { AuthRoleAttr } from "./AuthRoleAttr"; +import { Entity, Column, CreateDateColumn, UpdateDateColumn, PrimaryColumn } from "typeorm"; @Entity("authSys") export class AuthSys { @@ -16,6 +8,36 @@ export class AuthSys { }) id: string; + @Column({ + comment: "Id ของเมนูหลักถ้าเป็นเมนูหลักจะเป็นค่า null", + nullable: true, + default: null, + length: 255, + }) + parentId!: string; + + @Column({ + comment: "ชื่อ icon", + nullable: true, + default: null, + length: 100, + }) + icon!: string; + + @Column({ + comment: "path url ของระบบ", + nullable: true, + default: null, + length: 255, + }) + path!: string; + + @Column({ + comment: "ลำดับการแสดงผล", + default: 0, + }) + order: number; + @CreateDateColumn({ comment: "สร้างข้อมูลเมื่อ" }) createdAt!: Date; @@ -66,6 +88,9 @@ export class CreateAuthSys { @PrimaryColumn() id: string; + @Column() + parentId: string; + @Column() sysName: string;