diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 2f29d54..0d19c5a 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -104,4 +104,3 @@ jobs: }] }' \ ${{ secrets.DISCORD_WEBHOOK }} - diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 2cd5f30..0642d60 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -34,6 +34,8 @@ import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; import { CreateDevelopmentHistoryOBO, DevelopmentHistory } from "../entities/DevelopmentHistory"; import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; @@ -84,6 +86,8 @@ export class DevelopmentController extends Controller { private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); + private empPosTypeRepository = AppDataSource.getRepository(EmployeePosType); + private empPosLevelRepository = AppDataSource.getRepository(EmployeePosLevel); private strategyChild1Repository = AppDataSource.getRepository(StrategyChild1); private strategyChild2Repository = AppDataSource.getRepository(StrategyChild2); private strategyChild3Repository = AppDataSource.getRepository(StrategyChild3); @@ -366,20 +370,58 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkPosType: any = null; + let posTypeShortName: any = null; + if (x.posTypePlanned) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName; + } else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } - if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + if (x.posLevelPlanned) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id, + }, + }); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: x.posLevelPlanned, + posTypeId: checkPosType.id, + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } const before = structuredClone(development); @@ -466,30 +508,56 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.posTypeActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); - const checkId = await this.posTypeRepository.findOne({ - where: { id: requestBody.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkPosType: any = null; + let posTypeShortName: any = null; + if (requestBody.posTypeActual) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName; + } else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } - if (requestBody.posLevelActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); - const checkId = await this.posLevelRepository.findOne({ - where: { id: requestBody.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + if (requestBody.posLevelActual) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id, + }, + }); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: requestBody.posLevelActual, + posTypeId: checkPosType.id, + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } const before = structuredClone(development); @@ -607,20 +675,58 @@ export class DevelopmentController extends Controller { await Promise.all( requestBody.positions.map(async (x) => { const _data = Object.assign(new PlannedGoalPosition(), x); - if (x.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkPosType: any = null; + let posTypeShortName: any = null; + if (x.posTypePlanned) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName; + } else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: x.posTypePlanned }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } - if (x.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + if (x.posLevelPlanned) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || + requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id, + }, + }); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: x.posLevelPlanned, + posTypeId: checkPosType.id, + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } _data.createdUserId = request.user.sub; @@ -711,30 +817,56 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.posTypeActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Type.", - // }); - const checkId = await this.posTypeRepository.findOne({ - where: { id: requestBody.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + let checkPosType: any = null; + let posTypeShortName: any = null; + if (requestBody.posTypeActual) { + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosType = await this.empPosTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงาน"); + } + posTypeShortName = checkPosType.posTypeShortName; + } else { + checkPosType = await this.posTypeRepository.findOne({ + where: { posTypeName: requestBody.posTypeActual }, + }); + if (!checkPosType) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } } } - if (requestBody.posLevelActualId != null) { - // addLogSequence(request, { - // action: "database", - // status: "success", - // description: "Get Position Level.", - // }); - const checkId = await this.posLevelRepository.findOne({ - where: { id: requestBody.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + if (requestBody.posLevelActual) { + let checkPosLevel: any; + if ( + requestBody.groupTarget == "PERSONNEL" && + (requestBody.groupTargetSub == "EMPLOYEE" || requestBody.groupTargetSub == "EMPLOYEETEMP") + ) { + checkPosLevel = await this.empPosLevelRepository.find({ + where: { + posTypeId: checkPosType.id, + }, + }); + const mapShortName = checkPosLevel.flatMap( + (x: any) => `${posTypeShortName} ${x.posLevelName}`, + ); + if (checkPosLevel.length == 0 /*|| !mapShortName.includes(x.posLevelPlanned)*/) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับชั้นงาน"); + } + } else { + checkPosLevel = await this.posLevelRepository.findOne({ + where: { + posLevelName: requestBody.posLevelActual, + posTypeId: checkPosType.id, + }, + }); + if (!checkPosLevel) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } } } const before = structuredClone(development); @@ -1419,7 +1551,7 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - Object.assign(development, { ...requestBody, developmentAddresss: [] }); + Object.assign(development, { ...requestBody}); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.lastUpdatedAt = new Date(); @@ -1814,6 +1946,9 @@ export class DevelopmentController extends Controller { developmentProjectTechniqueActuals: true, developmentEvaluations: true, developmentAddresss: true, + developmentRisks: true, + developmentHistorys: true, + developmentOthers: true, }, }); if (!development) { @@ -1827,92 +1962,46 @@ export class DevelopmentController extends Controller { const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedGoalPosition.", - // }); await this.plannedGoalPositionRepository.remove(plannedGoalPosition, { data: request }); } - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove ActualPeople.", - // }); await this.actualPeopleRepository.remove(development.developmentActualPeoples, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedPeople.", - // }); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove ActualGoal.", - // }); await this.actualGoalRepository.remove(development.developmentActualGoals, { data: request }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove PlannedGoal.", - // }); await this.plannedGoalRepository.remove(development.developmentPlannedGoals, { data: request }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectType.", - // }); await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectTechniquePlanned.", - // }); await this.developmentProjectTechniquePlannedRepository.remove( development.developmentProjectTechniquePlanneds, { data: request, }, ); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentProjectTechniqueActuals.", - // }); await this.developmentProjectTechniqueActualRepository.remove( development.developmentProjectTechniqueActuals, { data: request, }, ); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentEvaluation.", - // }); await this.developmentEvaluationRepository.remove(development.developmentEvaluations, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove DevelopmentAddresss.", - // }); await this.developmentAddresssRepository.remove(development.developmentAddresss, { data: request, }); - // addLogSequence(request, { - // action: "remove", - // status: "success", - // description: "Remove Development.", - // }); + await this.developmentRiskRepository.remove(development.developmentRisks, { + data: request, + }); + await this.developmentHistoryRepository.remove(development.developmentHistorys, { + data: request, + }); + await this.developmentOtherRepository.remove(development.developmentOthers, { + data: request, + }); await this.developmentRepository.remove(development, { data: request }); return new HttpSuccess(); } @@ -1934,7 +2023,13 @@ export class DevelopmentController extends Controller { @Query("node") node?: number | null, @Query("keyword") keyword?: string, ) { - // await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP"); + let _data = await new permission().PermissionOrgList(request, "SYS_DEV_PROJECT"); + await new CallAPI() + .PostData(request, "/org/finddna", _data) + .then((x) => { + _data = x; + }) + .catch((x) => {}); const [development, total] = await AppDataSource.getRepository(Development) .createQueryBuilder("development") .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { @@ -1974,6 +2069,56 @@ export class DevelopmentController extends Controller { keyword: `%${keyword}%`, }, ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `development.rootDnaId IN (:...root)` + : `development.rootDnaId is null` + : "1=1", + { + root: _data.root, + }, + ) + .andWhere( + _data.child1 != undefined && _data.child1 != null + ? _data.child1[0] != null + ? `development.child1DnaId IN (:...child1)` + : `development.child1DnaId is null` + : "1=1", + { + child1: _data.child1, + }, + ) + .andWhere( + _data.child2 != undefined && _data.child2 != null + ? _data.child2[0] != null + ? `development.child2DnaId IN (:...child2)` + : `development.child2DnaId is null` + : "1=1", + { + child2: _data.child2, + }, + ) + .andWhere( + _data.child3 != undefined && _data.child3 != null + ? _data.child3[0] != null + ? `development.child3DnaId IN (:...child3)` + : `development.child3DnaId is null` + : "1=1", + { + child3: _data.child3, + }, + ) + .andWhere( + _data.child4 != undefined && _data.child4 != null + ? _data.child4[0] != null + ? `development.child4DnaId IN (:...child4)` + : `development.child4DnaId is null` + : "1=1", + { + child4: _data.child4, + }, + ) .select([ "development.id", "development.projectName", @@ -2116,17 +2261,18 @@ export class DevelopmentController extends Controller { if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_PROJECT"); const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, + //posTypeActual relations: [ "developmentActualPeoples", "developmentPlannedPeoples", "developmentActualGoals", - "developmentActualGoals.posTypeActual", - "developmentActualGoals.posLevelActual", + // "developmentActualGoals.posTypeActual", + // "developmentActualGoals.posLevelActual", "developmentActualGoals", "developmentPlannedGoals", "developmentPlannedGoals.plannedGoalPositions", - "developmentPlannedGoals.plannedGoalPositions.posTypePlanned", - "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned", + // "developmentPlannedGoals.plannedGoalPositions.posTypePlanned", + // "developmentPlannedGoals.plannedGoalPositions.posLevelPlanned", ], }); if (!getDevelopment) { @@ -2164,10 +2310,12 @@ export class DevelopmentController extends Controller { groupTarget: x.groupTarget, groupTargetSub: x.groupTargetSub, position: x.position, - posTypeId: x.posTypeActualId, - posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName, - posLevelId: x.posLevelActualId, - posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName, + // posTypeId: x.posTypeActualId, + // posType: x.posTypeActual == null ? null : x.posTypeActual.posTypeName, + // posLevelId: x.posLevelActualId, + // posLevel: x.posLevelActual == null ? null : x.posLevelActual.posLevelName, + posType: x.posTypeActual, + posLevel: x.posLevelActual, type: x.type, amount: x.amount, })), @@ -2189,10 +2337,12 @@ export class DevelopmentController extends Controller { id: y.id, position: y.position, posExecutive: y.posExecutive, - posTypeId: y.posTypePlannedId, - posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, - posLevelId: y.posLevelPlannedId, - posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName, + // posTypeId: y.posTypePlannedId, + // posType: y.posTypePlanned == null ? null : y.posTypePlanned.posTypeName, + // posLevelId: y.posLevelPlannedId, + // posLevel: y.posLevelPlanned == null ? null : y.posLevelPlanned.posLevelName, + posType: y.posTypePlanned, + posLevel: y.posLevelPlanned, })), amount: x.amount, })), @@ -2269,7 +2419,11 @@ export class DevelopmentController extends Controller { dateEnd: getDevelopment.dateEnd, totalDate: getDevelopment.totalDate, developmentAddresss: - getDevelopment.developmentAddresss == null ? null : getDevelopment.developmentAddresss, + getDevelopment.developmentAddresss == null + ? null + : getDevelopment.developmentAddresss.sort( + (a, b) => new Date(a.createdAt).getTime() - new Date(b.createdAt).getTime(), + ), }; return new HttpSuccess(_getDevelopment); } @@ -2434,7 +2588,7 @@ export class DevelopmentController extends Controller { ? item.posLevel.posLevelName : null : item.employeePosLevel - ? item.employeePosLevel.posLevelName + ? `${item.employeePosType.posTypeShortName ?? ""} ${item.employeePosLevel.posLevelName ?? ""}` : null, posExecutive: item.posExecutive, org: item.org, @@ -2451,9 +2605,9 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน) * - * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ # + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>การฝึกอบรม/ดูงาน) # * * @param {string} id Id โครงการ */ @@ -2481,6 +2635,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + developmentId: id, }) .then((x) => { _data.isDone = true; @@ -2503,6 +2658,7 @@ export class DevelopmentController extends Controller { startDate: x.dateStart, endDate: x.dateEnd, isDate: true, + developmentId: id, }) .then((x) => { _data.isDone = true; @@ -2527,9 +2683,9 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 IDP ส่งบันทึกทะเบียนประวัติ + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 IDP ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>ผลการประเมินการปฏิบัติราชการ) * - * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 IDP ส่งบันทึกทะเบียนประวัติ # + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 IDP ส่งบันทึกทะเบียนประวัติ (ข้อมูลผลงาน>ผลการประเมินการปฏิบัติราชการ)# * * @param {string} id Id โครงการ */ @@ -2539,9 +2695,55 @@ export class DevelopmentController extends Controller { where: { developmentId: id, isDoneIDP: false }, relations: ["development", "development.developmentProjectTechniqueActuals"], }); + + let isDevelopment70: boolean = false; + const dev70Lists = [ + "on_the_job_training", + "job_project_assignment", + "job_shadowing", + "job_enlargement", + "internal_trainer", + "rotation", + "activity", + "site_visit", + "benchmarking", + "problem_solving", + "team_working", + "other1", + ]; + let isDevelopment20: boolean = false; + const dev20Lists = [ + "coaching", + "mentoring", + "team_meeting", + "consulting", + "feedback", + "other2", + ]; + let isDevelopment10: boolean = false; + const dev10Lists = [ + "self_learning", + "classroom_training", + "in_house_training", + "public_training", + "e_training", + "meeting", + "seminar", + "other3", + ]; await Promise.all( getDevelopment.map(async (x) => { const _data = Object.assign(new DevelopmentHistory(), x); + + const techniqueActuals = + x.development?.developmentProjectTechniqueActuals.flatMap((x) => x.name) || []; + isDevelopment70 = + techniqueActuals.length > 0 && dev70Lists.some((item) => techniqueActuals.includes(item)); + isDevelopment20 = + techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item)); + isDevelopment10 = + techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item)); + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "/org/profile/development", { @@ -2555,9 +2757,9 @@ export class DevelopmentController extends Controller { reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: x.development.isReasonActual70, - isDevelopment20: x.development.isReasonActual20, - isDevelopment10: x.development.isReasonActual10, + isDevelopment70: isDevelopment70, + isDevelopment20: isDevelopment20, + isDevelopment10: isDevelopment10, developmentTarget: null, developmentResults: null, developmentReport: null, @@ -2584,9 +2786,9 @@ export class DevelopmentController extends Controller { reasonDevelopment70: x.development.reasonActual70, reasonDevelopment20: x.development.reasonActual20, reasonDevelopment10: x.development.reasonActual10, - isDevelopment70: x.development.isReasonActual70, - isDevelopment20: x.development.isReasonActual20, - isDevelopment10: x.development.isReasonActual10, + isDevelopment70: isDevelopment70, + isDevelopment20: isDevelopment20, + isDevelopment10: isDevelopment10, developmentTarget: null, developmentResults: null, developmentReport: null, diff --git a/src/controllers/DevelopmentEmployeeHistoryController.ts b/src/controllers/DevelopmentEmployeeHistoryController.ts index 2b8054f..007d978 100644 --- a/src/controllers/DevelopmentEmployeeHistoryController.ts +++ b/src/controllers/DevelopmentEmployeeHistoryController.ts @@ -276,6 +276,14 @@ export class DevelopmentEmployeeHistoryController extends Controller { keyword: `%${body.keyword}%`, }, ) + .orWhere( + body.keyword != null && body.keyword != "" + ? "CONCAT(employeePosType.posTypeShortName,' ',employeePosLevel.posLevelName) LIKE :keyword" + : "1=1", + { + keyword: `%${body.keyword}%`, + }, + ) .orWhere( body.keyword != null && body.keyword != "" ? "developmentHistory.position LIKE :keyword" @@ -403,6 +411,7 @@ export class DevelopmentEmployeeHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + trainingDays: getDevelopment.development != null ? getDevelopment.trainingDays : null, // addressAcademic: // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, // topicAcademic: diff --git a/src/controllers/DevelopmentHistoryController.ts b/src/controllers/DevelopmentHistoryController.ts index e546a0c..edb65eb 100644 --- a/src/controllers/DevelopmentHistoryController.ts +++ b/src/controllers/DevelopmentHistoryController.ts @@ -250,6 +250,7 @@ export class DevelopmentOfficerHistoryController extends Controller { .leftJoinAndSelect("developmentHistory.development", "development") .leftJoinAndSelect("developmentHistory.posLevel", "posLevel") .leftJoinAndSelect("developmentHistory.posType", "posType") + .where("developmentHistory.profileId IS NOT NULL") .andWhere( body.year != 0 && body.year != null && body.year != undefined ? "development.year = :year" @@ -389,6 +390,7 @@ export class DevelopmentOfficerHistoryController extends Controller { dateStart: getDevelopment.development != null ? getDevelopment.development.dateStart : null, dateEnd: getDevelopment.development != null ? getDevelopment.development.dateEnd : null, totalDate: getDevelopment.development != null ? getDevelopment.development.totalDate : null, + trainingDays: getDevelopment.development != null ? getDevelopment.trainingDays : null, // addressAcademic: // getDevelopment.development != null ? getDevelopment.development.addressAcademic : null, // topicAcademic: diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 117dfb3..af23f0a 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -161,7 +161,13 @@ export class DevelopmentScholarshipController extends Controller { @Query("year") year?: number, @Query("scholarshipType") scholarshipType?: string, ) { - await new permission().PermissionList(request, "SYS_DEV_SCHOLARSHIP"); + let _data = await new permission().PermissionOrgList(request, "SYS_DEV_SCHOLARSHIP"); + await new CallAPI() + .PostData(request, "/org/finddna", _data) + .then((x) => { + _data = x; + }) + .catch((x) => {}); const [development, total] = await AppDataSource.getRepository(DevelopmentScholarship) .createQueryBuilder("developmentScholarship") .leftJoinAndSelect("developmentScholarship.posLevel", "posLevel") @@ -226,6 +232,16 @@ export class DevelopmentScholarshipController extends Controller { ); }), ) + .andWhere( + _data.root != undefined && _data.root != null + ? _data.root[0] != null + ? `developmentScholarship.rootDnaId IN (:...root)` + : `developmentScholarship.rootDnaId is null` + : "1=1", + { + root: _data.root, + }, + ) .orderBy("developmentScholarship.scholarshipYear", "DESC") .addOrderBy("developmentScholarship.createdAt", "DESC") .skip((page - 1) * pageSize) @@ -264,6 +280,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + rootDnaId: getDevelopment.rootDnaId ? getDevelopment.rootDnaId : null, rootId: getDevelopment.rootId ? getDevelopment.rootId : null, root: getDevelopment.root ? getDevelopment.root : null, org: getDevelopment.org ? getDevelopment.org : null, @@ -282,6 +299,9 @@ export class DevelopmentScholarshipController extends Controller { : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootDnaId: getDevelopment.guarantorRootDnaId + ? getDevelopment.guarantorRootDnaId + : null, guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, @@ -322,7 +342,7 @@ export class DevelopmentScholarshipController extends Controller { bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, - useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, fundType: getDevelopment.fundType ? getDevelopment.fundType : null, @@ -426,6 +446,7 @@ export class DevelopmentScholarshipController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); } const formattedData = { + rootDnaId: getDevelopment.rootDnaId ? getDevelopment.rootDnaId : null, rootId: getDevelopment.rootId ? getDevelopment.rootId : null, root: getDevelopment.root ? getDevelopment.root : null, org: getDevelopment.org ? getDevelopment.org : null, @@ -444,6 +465,9 @@ export class DevelopmentScholarshipController extends Controller { : null, posTypeId: getDevelopment.posTypeId ? getDevelopment.posTypeId : null, posTypeName: getDevelopment.posType?.posTypeName ? getDevelopment.posType?.posTypeName : null, + guarantorRootDnaId: getDevelopment.guarantorRootDnaId + ? getDevelopment.guarantorRootDnaId + : null, guarantorRootId: getDevelopment.guarantorRootId ? getDevelopment.guarantorRootId : null, guarantorRoot: getDevelopment.guarantorRoot ? getDevelopment.guarantorRoot : null, guarantorOrg: getDevelopment.guarantorOrg ? getDevelopment.guarantorOrg : null, @@ -484,7 +508,7 @@ export class DevelopmentScholarshipController extends Controller { bookNo: getDevelopment.bookNo ? getDevelopment.bookNo : null, bookNoDate: getDevelopment.bookNoDate ? getDevelopment.bookNoDate : null, bookApproveDate: getDevelopment.bookApproveDate ? getDevelopment.bookApproveDate : null, - useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : false, + useOfficialTime: getDevelopment.useOfficialTime ? getDevelopment.useOfficialTime : null, changeDetail: getDevelopment.changeDetail ? getDevelopment.changeDetail : null, scholarshipType: getDevelopment.scholarshipType ? getDevelopment.scholarshipType : null, fundType: getDevelopment.fundType ? getDevelopment.fundType : null, @@ -519,6 +543,7 @@ export class DevelopmentScholarshipController extends Controller { profileId: getDevelopment.profileId ? getDevelopment.profileId : null, planType: getDevelopment.planType ? getDevelopment.planType : null, isNoUseBudget: getDevelopment.isNoUseBudget ? getDevelopment.isNoUseBudget : null, + budgetSourceOther: getDevelopment.budgetSourceOther ? getDevelopment.budgetSourceOther : null, }; return new HttpSuccess(formattedData); } @@ -558,6 +583,44 @@ export class DevelopmentScholarshipController extends Controller { return new HttpSuccess(getDevelopment); } + /** + * API รายละเอียดทุนของ admin + * + * @summary DEV_0 - รายละเอียดทุนของ admin # + * + * @param {string} id id รายการ + */ + @Get("admin/detail/{id}") + async GetDevelopemtScholarshipUserDetailAdminById( + @Request() request: RequestWithUser, + @Path() id: string, + ) { + let _workflow = await new permission().Workflow(request, id, "SYS_DEV_SCHOLARSHIP"); + if (_workflow == false) await new permission().PermissionGet(request, "SYS_DEV_SCHOLARSHIP"); + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + select: [ + "id", + "scholarshipYear", + "scholarshipType", + "fundType", + "bookNumber", + "bookDate", + "governmentDate", + "governmentEndDate", + "isGraduated", + "graduatedDate", + "graduatedReason", + "org", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + + return new HttpSuccess(getDevelopment); + } + /** * API รายละเอียดทุนของ user * @@ -621,6 +684,36 @@ export class DevelopmentScholarshipController extends Controller { return new HttpSuccess(getDevelopment.id); } + /** + * API แก้ไขรายการทุนของ admin + * + * @summary DEV_015 - แก้ไขรายการทุนของ admin #15 + * + * @param {string} id รายการ + */ + @Put("admin/detail/{id}") + async UpdateDevelopemtScholarshipAdminById( + @Path() id: string, + @Body() requestBody: UpdateDevelopmentScholarshipUser, + @Request() request: RequestWithUser, + ) { + await new permission().PermissionUpdate(request, "SYS_DEV_SCHOLARSHIP"); + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + const before = structuredClone(getDevelopment); + Object.assign(getDevelopment, requestBody); + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + getDevelopment.lastUpdatedAt = new Date(); + await this.developmentScholarshipRepository.save(getDevelopment, { data: request }); + setLogDataDiff(request, { before, after: getDevelopment }); + return new HttpSuccess(getDevelopment.id); + } + /** * API เปลี่ยนสถานะ * diff --git a/src/controllers/PortfolioController.ts b/src/controllers/PortfolioController.ts index d027420..eecf28a 100644 --- a/src/controllers/PortfolioController.ts +++ b/src/controllers/PortfolioController.ts @@ -59,6 +59,30 @@ export class PortfolioController extends Controller { return new HttpSuccess(_portfolio); } + /** + * API list รายการผลงานสำหรับระบบประเมิน + * + * @summary list รายการผลงานสำหรับระบบประเมิน + * + */ + @Get("user") + async GetResultForEva(@Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: request.user.sub }, + select: [ + "id", + "name", + "detail", + "createdAt", + "lastUpdatedAt", + "createdFullName", + "lastUpdateFullName", + ], + order: { createdAt: "DESC" }, + }); + return new HttpSuccess(_portfolio); + } + /** * API รายละเอียดรายการผลงาน * @@ -79,6 +103,32 @@ export class PortfolioController extends Controller { return new HttpSuccess(_portfolio); } + /** + * API รายละเอียดรายการผลงาน ใช้แสดงในรายงาน ก.พ.7/ก.ก.1 + * + * @summary รายละเอียดรายการผลงาน ใช้แสดงในรายงาน ก.พ.7/ก.ก.1 + * + */ + @Get("kk1/{keycloak}") + async GetPortfolio(@Path() keycloak: string, @Request() request: RequestWithUser) { + const _portfolio = await this.portfolioRepository.find({ + where: { createdUserId: keycloak }, + select: [ + "name", + "createdAt" + ], + order: { createdAt: "DESC" }, + }); + const result = + _portfolio.map(x => ({ + name: x.name, + year: x.createdAt.getFullYear() > 2500 + ? x.createdAt.getFullYear() + : x.createdAt.getFullYear()+543 + })); + return new HttpSuccess(result); + } + /** * API สร้างรายการ body ผลงาน * diff --git a/src/controllers/ReportController.ts b/src/controllers/ReportController.ts index bf63247..e6b9826 100644 --- a/src/controllers/ReportController.ts +++ b/src/controllers/ReportController.ts @@ -16,6 +16,7 @@ import { isNotEmittedStatement } from "typescript"; @Tags("Report") @Security("bearerAuth") export class ReportController extends Controller { + private developmentRepository = AppDataSource.getRepository(Development); private developmentScholarshipRepository = AppDataSource.getRepository(DevelopmentScholarship); private viewDevScholarship = AppDataSource.getRepository(viewDevScholarship); /** @@ -44,6 +45,7 @@ export class ReportController extends Controller { .leftJoinAndSelect("development.strategyChild5Actual", "strategy5") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") + .andWhere("development.rootDnaId = :rootDnaId", { rootDnaId: rootId }) .select([ "development.id AS id", "development.projectName AS projectName", @@ -114,6 +116,7 @@ export class ReportController extends Controller { .leftJoinAndSelect("development.strategyChild1Actual", "strategy1") .where("development.status = :status", { status: "FINISH" }) .andWhere("development.strategyChild1ActualId IS NOT NULL") + .andWhere("development.rootDnaId = :rootDnaId", { rootDnaId: rootId }) .select([ "development.rootId AS rootId", "development.strategyChild1ActualId AS strategyId", @@ -377,10 +380,17 @@ export class ReportController extends Controller { return formattedGroup; }); + const dev = await this.developmentRepository.findOne({ + where: { rootDnaId: rootId }, + select: ["root", "year"] + }) + return new HttpSuccess({ template: "development", reportName: "development", data: { + root: dev && dev.root ? dev.root : "-", + year: dev && dev.year ? Extension.ToThaiNumber((dev.year+543).toString()) : "-", data: mappedDataDev, resultAllStrategy: reformattedData, sumDev1: Extension.ToThaiNumber(sumDev1.toLocaleString()) ?? "-", @@ -431,7 +441,7 @@ export class ReportController extends Controller { .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { year: body.year, }) - .andWhere(body.root != null ? "development.root = :root" : "1=1", { + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root, }) .andWhere("developmentHistory.type = :type", { type: "OFFICER" }) @@ -495,7 +505,7 @@ export class ReportController extends Controller { .andWhere(body.year != 0 && body.year != null ? "development.year = :year" : "1=1", { year: body.year, }) - .andWhere(body.root != null ? "development.root = :root" : "1=1", { + .andWhere(body.root != null ? "developmentHistory.root = :root" : "1=1", { root: body.root, }) .andWhere("developmentHistory.type = :type", { type: "EMPLOYEE" }) @@ -580,31 +590,39 @@ export class ReportController extends Controller { break; case "NOABROAD": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่ไม่มีการไปต่างประเทศ)"; break; case "ABROAD": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรที่มีการไปต่างประเทศ)"; break; case "EXECUTIVE": getDevelopment.scholarshipType = - "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยวงานภายนอก (หลักสูตรประเภทนักบริหาร)"; + "ฝึกอบรมในประเทศที่ส่งไปพัฒนากับหน่วยงานภายนอก (หลักสูตรประเภทนักบริหาร)"; break; case "RESEARCH": getDevelopment.scholarshipType = "ศึกษา ฝึกอบรม ประชุม ดูงาน และปฏิบัติการวิจัย ณ ต่างประเทศ"; break; + case "STUDY": + getDevelopment.scholarshipType = + "ทุนการศึกษา ณ ต่างประเทศ"; + break; + case "TRAINING": + getDevelopment.scholarshipType = + "ทุนฝึกอบรม ณ ต่างประเทศ"; + break; default: break; } } - + let _orgNoNewLine = (getDevelopment.org ? getDevelopment.org : "-").replace(/\n/g, " "); const formattedData = { id: getDevelopment.id, firstName: getDevelopment.firstName, lastName: getDevelopment.lastName, position: getDevelopment.position, - org: getDevelopment.org, + org: _orgNoNewLine, degreeLevel: getDevelopment.degreeLevel, course: getDevelopment.course, field: getDevelopment.field, @@ -640,7 +658,7 @@ export class ReportController extends Controller { : Extension.ToThaiNumber(Extension.ToThaiFullDate3(getDevelopment.graduatedDate)), graduatedReason: getDevelopment.graduatedReason == null ? "" : getDevelopment.graduatedReason, useOfficialTime: getDevelopment.useOfficialTime, - useOffTime: getDevelopment.useOfficialTime == true ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", + useOffTime: getDevelopment.useOfficialTime == "NOUSETIME" ? "🗹 ใช้ ☐ ไม่ใช้" : "☐ ใช้ 🗹 ไม่ใช้", isGraduated: getDevelopment.isGraduated, isG1: getDevelopment.isGraduated == true ? "🗹" : "☐", isG2: getDevelopment.isGraduated == true ? "☐" : "🗹", diff --git a/src/controllers/StrategyController.ts b/src/controllers/StrategyController.ts index ce1cbd2..1f5b4c0 100644 --- a/src/controllers/StrategyController.ts +++ b/src/controllers/StrategyController.ts @@ -6,6 +6,7 @@ import { Patch, Path, Post, + Put, Request, Route, Security, @@ -43,32 +44,46 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + order: "ASC", + strategyChild2s: { + order: "ASC", + strategyChild3s: { + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, + }, + }, + }, }); const formattedData = listStrategyChild1.map((item) => ({ id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -100,7 +115,16 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + order: "ASC", + strategyChild2s: { + order: "ASC", + strategyChild3s: { + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, + }, + }, + }, }); // if (!listStrategyChild1 || listStrategyChild1.length === 0) { @@ -111,25 +135,30 @@ export class StrategyController extends Controller { id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -151,7 +180,16 @@ export class StrategyController extends Controller { "strategyChild2s.strategyChild3s.strategyChild4s", "strategyChild2s.strategyChild3s.strategyChild4s.strategyChild5s", ], - order: { createdAt: "ASC" }, + order: { + order: "ASC", + strategyChild2s: { + order: "ASC", + strategyChild3s: { + order: "ASC", + strategyChild4s: { order: "ASC", strategyChild5s: { order: "ASC" } }, + }, + }, + }, }); // if (!listStrategyChild1 || listStrategyChild1.length === 0) { @@ -162,25 +200,30 @@ export class StrategyController extends Controller { id: item.id, level: 1, name: item.strategyChild1Name, + order: item.order, children: item.strategyChild2s.map((child2) => ({ id: child2.id, level: 2, name: child2.strategyChild2Name, + order: child2.order, children: child2.strategyChild3s ? child2.strategyChild3s.map((child3) => ({ id: child3.id, level: 3, name: child3.strategyChild3Name, + order: child3.order, children: child3.strategyChild4s ? child3.strategyChild4s.map((child4) => ({ id: child4.id, level: 4, name: child4.strategyChild4Name, + order: child4.order, children: child4.strategyChild5s ? child4.strategyChild5s.map((child5) => ({ id: child5.id, level: 5, name: child5.strategyChild5Name, + order: child5.order, })) : [], })) @@ -210,22 +253,31 @@ export class StrategyController extends Controller { switch (body.levelnode) { case 0: + const ckOrder = await this.strategy1Repo.findOne({ + where: {}, + order: { order: "DESC" }, + }); + strategyRepo = this.strategy1Repo; strategyRepo = this.strategy1Repo; repoSave = this.strategy1Repo; strategyChild = new StrategyChild1(); strategyChild.strategyChild1Name = body.name; + strategyChild.order = ckOrder ? ckOrder.order + 1 : 1; break; case 1: strategyRepo = this.strategy1Repo; repoSave = this.strategy2Repo; strategyChild = new StrategyChild2(); strategyChild.strategyChild2Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk1 = await this.strategy1Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk1) { strategyChild.strategyChild1Id = chk1.id; + strategyChild.order = chk1 ? chk1.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -236,13 +288,16 @@ export class StrategyController extends Controller { repoSave = this.strategy3Repo; strategyChild = new StrategyChild3(); strategyChild.strategyChild3Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk2 = await this.strategy2Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk2) { strategyChild.strategyChild1Id = chk2.strategyChild1Id; strategyChild.strategyChild2Id = chk2.id; + strategyChild.order = chk2 ? chk2.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -253,14 +308,17 @@ export class StrategyController extends Controller { repoSave = this.strategy4Repo; strategyChild = new StrategyChild4(); strategyChild.strategyChild4Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk3 = await this.strategy3Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk3) { strategyChild.strategyChild1Id = chk3.strategyChild1Id; strategyChild.strategyChild2Id = chk3.strategyChild2Id; strategyChild.strategyChild3Id = chk3.id; + strategyChild.order = chk3 ? chk3.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -271,15 +329,18 @@ export class StrategyController extends Controller { repoSave = this.strategy5Repo; strategyChild = new StrategyChild5(); strategyChild.strategyChild5Name = body.name; + strategyChild.order = 1; if (body.idnode) { const chk4 = await this.strategy4Repo.findOne({ where: { id: body.idnode }, + order: { order: "DESC" }, }); if (chk4) { strategyChild.strategyChild1Id = chk4.strategyChild1Id; strategyChild.strategyChild2Id = chk4.strategyChild2Id; strategyChild.strategyChild3Id = chk4.strategyChild3Id; strategyChild.strategyChild4Id = chk4.id; + strategyChild.order = chk4 ? chk4.order + 1 : 1; } else { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลยุทธศาสตร์"); } @@ -594,4 +655,89 @@ export class StrategyController extends Controller { throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy); } } + + /** + * API เรียงลำดับ + * + * @summary เรียงลำดับ (ADMIN) + * + */ + @Post("sort") + async sortNode( + @Body() requestBody: { strategy: number; strategyId: string[]; id: string | null }, + @Request() request: RequestWithUser, + ) { + switch (requestBody.strategy) { + case 1: { + const data = await this.strategy1Repo.find(); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy1."); + } + const sortLevel = data.map((data) => ({ + ...data, + order: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy1Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 2: { + const data = await this.strategy2Repo.find({ + where: { strategyChild1Id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy2."); + } + const sortLevel = data.map((data) => ({ + ...data, + order: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy2Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 3: { + const data = await this.strategy3Repo.find({ + where: { strategyChild2Id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy3."); + } + const sortLevel = data.map((data) => ({ + ...data, + order: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy3Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 4: { + const data = await this.strategy4Repo.find({ + where: { strategyChild3Id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy4."); + } + const sortLevel = data.map((data) => ({ + ...data, + order: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy4Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + case 5: { + const data = await this.strategy5Repo.find({ + where: { strategyChild4Id: requestBody.id ?? "" }, + }); + if (data == null) { + throw new HttpError(HttpStatus.NOT_FOUND, "not found strategy5."); + } + const sortLevel = data.map((data) => ({ + ...data, + order: requestBody.strategyId.indexOf(data.id) + 1, + })); + await this.strategy5Repo.save(sortLevel); + return new HttpSuccess(sortLevel); + } + default: + throw new HttpError(HttpStatus.NOT_FOUND, "not found type: " + requestBody.strategy); + } + } } diff --git a/src/entities/ActualGoal.ts b/src/entities/ActualGoal.ts index cbe85aa..2fe2589 100644 --- a/src/entities/ActualGoal.ts +++ b/src/entities/ActualGoal.ts @@ -29,25 +29,39 @@ export class ActualGoal extends EntityBase { @Column({ nullable: true, - comment: "ประเภทตำแหน่ง", + comment: "ประเภทตำแหน่ง & กลุ่มงาน", default: null, }) - posTypeActualId: string; + posTypeActual: string; + + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypeActualId: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.actualGoals) - @JoinColumn({ name: "posTypeActualId" }) - posTypeActual: PosType; + // @ManyToOne(() => PosType, (posType: PosType) => posType.actualGoals) + // @JoinColumn({ name: "posTypeActualId" }) + // posTypeActual: PosType; @Column({ nullable: true, - comment: "ระดับตำแหน่ง", + comment: "ระดับตำแหน่ง & ระดับชั้นงาน", default: null, }) - posLevelActualId: string; + posLevelActual: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.actualGoals) - @JoinColumn({ name: "posLevelActualId" }) - posLevelActual: PosLevel; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelActualId: string; + + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.actualGoals) + // @JoinColumn({ name: "posLevelActualId" }) + // posLevelActual: PosLevel; @Column({ nullable: true, @@ -82,10 +96,14 @@ export class CreateActualGoal { groupTargetSub: string | null; @Column() position: string | null; + // @Column() + // posTypeActualId: string | null; + // @Column() + // posLevelActualId: string | null; @Column() - posTypeActualId: string | null; + posTypeActual: string | null; @Column() - posLevelActualId: string | null; + posLevelActual: string | null; @Column() type: string | null; @Column() diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts index 1629293..8de2fa8 100644 --- a/src/entities/DevelopmentAddress.ts +++ b/src/entities/DevelopmentAddress.ts @@ -20,7 +20,7 @@ export class DevelopmentAddress extends EntityBase { @Column({ nullable: true, - comment: "โครงการ/หลักสูตรการฝึกอบรม", + comment: "ชื่อจังหวัด (กรณีเลือกสถานที่ดำเนินการในประเทศ)", default: null, }) provinceName: string; @@ -32,6 +32,20 @@ export class DevelopmentAddress extends EntityBase { }) developmentId: string; + @Column({ + nullable: true, + comment: "สถานที่ดำเนินการ ในประเทศ(IN_COUNTRY) หรือ ต่างประเทศ(ABROAD)", + default: null, + }) + addressType: string; + + @Column({ + nullable: true, + comment: "ชื่อประเทศ (กรณีเลือกสถานที่ดำเนินการต่างประเทศ)", + default: null, + }) + country: string; + @ManyToOne(() => Development, (development: Development) => development.developmentAddresss) @JoinColumn({ name: "developmentId" }) development: Development; @@ -39,6 +53,16 @@ export class DevelopmentAddress extends EntityBase { export class CreateDevelopmentAddress { @Column() address: string | null; + @Column() provinceId: string | null; + + @Column() + addressType?: string | null; + + @Column() + provinceName?: string | null; + + @Column() + country?: string | null; } diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index efa05ba..24745ae 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,13 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + nullable: true, + comment: "id dna หน่วยงาน", + default: null, + }) + rootDnaId: string; + @Column({ nullable: true, comment: "id หน่วยงาน", @@ -137,6 +144,13 @@ export class DevelopmentScholarship extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; + @Column({ + nullable: true, + comment: "id Dna หน่วยงาน", + default: null, + }) + guarantorRootDnaId: string; + @Column({ nullable: true, comment: "id หน่วยงาน", @@ -301,7 +315,7 @@ export class DevelopmentScholarship extends EntityBase { comment: "ใช้เวลาราชการ", default: false, }) - useOfficialTime: boolean; + useOfficialTime: string; @Column({ nullable: true, @@ -567,8 +581,16 @@ export class DevelopmentScholarship extends EntityBase { default: null, }) graduatedReason: string; + + @Column({ + nullable: true, + comment: "เงินอื่นๆ", + default: null, + }) + budgetSourceOther: string; } export class CreateDevelopmentScholarship { + rootDnaId?: string | null; rootId: string | null; root: string | null; org: string | null; @@ -584,6 +606,7 @@ export class CreateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootDnaId?: string | null; guarantorRootId: string | null; guarantorRoot: string | null; guarantorOrg: string | null; @@ -604,7 +627,7 @@ export class CreateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | false; + useOfficialTime: string | null; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; @@ -631,9 +654,11 @@ export class CreateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; + budgetSourceOther?: string | null; } export class UpdateDevelopmentScholarship { + rootDnaId?: string | null; rootId: string | null; root: string | null; org: string | null; @@ -649,6 +674,7 @@ export class UpdateDevelopmentScholarship { posExecutive: string | null; posLevelId: string | null; posTypeId: string | null; + guarantorRootDnaId?: string | null; guarantorRootId?: string | null; guarantorRoot?: string | null; guarantorOrg?: string | null; @@ -669,7 +695,7 @@ export class UpdateDevelopmentScholarship { bookNo: string | null; bookNoDate: Date | null; bookApproveDate: Date | null; - useOfficialTime: boolean | false; + useOfficialTime: string | null; changeDetail: string | null; scholarshipType: string | null; fundType: string | null; @@ -696,6 +722,7 @@ export class UpdateDevelopmentScholarship { totalPeriod: string | null; planType: string | null; isNoUseBudget: boolean | null; + budgetSourceOther?: string | null; } export class UpdateDevelopmentScholarshipUser { @@ -706,4 +733,5 @@ export class UpdateDevelopmentScholarshipUser { isGraduated: boolean | null; graduatedDate: Date | null; graduatedReason: string | null; + budgetSourceOther?: string | null; } diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts index 990c977..a5df81d 100644 --- a/src/entities/PlannedGoalPosition.ts +++ b/src/entities/PlannedGoalPosition.ts @@ -22,25 +22,39 @@ export class PlannedGoalPosition extends EntityBase { @Column({ nullable: true, - comment: "ประเภทตำแหน่ง", + comment: "ประเภทตำแหน่ง & กลุ่มงาน", default: null, }) - posTypePlannedId: string; + posTypePlanned: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) - @JoinColumn({ name: "posTypePlannedId" }) - posTypePlanned: PosType; + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypePlannedId: string; + + // @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) + // @JoinColumn({ name: "posTypePlannedId" }) + // posTypePlanned: PosType; @Column({ nullable: true, - comment: "ระดับตำแหน่ง", + comment: "ระดับตำแหน่ง & ระดับชั้นงาน", default: null, }) - posLevelPlannedId: string; + posLevelPlanned: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) - @JoinColumn({ name: "posLevelPlannedId" }) - posLevelPlanned: PosLevel; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelPlannedId: string; + + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) + // @JoinColumn({ name: "posLevelPlannedId" }) + // posLevelPlanned: PosLevel; @Column({ nullable: true, @@ -59,10 +73,14 @@ export class CreatePlannedGoalPosition { position: string | null; @Column() posExecutive: string | null; + // @Column() + // posTypePlannedId: string | null; + // @Column() + // posLevelPlannedId: string | null; @Column() - posTypePlannedId: string | null; + posTypePlanned: string | null; @Column() - posLevelPlannedId: string | null; + posLevelPlanned: string | null; } export type UpdatePlannedGoalPosition = Partial; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index 705b6b8..3c686fa 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -48,14 +48,14 @@ export class PosLevel extends EntityBase { @JoinColumn({ name: "posTypeId" }) posType: PosType; - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) - actualGoals: ActualGoal[]; + // @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) + // actualGoals: ActualGoal[]; - @OneToMany( - () => PlannedGoalPosition, - (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posLevelPlanned, - ) - plannedGoalPositions: PlannedGoalPosition[]; + // @OneToMany( + // () => PlannedGoalPosition, + // (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posLevelPlanned, + // ) + // plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posLevel) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/PosType.ts b/src/entities/PosType.ts index d18e7fb..b28047b 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -28,14 +28,14 @@ export class PosType extends EntityBase { @OneToMany(() => PosLevel, (posLevel: PosLevel) => posLevel.posType) posLevels: PosLevel[]; - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) - actualGoals: ActualGoal[]; + // @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) + // actualGoals: ActualGoal[]; - @OneToMany( - () => PlannedGoalPosition, - (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, - ) - plannedGoalPositions: PlannedGoalPosition[]; + // @OneToMany( + // () => PlannedGoalPosition, + // (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, + // ) + // plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/StrategyChild1.ts b/src/entities/StrategyChild1.ts index 05c56ea..8bc9803 100644 --- a/src/entities/StrategyChild1.ts +++ b/src/entities/StrategyChild1.ts @@ -16,6 +16,13 @@ export class StrategyChild1 extends EntityBase { }) strategyChild1Name: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @OneToMany(() => StrategyChild2, (strategyChild2) => strategyChild2.strategyChild1) strategyChild2s: StrategyChild2[]; diff --git a/src/entities/StrategyChild2.ts b/src/entities/StrategyChild2.ts index 9425e59..0f57eef 100644 --- a/src/entities/StrategyChild2.ts +++ b/src/entities/StrategyChild2.ts @@ -22,6 +22,13 @@ export class StrategyChild2 extends EntityBase { }) strategyChild1Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild2s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild3.ts b/src/entities/StrategyChild3.ts index 9698d0c..d8c5ba7 100644 --- a/src/entities/StrategyChild3.ts +++ b/src/entities/StrategyChild3.ts @@ -28,6 +28,13 @@ export class StrategyChild3 extends EntityBase { }) strategyChild2Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild3s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild4.ts b/src/entities/StrategyChild4.ts index 4382a0c..6c5d58e 100644 --- a/src/entities/StrategyChild4.ts +++ b/src/entities/StrategyChild4.ts @@ -34,6 +34,13 @@ export class StrategyChild4 extends EntityBase { }) strategyChild3Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild4s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/entities/StrategyChild5.ts b/src/entities/StrategyChild5.ts index 7282210..9d3f413 100644 --- a/src/entities/StrategyChild5.ts +++ b/src/entities/StrategyChild5.ts @@ -40,6 +40,13 @@ export class StrategyChild5 extends EntityBase { }) strategyChild4Id: string; + @Column({ + nullable: true, + comment: "ลำดับความสำคัญ", + default: null, + }) + order: number; + @ManyToOne(() => StrategyChild1, (strategyChild1) => strategyChild1.strategyChild5s) @JoinColumn({ name: "strategyChild1Id" }) strategyChild1: StrategyChild1; diff --git a/src/interfaces/utils.ts b/src/interfaces/utils.ts index 30035f0..c667f54 100644 --- a/src/interfaces/utils.ts +++ b/src/interfaces/utils.ts @@ -19,10 +19,20 @@ export type LogSequence = { }; export function setLogDataDiff(req: RequestWithUser, data: DataDiff) { - req.app.locals.logData.dataDiff = { - before: JSON.stringify(data.before), - after: JSON.stringify(data.after), - }; + // Check if data.before and data.after are valid objects + if ( + data.before && + typeof data.before === "object" && + data.after && + typeof data.after === "object" + ) { + req.app.locals.logData.dataDiff = { + before: JSON.stringify(data.before), + after: JSON.stringify(data.after), + }; + } else { + console.error("Invalid data provided: both before and after must be valid objects."); + } } export function addLogSequence(req: RequestWithUser, data: LogSequence) { diff --git a/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts b/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts deleted file mode 100644 index c577bb8..0000000 --- a/src/migration/1727719189429-update_developmentHis_add_isDoneIDP.ts +++ /dev/null @@ -1,14 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentHisAddIsDoneIDP1727719189429 implements MigrationInterface { - name = 'UpdateDevelopmentHisAddIsDoneIDP1727719189429' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` ADD \`isDoneIDP\` tinyint NOT NULL COMMENT 'บันทึก IDP ที่ทะเบียนประวัติ' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentHistory\` DROP COLUMN \`isDoneIDP\``); - } - -} diff --git a/src/migration/1727753251629-update_development_add_isReasonActual70.ts b/src/migration/1727753251629-update_development_add_isReasonActual70.ts deleted file mode 100644 index 32c8f84..0000000 --- a/src/migration/1727753251629-update_development_add_isReasonActual70.ts +++ /dev/null @@ -1,24 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentAddIsReasonActual701727753251629 implements MigrationInterface { - name = 'UpdateDevelopmentAddIsReasonActual701727753251629' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual70\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 70 จริง' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual20\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 20 จริง' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual20\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual70\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned20\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned70\``); - } - -} diff --git a/src/migration/1727755044851-update_development_add_isReasonActual10.ts b/src/migration/1727755044851-update_development_add_isReasonActual10.ts deleted file mode 100644 index a5a0c33..0000000 --- a/src/migration/1727755044851-update_development_add_isReasonActual10.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDevelopmentAddIsReasonActual101727755044851 implements MigrationInterface { - name = 'UpdateDevelopmentAddIsReasonActual101727755044851' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน' DEFAULT 0`); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` tinyint NOT NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง' DEFAULT 0`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonActual10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonActual10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 จริง'`); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isReasonPlanned10\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`isReasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); - } - -} diff --git a/src/migration/1737111015155-update_delete_dev_provincename.ts b/src/migration/1737111015155-update_delete_dev_provincename.ts deleted file mode 100644 index 9f0b4e5..0000000 --- a/src/migration/1737111015155-update_delete_dev_provincename.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateDeleteDevProvincename1737111015155 implements MigrationInterface { - name = 'UpdateDeleteDevProvincename1737111015155' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``); - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP FOREIGN KEY \`FK_47bbbecaea9b7b31d2536054656\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_bdafbb824b88c3bdb73adf7f220\``); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD \`provinceName\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม'`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`provinceActualName\` varchar(255) NULL COMMENT 'จังหวัด(ข้อมูลวิชาการ)'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`provinceActualName\``); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP COLUMN \`provinceName\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_bdafbb824b88c3bdb73adf7f220\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD CONSTRAINT \`FK_47bbbecaea9b7b31d2536054656\` FOREIGN KEY (\`provinceActualId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); - } - -} diff --git a/src/migration/1738201344610-Updatedevadddna.ts b/src/migration/1738201344610-Updatedevadddna.ts deleted file mode 100644 index 4b3ebc1..0000000 --- a/src/migration/1738201344610-Updatedevadddna.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class Updatedevadddna1738201344610 implements MigrationInterface { - name = 'Updatedevadddna1738201344610' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DROP INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\``); - await queryRunner.query(`DROP INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\``); - await queryRunner.query(`DROP INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\``); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`rootDnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child1DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child1'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child2DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child2'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child3DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child3'`); - await queryRunner.query(`ALTER TABLE \`development\` ADD \`child4DnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน child4'`); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child4DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child3DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child2DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`child1DnaId\``); - await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`rootDnaId\``); - await queryRunner.query(`CREATE INDEX \`FK_bdafbb824b88c3bdb73adf7f220\` ON \`development\` (\`provinceActualId\`)`); - await queryRunner.query(`CREATE INDEX \`FK_47bbbecaea9b7b31d2536054656\` ON \`developmentOther\` (\`provinceActualId\`)`); - await queryRunner.query(`CREATE INDEX \`FK_e2721b3f440256b56ce83a04fb2\` ON \`developmentAddress\` (\`provinceId\`)`); - } - -} diff --git a/src/migration/1739444714910-updateView.ts b/src/migration/1739444714910-updateView.ts deleted file mode 100644 index ab12b2e..0000000 --- a/src/migration/1739444714910-updateView.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateView1739444714910 implements MigrationInterface { - name = 'UpdateView1739444714910' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, - MAX(\`root\`) AS root,\`degreeLevel\`, - COUNT(*) AS numberOfRecords, - COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, - SUM(\`budgetApprove\`) AS totalBudgetApprove - FROM \`developmentScholarship\` - GROUP BY \`rootId\`,\`degreeLevel\` - `); - await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); - await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); - } - -} diff --git a/src/migration/1739446719623-update_viewDevScholarship.ts b/src/migration/1739446719623-update_viewDevScholarship.ts deleted file mode 100644 index 9a1acbc..0000000 --- a/src/migration/1739446719623-update_viewDevScholarship.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { MigrationInterface, QueryRunner } from "typeorm"; - -export class UpdateViewDevScholarship1739446719623 implements MigrationInterface { - name = 'UpdateViewDevScholarship1739446719623' - - public async up(queryRunner: QueryRunner): Promise { - await queryRunner.query(`CREATE VIEW \`view_dev_scholarship\` AS SELECT MAX(\`rootId\`) AS rootId, - MAX(\`root\`) AS root,\`degreeLevel\`, - COUNT(*) AS numberOfRecords, - COUNT(DISTINCT \`scholarshipType\`) AS numberOfScholarshipTypes, - SUM(\`budgetApprove\`) AS totalBudgetApprove - FROM \`developmentScholarship\` - GROUP BY \`rootId\`,\`degreeLevel\` - `); - await queryRunner.query(`INSERT INTO \`bma_ehr_development_demo\`.\`typeorm_metadata\`(\`database\`, \`schema\`, \`table\`, \`type\`, \`name\`, \`value\`) VALUES (DEFAULT, ?, DEFAULT, ?, ?, ?)`, ["bma_ehr_development_demo","VIEW","view_dev_scholarship","SELECT MAX(`rootId`) AS rootId, \n MAX(`root`) AS root,`degreeLevel`,\n COUNT(*) AS numberOfRecords, \n COUNT(DISTINCT `scholarshipType`) AS numberOfScholarshipTypes,\n SUM(`budgetApprove`) AS totalBudgetApprove\n FROM `developmentScholarship`\n GROUP BY `rootId`,`degreeLevel`"]); - } - - public async down(queryRunner: QueryRunner): Promise { - await queryRunner.query(`DELETE FROM \`bma_ehr_development_demo\`.\`typeorm_metadata\` WHERE \`type\` = ? AND \`name\` = ? AND \`schema\` = ?`, ["VIEW","view_dev_scholarship","bma_ehr_development_demo"]); - await queryRunner.query(`DROP VIEW \`view_dev_scholarship\``); - } - -} diff --git a/src/migration/1750083465733-update30062025604.ts b/src/migration/1750083465733-update30062025604.ts new file mode 100644 index 0000000..8fcdedc --- /dev/null +++ b/src/migration/1750083465733-update30062025604.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Update300620256041750083465733 implements MigrationInterface { + name = 'Update300620256041750083465733' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`rootDnaId\` varchar(255) NULL COMMENT 'id dna หน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`rootDnaId\``); + } + +} diff --git a/src/migration/1750083913468-update30062025605.ts b/src/migration/1750083913468-update30062025605.ts new file mode 100644 index 0000000..644e8c2 --- /dev/null +++ b/src/migration/1750083913468-update30062025605.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class Update300620256051750083913468 implements MigrationInterface { + name = 'Update300620256051750083913468' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`guarantorRootDnaId\` varchar(255) NULL COMMENT 'id Dna หน่วยงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`guarantorRootDnaId\``); + } + +}