From 1478349d42c3c1140867234a4dd123048c7f6dba Mon Sep 17 00:00:00 2001 From: Harid Promsri <52228846+Harid-999@users.noreply.github.com> Date: Mon, 6 Oct 2025 18:04:35 +0700 Subject: [PATCH 1/4] discord-notify.yml (#7) Co-authored-by: harid --- .github/workflows/discord-notify.yml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .github/workflows/discord-notify.yml diff --git a/.github/workflows/discord-notify.yml b/.github/workflows/discord-notify.yml new file mode 100644 index 0000000..ce4ee51 --- /dev/null +++ b/.github/workflows/discord-notify.yml @@ -0,0 +1,22 @@ +name: Discord PR Notify + +on: + pull_request: + types: [opened] + +jobs: + discord: + runs-on: ubuntu-latest + steps: + - name: Send Discord + run: | + curl -X POST "${{ secrets.DISCORD_WEBHOOK_PULLREQUEST }}" \ + -H "Content-Type: application/json" \ + -d '{ + "embeds": [{ + "title": "šŸ”” **Service:** ${{ github.repository }}", + "description": "šŸ‘¤ **Author:** ${{ github.event.pull_request.user.login }}\n🌿 **Branch:** ${{ github.event.pull_request.head.ref }} → ${{ github.event.pull_request.base.ref }}\nšŸ“¦ **Pull Request:** [#${{ github.event.pull_request.number }} - ${{ github.event.pull_request.title }}](${{ github.event.pull_request.html_url }})", + "color": 5814783, + "timestamp": "${{ github.event.pull_request.created_at }}" + }] + }' From 719b8287511bfa0d6e4db3abd471394a3241a214 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 21 Oct 2025 11:18:04 +0700 Subject: [PATCH 2/4] test log --- src/interfaces/permission.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index cfe76e6..b7f3576 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -196,7 +196,7 @@ class CheckAuth { console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); // Create Redis client - const redisClient = this.redis.createClient({ + const redisClient = await this.redis.createClient({ socket: { host: REDIS_HOST, port: REDIS_PORT, From 23a3687b50b7e88ae8a5e759538aece43d0c1c67 Mon Sep 17 00:00:00 2001 From: harid Date: Tue, 21 Oct 2025 11:34:35 +0700 Subject: [PATCH 3/4] test log --- src/interfaces/permission.ts | 125 ++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 46 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index b7f3576..387416c 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -184,61 +184,94 @@ class CheckAuth { }); } public async checkOrg(token: any, keycloakId: string) { - try { - // Validate required environment variables - const REDIS_HOST = process.env.REDIS_HOST; - const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379; + // try { + // // Validate required environment variables + // const REDIS_HOST = process.env.REDIS_HOST; + // const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379; - if (!REDIS_HOST) { - throw new Error("REDIS_HOST is not set in environment variables"); - } + // if (!REDIS_HOST) { + // throw new Error("REDIS_HOST is not set in environment variables"); + // } - console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); + // console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); - // Create Redis client - const redisClient = await this.redis.createClient({ - socket: { - host: REDIS_HOST, - port: REDIS_PORT, - }, - }); + // // Create Redis client + // const redisClient = await this.redis.createClient({ + // socket: { + // host: REDIS_HOST, + // port: REDIS_PORT, + // }, + // }); - redisClient.on("error", (err: any) => { - console.error("[REDIS] Connection error:", err.message); - }); + // redisClient.on("error", (err: any) => { + // console.error("[REDIS] Connection error:", err.message); + // }); - await redisClient.connect(); - console.log("[REDIS] Connected successfully!"); + // await redisClient.connect(); + // console.log("[REDIS] Connected successfully!"); - const getAsync = promisify(redisClient.get).bind(redisClient); + // const getAsync = promisify(redisClient.get).bind(redisClient); - let reply = await getAsync("org_" + keycloakId); - if (reply != null) { - reply = JSON.parse(reply); - } else { - if (!keycloakId) throw new Error("No KeycloakId provided"); - const x = await new CallAPI().GetData( - { - headers: { authorization: token }, - }, - `/org/permission/checkOrg/${keycloakId}`, - false, - ); + // let reply = await getAsync("org_" + keycloakId); + // if (reply != null) { + // reply = JSON.parse(reply); + // } else { + // if (!keycloakId) throw new Error("No KeycloakId provided"); + // const x = await new CallAPI().GetData( + // { + // headers: { authorization: token }, + // }, + // `/org/permission/checkOrg/${keycloakId}`, + // false, + // ); - const data = { - orgRootId: x.orgRootId, - orgChild1Id: x.orgChild1Id, - orgChild2Id: x.orgChild2Id, - orgChild3Id: x.orgChild3Id, - orgChild4Id: x.orgChild4Id, - }; + // const data = { + // orgRootId: x.orgRootId, + // orgChild1Id: x.orgChild1Id, + // orgChild2Id: x.orgChild2Id, + // orgChild3Id: x.orgChild3Id, + // orgChild4Id: x.orgChild4Id, + // }; - return data; - } - } catch (error) { - console.error("Error calling API:", error); - throw error; - } + // return data; + // } + // } catch (error) { + // console.error("Error calling API:", error); + // throw error; + // } + const redisClient = await this.redis.createClient({ + host: process.env.REDIS_HOST, + port: process.env.REDIS_PORT, + }) + const getAsync = promisify(redisClient.get).bind(redisClient) + try { + let reply = await getAsync("org_" + keycloakId) + if (reply != null) { + reply = JSON.parse(reply) + } else { + if (!keycloakId) throw new Error("No KeycloakId provided") + const x = await new CallAPI().GetData( + { + headers: { authorization: token }, + }, + `/org/permission/checkOrg/${keycloakId}`, + false + ) + + const data = { + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + } + + return data + } + } catch (error) { + console.error("Error calling API:", error) + throw error + } } public async PermissionCreate(req: RequestWithUser, system: string) { return await this.Permission(req, system, "CREATE"); From c2f7a91cc850bfa234cd57f9e7c76eae917a4b7a Mon Sep 17 00:00:00 2001 From: Harid Promsri <52228846+Harid-999@users.noreply.github.com> Date: Tue, 21 Oct 2025 14:40:58 +0700 Subject: [PATCH 4/4] fix log (#8) Co-authored-by: harid --- src/interfaces/permission.ts | 55 ------------------------------------ 1 file changed, 55 deletions(-) diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 387416c..6ff8977 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -184,61 +184,6 @@ class CheckAuth { }); } public async checkOrg(token: any, keycloakId: string) { - // try { - // // Validate required environment variables - // const REDIS_HOST = process.env.REDIS_HOST; - // const REDIS_PORT = process.env.REDIS_PORT ? Number(process.env.REDIS_PORT) : 6379; - - // if (!REDIS_HOST) { - // throw new Error("REDIS_HOST is not set in environment variables"); - // } - - // console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); - - // // Create Redis client - // const redisClient = await this.redis.createClient({ - // socket: { - // host: REDIS_HOST, - // port: REDIS_PORT, - // }, - // }); - - // redisClient.on("error", (err: any) => { - // console.error("[REDIS] Connection error:", err.message); - // }); - - // await redisClient.connect(); - // console.log("[REDIS] Connected successfully!"); - - // const getAsync = promisify(redisClient.get).bind(redisClient); - - // let reply = await getAsync("org_" + keycloakId); - // if (reply != null) { - // reply = JSON.parse(reply); - // } else { - // if (!keycloakId) throw new Error("No KeycloakId provided"); - // const x = await new CallAPI().GetData( - // { - // headers: { authorization: token }, - // }, - // `/org/permission/checkOrg/${keycloakId}`, - // false, - // ); - - // const data = { - // orgRootId: x.orgRootId, - // orgChild1Id: x.orgChild1Id, - // orgChild2Id: x.orgChild2Id, - // orgChild3Id: x.orgChild3Id, - // orgChild4Id: x.orgChild4Id, - // }; - - // return data; - // } - // } catch (error) { - // console.error("Error calling API:", error); - // throw error; - // } const redisClient = await this.redis.createClient({ host: process.env.REDIS_HOST, port: process.env.REDIS_PORT,