Merge branch 'develop'

This commit is contained in:
kittapath 2024-12-18 09:50:57 +07:00
commit 404bfd09fc
7 changed files with 157 additions and 37 deletions

View file

@ -1,5 +1,5 @@
name: release-test
run-name: release-test ${{ github.actor }}
name: release
run-name: release ${{ github.actor }}
on:
push:
tags:
@ -9,11 +9,11 @@ env:
REGISTRY: docker.frappet.com
IMAGE_NAME: ehr/bma-ehr-kpi-service
DEPLOY_HOST: frappet.com
# COMPOSE_PATH: /home/frappet/docker/bma-ehr
COMPOSE_PATH: /home/frappet/docker/bma/bma-ehr-kpi
jobs:
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=latest -s DOCKER_USER=admin -s DOCKER_PASS=FPTadmin2357 -s SSH_PASSWORD=FPTadmin2357
release-test:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
@ -67,21 +67,40 @@ jobs:
docker compose pull
docker compose up -d
echo "${{ steps.gen_ver.outputs.image_ver }}"> success
- uses: snow-actions/line-notify@v1.1.0
- name: Notify Discord Success
if: success()
with:
access_token: ${{ secrets.TOKEN_LINE }}
message: |
-Success✅✅✅
Image: ${{env.IMAGE_NAME}}
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }}
By: ${{github.actor}}
- uses: snow-actions/line-notify@v1.1.0
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "✅ Deployment Success!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Deployed by: `${{github.actor}}`",
"color": 3066993,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/success-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}
- name: Notify Discord Failure
if: failure()
with:
access_token: ${{ secrets.TOKEN_LINE }}
message: |
-Failure❌❌❌
Image: ${{env.IMAGE_NAME}}
Version: ${{ steps.gen_ver.outputs.IMAGE_VER }}
By: ${{github.actor}}
run: |
curl -H "Content-Type: application/json" \
-X POST \
-d '{
"embeds": [{
"title": "❌ Deployment Failed!",
"description": "**Details:**\n- Image: `${{env.IMAGE_NAME}}`\n- Version: `${{ steps.gen_ver.outputs.image_ver }}`\n- Attempted by: `${{github.actor}}`",
"color": 15158332,
"footer": {
"text": "Release Notification",
"icon_url": "https://example.com/failure-icon.png"
},
"timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'"
}]
}' \
${{ secrets.DISCORD_WEBHOOK }}

View file

