From 0afa53889dd034de12f5da0d2c394bbdb2a3332e Mon Sep 17 00:00:00 2001 From: kittapath Date: Tue, 20 Aug 2024 22:41:17 +0700 Subject: [PATCH] dotnet-user --- src/controllers/PermissionController.ts | 33 ++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/controllers/PermissionController.ts b/src/controllers/PermissionController.ts index 52b4603b..62341dde 100644 --- a/src/controllers/PermissionController.ts +++ b/src/controllers/PermissionController.ts @@ -208,6 +208,33 @@ export class PermissionController extends Controller { return new HttpSuccess(res); } + /** + * API permission (dotnet api) + * @summary permission (dotnet api) + * @param {string} action action + * @param {string} system authSysId + * @param {string} profileId profileId + */ + @Get("dotnet-user/{action}/{system}/{profileId}") + public async dotnetUser( + @Request() req: RequestWithUser, + @Path() action: string, + @Path() system: string, + @Path() profileId: string, + ) { + if (!["CREATE", "DELETE", "GET", "LIST", "UPDATE"].includes(action)) { + throw new HttpError(HttpStatus.NOT_FOUND, "Action ไม่ถูกต้อง"); + } + + let res = await new permission().PermissionOrgByUser( + req, + system.toLocaleUpperCase(), + action, + profileId, + ); + return new HttpSuccess(res); + } + @Get("org") public async listAuthSysOrg(@Request() request: RequestWithUser) { const redisClient = await this.redis.createClient({ @@ -217,7 +244,7 @@ export class PermissionController extends Controller { const getAsync = promisify(redisClient.get).bind(redisClient); const profile = await this.profileRepo.findOne({ - select: ["id"], + select: ["id"], where: { keycloak: request.user.sub }, }); if (!profile) { @@ -254,7 +281,7 @@ export class PermissionController extends Controller { } @Get("user/{id}") - public async listOrgUser(@Request() request: RequestWithUser,@Path() id: string) { + public async listOrgUser(@Request() request: RequestWithUser, @Path() id: string) { const redisClient = await this.redis.createClient({ host: REDIS_HOST, port: REDIS_PORT, @@ -262,7 +289,7 @@ export class PermissionController extends Controller { const getAsync = promisify(redisClient.get).bind(redisClient); const profile = await this.profileRepo.findOne({ - select: ["id"], + select: ["id"], where: { id: id }, }); if (!profile) {