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 }}" + }] + }' diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index 3de8a72..43a03ab 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -235,20 +235,32 @@ export class kpiPeriodController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("year") year?: number, @Query("keyword") keyword?: string, + @Query("sortBy") sortBy?: string, + @Query("descending") descending?: boolean, ) { await new permission().PermissionList(request, "SYS_KPI_ROUND"); - const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod) + let query = await AppDataSource.getRepository(KpiPeriod) .createQueryBuilder("kpiPeriod") .andWhere( year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1", { year: year }, ) - .orderBy("kpiPeriod.year", "DESC") - .addOrderBy("kpiPeriod.durationKPI", "DESC") - .addOrderBy("kpiPeriod.startDate", "DESC") - .skip((page - 1) * pageSize) - .take(pageSize) - .getManyAndCount(); + + if (sortBy) { + query = query.orderBy( + `kpiPeriod.${sortBy}`, + descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy("kpiPeriod.year", "DESC") + .addOrderBy("kpiPeriod.durationKPI", "DESC") + .addOrderBy("kpiPeriod.startDate", "DESC") + } + + const [kpiPeriod, total] = await query + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); return new HttpSuccess({ data: kpiPeriod, total }); } @@ -291,7 +303,7 @@ export class kpiPeriodController extends Controller { @Query("year") year?: number, @Query("keyword") keyword?: string, ) { - const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod) + const [kpiPeriod,total] = await AppDataSource.getRepository(KpiPeriod) .createQueryBuilder("kpiPeriod") .andWhere( year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1", diff --git a/src/controllers/KpiUserDevelopmentController.ts b/src/controllers/KpiUserDevelopmentController.ts index 8f8a2fe..5512e8f 100644 --- a/src/controllers/KpiUserDevelopmentController.ts +++ b/src/controllers/KpiUserDevelopmentController.ts @@ -360,6 +360,8 @@ export class KpiUserDevelopmentController extends Controller { // results?: string | null; // reqedit?: string | null; // evaluating?: boolean | null; + sortBy?: string; + descending?: boolean; }, ) { // await new permission().PermissionList(request, "SYS_RESULT"); @@ -372,7 +374,7 @@ export class KpiUserDevelopmentController extends Controller { _data = x; }) .catch((x) => {}); - const [kpiUserDevelopment, total] = await AppDataSource.getRepository(KpiUserDevelopment) + let query = await AppDataSource.getRepository(KpiUserDevelopment) .createQueryBuilder("kpiUserDevelopment") .leftJoinAndSelect("kpiUserDevelopment.kpiUserEvaluation", "kpiUserEvaluation") .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") @@ -476,7 +478,46 @@ export class KpiUserDevelopmentController extends Controller { }); }), ) - .orderBy("kpiUserDevelopment.createdAt", "ASC") + + if (requestBody.sortBy) { + if(requestBody.sortBy === "developmentName"){ + query = query.orderBy( + `kpiUserDevelopment.name`, + requestBody.descending ? "DESC" : "ASC" + ); + }else if (requestBody.sortBy === "organization"){ + query = query + .orderBy(`kpiUserEvaluation.child4`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child3`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child2`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child1`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.org`, requestBody.descending ? "DESC" : "ASC"); + }else if(requestBody.sortBy === "firstname"){ + query = query.orderBy( + `kpiUserEvaluation.firstName`, + requestBody.descending ? "DESC" : "ASC" + ); + }else if(requestBody.sortBy === "lastname"){ + query = query.orderBy( + `kpiUserEvaluation.lastName`, + requestBody.descending ? "DESC" : "ASC" + ); + }else if(requestBody.sortBy === "root"){ + query = query.orderBy( + `kpiUserEvaluation.org`, + requestBody.descending ? "DESC" : "ASC" + ); + }else{ + query = query.orderBy( + `kpiUserEvaluation.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("kpiUserDevelopment.createdAt", "ASC") + } + + const [kpiUserDevelopment, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount(); diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index e78a8ec..b311bae 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -241,6 +241,8 @@ export class KpiUserEvaluationController extends Controller { results?: string | null; reqedit?: string | null; evaluating?: boolean | null; + sortBy?: string; + descending?: boolean; }, ) { // await new permission().PermissionList(request, "SYS_RESULT"); @@ -253,7 +255,7 @@ export class KpiUserEvaluationController extends Controller { _data = x; }) .catch((x) => {}); - const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) + let query = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") .andWhere( _data.root != undefined && _data.root != null @@ -385,7 +387,31 @@ export class KpiUserEvaluationController extends Controller { }); }), ) - .orderBy("kpiUserEvaluation.createdAt", "DESC") + + if (requestBody.sortBy) { + if(requestBody.sortBy === "root"){ + query = query.orderBy( + `kpiUserEvaluation.org`, + requestBody.descending ? "DESC" : "ASC" + ); + }else if(requestBody.sortBy === "organization"){ + query = query + .orderBy(`kpiUserEvaluation.child4`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child3`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child2`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child1`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.org`, requestBody.descending ? "DESC" : "ASC"); + }else{ + query = query.orderBy( + `kpiUserEvaluation.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("kpiUserEvaluation.createdAt", "DESC") + } + + const [kpiUserEvaluation, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount(); @@ -441,6 +467,8 @@ export class KpiUserEvaluationController extends Controller { keyword?: string; status?: string | null; results?: string | null; + sortBy?: string; + descending?: boolean; }, ) { let _data = await new permission().PermissionOrgList(request, "SYS_KPI_LIST"); @@ -452,7 +480,7 @@ export class KpiUserEvaluationController extends Controller { .catch((x) => {}); let conditionFullName = "CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword"; - const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) + let query = await AppDataSource.getRepository(KpiUserEvaluation) .createQueryBuilder("kpiUserEvaluation") .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") .andWhere( @@ -564,8 +592,32 @@ export class KpiUserEvaluationController extends Controller { child4: _data.child4, }, ) - .orderBy("kpiPeriod.year", "DESC") - .addOrderBy("kpiUserEvaluation.createdAt", "DESC") + + if (requestBody.sortBy) { + if(requestBody.sortBy === "root"){ + query = query.orderBy( + `kpiUserEvaluation.org`, + requestBody.descending ? "DESC" : "ASC" + ); + }else if(requestBody.sortBy === "organization"){ + query = query + .orderBy(`kpiUserEvaluation.child4`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child3`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child2`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.child1`, requestBody.descending ? "DESC" : "ASC") + .addOrderBy(`kpiUserEvaluation.org`, requestBody.descending ? "DESC" : "ASC"); + }else{ + query = query.orderBy( + `kpiUserEvaluation.${requestBody.sortBy}`, + requestBody.descending ? "DESC" : "ASC" + ); + } + }else{ + query = query.orderBy("kpiPeriod.year", "DESC") + .addOrderBy("kpiUserEvaluation.createdAt", "DESC") + } + + const [kpiUserEvaluation, total] = await query .skip((requestBody.page - 1) * requestBody.pageSize) .take(requestBody.pageSize) .getManyAndCount(); diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index cfe76e6..6ff8977 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -184,61 +184,39 @@ 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; + 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 + ) - if (!REDIS_HOST) { - throw new Error("REDIS_HOST is not set in environment variables"); - } + const data = { + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + } - console.log(`[REDIS] Connecting to Redis at ${REDIS_HOST}:${REDIS_PORT}`); - - // Create Redis client - const redisClient = 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; - } + 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");