@ -350,11 +350,7 @@ export class kpiCapacityController extends Controller {
const [kpiCapacity, total] = await AppDataSource.getRepository(KpiCapacity)
.createQueryBuilder("kpiCapacity")
.leftJoinAndSelect("kpiCapacity.kpiCapacityDetails", "kpiCapacityDetail")
.andWhere(
keyword == undefined
? "1=1"
: [{ name: Like(`%${keyword}%`) }, { description: Like(`%${keyword}%`) }],
)
.andWhere(keyword == undefined ? "1=1" : [{ name: Like(`%${keyword}%`) }])
.andWhere(type == undefined ? "1=1" : { type: type })
.orderBy("kpiCapacity.createdAt", "ASC")
.skip((page - 1) * pageSize)

View file

@ -18,12 +18,14 @@ import {
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import { Like, Not } from "typeorm";
import { In, Like, Not } from "typeorm";
import HttpStatusCode from "../interfaces/http-status";
import { KpiGroup, createKpiGroup, updateKpiGroup } from "../entities/kpiGroup";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { KpiLink } from "../entities/kpiLink";
import { Position } from "../entities/position";
@Route("api/v1/kpi/group")
@Tags("kpiGroup")
@ -35,6 +37,8 @@ import { setLogDataDiff } from "../interfaces/utils";
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiGroupController extends Controller {
private kpiGroupRepository = AppDataSource.getRepository(KpiGroup);
private kpiLinkRepository = AppDataSource.getRepository(KpiLink);
private positionRepository = AppDataSource.getRepository(Position);
/**
* API
@ -192,7 +196,11 @@ export class kpiGroupController extends Controller {
if (!kpiGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
}
const kpiLink = await this.kpiLinkRepository.find({
where: { kpiGroupId: id },
});
await this.positionRepository.delete({ kpiLinkId: In(kpiLink.map((x) => x.id)) });
await this.kpiLinkRepository.remove(kpiLink, { data: request });
await this.kpiGroupRepository.remove(kpiGroup, { data: request });
return new HttpSuccess();
}

View file

@ -331,7 +331,12 @@ export class kpiPeriodController extends Controller {
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.find({
where: { kpiPeriodId: id },
});
if (kpiUserEvaluation && kpiUserEvaluation.length > 0) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่สามารถลบรอบการประเมินนี้ได้ เนื่องจากพบรายการผู้รับการประเมินในรอบนี้",
);
}
const kpiUserRole = await this.kpiUserRoleRepository.find({
where: { kpiRoleId: In(kpiRole.map((x) => x.id)) },
});

View file

@ -47,17 +47,16 @@ export class kpiRoleController extends Controller {
async createKpiRole(@Body() requestBody: createKpiRole, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_EVA_INDICATOR");
const kpiRole = Object.assign(new KpiRole(), requestBody);
if (requestBody.year != null && requestBody.period != null) {
if (requestBody.year != null && requestBody.period != null && requestBody.period != "") {
const kpiPeriod = await this.kpiPeriodRepository
.createQueryBuilder("kpiPeriod")
.where("kpiPeriod.year = :year", { year: requestBody.year })
.andWhere("kpiPeriod.durationKPI = :durationKPI", { durationKPI: requestBody.period })
.getOne();
if (!kpiPeriod) {
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตัวชี้วัดตามตำแหน่งนี้");
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + requestBody.year,
"ไม่พบข้อมูลรอบการประเมินนี้ในปีงบประมาณ " + (requestBody.year + 543),
);
}
}

View file

@ -770,6 +770,12 @@ export class ReportController extends Controller {
acc.posType = x.posTypeName;
acc.posLevel = x.posLevelName;
acc.affiliation = affiliation;
} else {
acc.fullName = "-";
acc.position = "-";
acc.posType = "-";
acc.posLevel = "-";
acc.affiliation = "-";
}
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "APR") {
@ -781,6 +787,11 @@ export class ReportController extends Controller {
acc.yearAPR1 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR1 = "-"
acc.textPointAPR1 = "-"
acc.periodAPR1 = "-"
acc.yearAPR1 = "-"
}
if (x.kpiPeriod.year === yearNow - 4 && x.kpiPeriod.durationKPI === "OCT") {
@ -792,6 +803,11 @@ export class ReportController extends Controller {
acc.yearOCT1 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT1 = "-"
acc.textPointOCT1 = "-"
acc.periodOCT1 = "-"
acc.yearOCT1 = "-"
}
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "APR") {
@ -803,6 +819,11 @@ export class ReportController extends Controller {
acc.yearAPR2 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR2 = "-"
acc.textPointAPR2 = "-"
acc.periodAPR2 = "-"
acc.yearAPR2 = "-"
}
if (x.kpiPeriod.year === yearNow - 3 && x.kpiPeriod.durationKPI === "OCT") {
@ -814,6 +835,11 @@ export class ReportController extends Controller {
acc.yearOCT2 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT2 = "-"
acc.textPointOCT2 = "-"
acc.periodOCT2 = "-"
acc.yearOCT2 = "-"
}
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
@ -825,6 +851,11 @@ export class ReportController extends Controller {
acc.yearAPR3 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR3 = "-"
acc.textPointAPR3 = "-"
acc.periodAPR3 = "-"
acc.yearAPR3 = "-"
}
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
@ -836,6 +867,11 @@ export class ReportController extends Controller {
acc.yearOCT3 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT3 = "-"
acc.textPointOCT3 = "-"
acc.periodOCT3 = "-"
acc.yearOCT3 = "-"
}
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
@ -847,6 +883,11 @@ export class ReportController extends Controller {
acc.yearAPR4 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR4 = "-"
acc.textPointAPR4 = "-"
acc.periodAPR4 = "-"
acc.yearAPR4 = "-"
}
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
@ -858,6 +899,11 @@ export class ReportController extends Controller {
acc.yearOCT4 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT4 = "-"
acc.textPointOCT4 = "-"
acc.periodOCT4 = "-"
acc.yearOCT4 = "-"
}
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
@ -869,6 +915,11 @@ export class ReportController extends Controller {
acc.yearAPR5 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR5 = "-"
acc.textPointAPR5 = "-"
acc.periodAPR5 = "-"
acc.yearAPR5 = "-"
}
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
@ -880,6 +931,11 @@ export class ReportController extends Controller {
acc.yearOCT5 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT5 = "-"
acc.textPointOCT5 = "-"
acc.periodOCT5 = "-"
acc.yearOCT5 = "-"
}
return acc;
@ -1069,6 +1125,12 @@ export class ReportController extends Controller {
acc.posType = x.posTypeName;
acc.posLevel = x.posLevelName;
acc.affiliation = affiliation;
} else {
acc.fullName = "-";
acc.position = "-";
acc.posType = "-";
acc.posLevel = "-";
acc.affiliation = "-";
}
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "APR") {
@ -1080,6 +1142,11 @@ export class ReportController extends Controller {
acc.yearAPR1 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR1 = "-"
acc.textPointAPR1 = "-"
acc.periodAPR1 = "-"
acc.yearAPR1 = "-"
}
if (x.kpiPeriod.year === yearNow - 2 && x.kpiPeriod.durationKPI === "OCT") {
@ -1091,6 +1158,11 @@ export class ReportController extends Controller {
acc.yearOCT1 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT1 = "-"
acc.textPointOCT1 = "-"
acc.periodOCT1 = "-"
acc.yearOCT1 = "-"
}
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "APR") {
@ -1102,6 +1174,11 @@ export class ReportController extends Controller {
acc.yearAPR2 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR2 = "-"
acc.textPointAPR2 = "-"
acc.periodAPR2 = "-"
acc.yearAPR2 = "-"
}
if (x.kpiPeriod.year === yearNow - 1 && x.kpiPeriod.durationKPI === "OCT") {
@ -1113,6 +1190,11 @@ export class ReportController extends Controller {
acc.yearOCT2 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT2 = "-"
acc.textPointOCT2 = "-"
acc.periodOCT2 = "-"
acc.yearOCT2 = "-"
}
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "APR") {
@ -1124,6 +1206,11 @@ export class ReportController extends Controller {
acc.yearAPR3 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointAPR3 = "-"
acc.textPointAPR3 = "-"
acc.periodAPR3 = "-"
acc.yearAPR3 = "-"
}
if (x.kpiPeriod.year === yearNow && x.kpiPeriod.durationKPI === "OCT") {
@ -1135,6 +1222,11 @@ export class ReportController extends Controller {
acc.yearOCT3 = x.kpiPeriod.year
? Extension.ToThaiNumber(Extension.ToThaiYear(x.kpiPeriod.year).toString())
: null;
} else {
acc.summaryPointOCT3 = "-"
acc.textPointOCT3 = "-"
acc.periodOCT3 = "-"
acc.yearOCT3 = "-"
}
return acc;

View file

@ -183,7 +183,7 @@ class CheckAuth {
return false;
});
}
public async checkOrg(token: any,keycloakId: string) {
public async checkOrg(token: any, keycloakId: string) {
const redisClient = await this.redis.createClient({
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT,
@ -194,14 +194,15 @@ class CheckAuth {
reply = JSON.parse(reply);
} else {
try {
if (!keycloakId) throw "Error calling API No KeycloakId";
const x = await new CallAPI().GetData(
{
headers: { authorization: token },
},
`/org/permission/checkOrg/${keycloakId}`,
false
},
`/org/permission/checkOrg/${keycloakId}`,
false,
);
const data = {
orgRootId: x.orgRootId,
orgChild1Id: x.orgChild1Id,
@ -209,7 +210,7 @@ class CheckAuth {
orgChild3Id: x.orgChild3Id,
orgChild4Id: x.orgChild4Id,
};
return data;
} catch (error) {
console.error("Error calling API:", error);