From 4f8b2cec736ba0419dbde5b3efd815323814bbf7 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 11 Apr 2024 11:39:56 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B8=9B=E0=B8=A3=E0=B8=B1=E0=B8=9A=E0=B9=82?= =?UTF-8?q?=E0=B8=84=E0=B8=A3=E0=B8=87=E0=B8=B2=E0=B8=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/DevelopmentController.ts | 1057 +++++++++++++---- .../DevelopmentScholarshipController.ts | 1 + src/entities/Development.ts | 422 +++---- src/entities/DevelopmentAddress.ts | 42 + src/entities/DevelopmentEvaluation.ts | 90 ++ src/entities/DevelopmentProjectTechnique.ts | 39 + src/entities/DevelopmentProjectType.ts | 32 + src/entities/Province.ts | 9 +- ...1712778363784-update_table_dev_refresh1.ts | 92 ++ ...1712779710145-update_table_dev_refresh2.ts | 16 + 10 files changed, 1317 insertions(+), 483 deletions(-) create mode 100644 src/entities/DevelopmentAddress.ts create mode 100644 src/entities/DevelopmentEvaluation.ts create mode 100644 src/entities/DevelopmentProjectTechnique.ts create mode 100644 src/entities/DevelopmentProjectType.ts create mode 100644 src/migration/1712778363784-update_table_dev_refresh1.ts create mode 100644 src/migration/1712779710145-update_table_dev_refresh2.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index b7013c5..466db5e 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -18,21 +18,42 @@ import { In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { Development, CreateDevelopment, UpdateDevelopment } from "../entities/Development"; -import { ActualPeople } from "../entities/ActualPeople"; -import { PlannedPeople } from "../entities/PlannedPeople"; -import { ActualGoal } from "../entities/ActualGoal"; -import { PlannedGoal } from "../entities/PlannedGoal"; +import { + Development, + CreateDevelopment, + UpdateDevelopment1, + UpdateDevelopment2_1, + UpdateDevelopment2_2, + UpdateDevelopment3, + UpdateDevelopment4, + UpdateDevelopment5, +} from "../entities/Development"; +import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople"; +import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople"; +import { ActualGoal, CreateActualGoal } from "../entities/ActualGoal"; +import { CreatePlannedGoal, PlannedGoal } from "../entities/PlannedGoal"; import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; +import { DevelopmentHistory } from "../entities/DevelopmentHistory"; +import { DevelopmentProjectType } from "../entities/DevelopmentProjectType"; +import { DevelopmentProjectTechnique } from "../entities/DevelopmentProjectTechnique"; +import { DevelopmentEvaluation } from "../entities/DevelopmentEvaluation"; +import { DevelopmentAddress } from "../entities/DevelopmentAddress"; @Route("api/v1/development/main") @Tags("Development") @Security("bearerAuth") export class DevelopmentController extends Controller { private developmentRepository = AppDataSource.getRepository(Development); + private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress); + private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation); + private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType); + private developmentProjectTechniqueRepository = AppDataSource.getRepository( + DevelopmentProjectTechnique, + ); + private developmentHistoryRepository = AppDataSource.getRepository(DevelopmentHistory); private actualPeopleRepository = AppDataSource.getRepository(ActualPeople); private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople); private actualGoalRepository = AppDataSource.getRepository(ActualGoal); @@ -70,155 +91,34 @@ export class DevelopmentController extends Controller { ); } - if (requestBody.provinceActualId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); - } - } - const development = Object.assign(new Development(), requestBody); - - if (requestBody.provinceIds != null) { - const chkProvince = await this.provinceRepository.find({ - where: { - id: In(requestBody.provinceIds), - }, - }); - - development.provinces = chkProvince; - } development.createdUserId = request.user.sub; development.createdFullName = request.user.name; development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); - await Promise.all( - requestBody.actualPeoples.map(async (x) => { - const data = Object.assign(new ActualPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualPeopleId = development.id; - await this.actualPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedPeoples.map(async (x) => { - const data = Object.assign(new PlannedPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedPeopleId = development.id; - await this.plannedPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.actualGoals.map(async (x) => { - if (x.posTypeActualId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: x.posTypeActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (x.posLevelActualId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - const data = Object.assign(new ActualGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualGoalId = development.id; - await this.actualGoalRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedGoals.map(async (x) => { - const data = Object.assign(new PlannedGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedGoalId = development.id; - await this.plannedGoalRepository.save(data); - - await Promise.all( - x.positions.map(async (y) => { - const _data = Object.assign(new PlannedGoalPosition(), y); - if (y.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: y.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (y.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: y.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - _data.createdUserId = request.user.sub; - _data.createdFullName = request.user.name; - _data.lastUpdateUserId = request.user.sub; - _data.lastUpdateFullName = request.user.name; - _data.plannedGoalId = data.id; - await this.plannedGoalPositionRepository.save(_data); - }), - ); - }), - ); return new HttpSuccess(development.id); } /** - * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม Tab1 * - * @summary DEV_002 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม #2 + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมTab1 # * * @param {string} id Id โครงการ */ - @Put("{id}") - async UpdateDevelopment( + @Put("tab1/{id}") + async UpdateDevelopmentTab1( @Path() id: string, - @Body() requestBody: UpdateDevelopment, + @Body() requestBody: UpdateDevelopment1, @Request() request: { user: Record }, ) { const development = await this.developmentRepository.findOne({ where: { id }, - relations: { - developmentActualPeoples: true, - developmentPlannedPeoples: true, - developmentActualGoals: true, - developmentPlannedGoals: true, - }, }); if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceActualId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceActualId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); - } - } const chk_name = await this.developmentRepository.find({ where: { projectName: requestBody.projectName, @@ -237,116 +137,562 @@ export class DevelopmentController extends Controller { ); } Object.assign(development, requestBody); - if ( - development.developmentPlannedGoals != null && - development.developmentPlannedGoals.length > 0 - ) { - const plannedGoalPosition = await this.plannedGoalPositionRepository.find({ - where: { plannedGoalId: In(development.developmentPlannedGoals.map((x) => x.id)) }, - }); - await this.plannedGoalPositionRepository.remove(plannedGoalPosition); - } - if (requestBody.provinceIds != null) { - const chkProvince = await this.provinceRepository.find({ - where: { - id: In(requestBody.provinceIds), - }, - }); - development.provinces = chkProvince; - } development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; await this.developmentRepository.save(development); - await this.actualPeopleRepository.remove(development.developmentActualPeoples); - await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); - await this.actualGoalRepository.remove(development.developmentActualGoals); - await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + return new HttpSuccess(development.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_1_add/{id}") + async CreateDevelopmenttab2_1( + @Path() id: string, + @Body() requestBody: CreatePlannedGoal, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new PlannedGoal(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedGoalId = development.id; + await this.plannedGoalRepository.save(data); + await Promise.all( - requestBody.actualPeoples.map(async (x) => { - const data = Object.assign(new ActualPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualPeopleId = development.id; - await this.actualPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.plannedPeoples.map(async (x) => { - const data = Object.assign(new PlannedPeople(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentPlannedPeopleId = development.id; - await this.plannedPeopleRepository.save(data); - }), - ); - await Promise.all( - requestBody.actualGoals.map(async (x) => { - if (x.posTypeActualId != null) { + 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.posTypeActualId }, + where: { id: x.posTypePlannedId }, }); if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); } } - if (x.posLevelActualId != null) { + if (x.posLevelPlannedId != null) { const checkId = await this.posLevelRepository.findOne({ - where: { id: x.posLevelActualId }, + where: { id: x.posLevelPlannedId }, }); if (!checkId) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); } } - const data = Object.assign(new ActualGoal(), x); - data.createdUserId = request.user.sub; - data.createdFullName = request.user.name; - data.lastUpdateUserId = request.user.sub; - data.lastUpdateFullName = request.user.name; - data.developmentActualGoalId = development.id; - await this.actualGoalRepository.save(data); + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = data.id; + await this.plannedGoalPositionRepository.save(_data); }), ); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_2_add/{id}") + async CreateDevelopmenttab2_2( + @Path() id: string, + @Body() requestBody: CreatePlannedPeople, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new PlannedPeople(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentPlannedPeopleId = development.id; + await this.plannedPeopleRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_3_add/{id}") + async CreateDevelopmenttab2_3( + @Path() id: string, + @Body() requestBody: CreateActualGoal, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + const data = Object.assign(new ActualGoal(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualGoalId = development.id; + await this.actualGoalRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_4_add/{id}") + async CreateDevelopmenttab2_4( + @Path() id: string, + @Body() requestBody: CreateActualPeople[], + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + const data = Object.assign(new ActualPeople(), requestBody); + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentActualPeopleId = development.id; + await this.actualPeopleRepository.save(data); + return new HttpSuccess(data.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_1_edit/{id}") + async UpdateDevelopmenttab2_1( + @Path() id: string, + @Body() requestBody: CreatePlannedGoal, + @Request() request: { user: Record }, + ) { + const development = await this.plannedGoalRepository.findOne({ + where: { id }, + relations: { + plannedGoalPositions: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + + await this.plannedGoalPositionRepository.remove(development.plannedGoalPositions); + const _requestBody: any = requestBody; + delete _requestBody.positions; + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.plannedGoalRepository.save(development); + + if (requestBody.positions != null) { + 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, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (x.posLevelPlannedId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: x.posLevelPlannedId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + _data.createdUserId = request.user.sub; + _data.createdFullName = request.user.name; + _data.lastUpdateUserId = request.user.sub; + _data.lastUpdateFullName = request.user.name; + _data.plannedGoalId = development.id; + await this.plannedGoalPositionRepository.save(_data); + }), + ); + } + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_2_edit/{id}") + async UpdateDevelopmenttab2_2( + @Path() id: string, + @Body() requestBody: CreatePlannedPeople, + @Request() request: { user: Record }, + ) { + const development = await this.plannedPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.plannedPeopleRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_3_edit/{id}") + async UpdateDevelopmenttab2_3( + @Path() id: string, + @Body() requestBody: CreateActualGoal, + @Request() request: { user: Record }, + ) { + const development = await this.actualGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.posTypeActualId != null) { + const checkId = await this.posTypeRepository.findOne({ + where: { id: requestBody.posTypeActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + } + } + if (requestBody.posLevelActualId != null) { + const checkId = await this.posLevelRepository.findOne({ + where: { id: requestBody.posLevelActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + } + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.actualGoalRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab2_4_edit/{id}") + async UpdateDevelopmenttab2_4( + @Path() id: string, + @Body() requestBody: CreateActualPeople, + @Request() request: { user: Record }, + ) { + const development = await this.actualPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.actualPeopleRepository.save(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-1 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_1/{id}") + async DeleteDevelopmenttab2_1(@Path() id: string) { + const development = await this.plannedGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามแผน"); + } + const _development = await this.plannedGoalPositionRepository.find({ + where: { plannedGoalId: id }, + }); + await this.plannedGoalPositionRepository.remove(_development); + await this.plannedGoalRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-2 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_2/{id}") + async DeleteDevelopmenttab2_2(@Path() id: string) { + const development = await this.plannedPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน"); + } + await this.plannedPeopleRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-3 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_3/{id}") + async DeleteDevelopmenttab2_3(@Path() id: string) { + const development = await this.actualGoalRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มเป้าหมายตามจริง"); + } + await this.actualGoalRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4 + * + * @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab2-4 # + * + * @param {string} id Id รายการ + */ + @Delete("tab2_4/{id}") + async DeleteDevelopmenttab2_4(@Path() id: string) { + const development = await this.actualPeopleRepository.findOne({ + where: { id }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามจริง"); + } + await this.actualPeopleRepository.remove(development); + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab3 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab3 # + * + * @param {string} id Id โครงการ + */ + @Put("tab3/{id}") + async UpdateDevelopmentTab3( + @Path() id: string, + @Body() requestBody: UpdateDevelopment3, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentProjectTypes: true, + developmentProjectTechniques: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + await this.developmentProjectTechniqueRepository.remove( + development.developmentProjectTechniques, + ); + if (requestBody.developmentProjectTypes != null) { + await Promise.all( + requestBody.developmentProjectTypes.map(async (x) => { + let data = new DevelopmentProjectType(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTypeRepository.save(data); + }), + ); + } + if (requestBody.developmentProjectTechniques != null) { + await Promise.all( + requestBody.developmentProjectTechniques.map(async (x) => { + let data = new DevelopmentProjectTechnique(); + data.name = x; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentProjectTechniqueRepository.save(data); + }), + ); + } + return new HttpSuccess(development.id); + } + + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab4 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab4 # + * + * @param {string} id Id โครงการ + */ + @Put("tab4/{id}") + async UpdateDevelopmentTab4( + @Path() id: string, + @Body() requestBody: UpdateDevelopment4, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentEvaluations: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentEvaluationRepository.remove(development.developmentEvaluations); await Promise.all( - requestBody.plannedGoals.map(async (x) => { - const data = Object.assign(new PlannedGoal(), x); + requestBody.developmentEvaluations.map(async (x) => { + const data = Object.assign(new DevelopmentEvaluation(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; data.lastUpdateUserId = request.user.sub; data.lastUpdateFullName = request.user.name; - data.developmentPlannedGoalId = development.id; - await this.plannedGoalRepository.save(data); + data.developmentId = development.id; + await this.developmentEvaluationRepository.save(data); + }), + ); + return new HttpSuccess(development.id); + } - await Promise.all( - x.positions.map(async (y) => { - const _data = Object.assign(new PlannedGoalPosition(), y); - if (y.posTypePlannedId != null) { - const checkId = await this.posTypeRepository.findOne({ - where: { id: y.posTypePlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); - } - } - if (y.posLevelPlannedId != null) { - const checkId = await this.posLevelRepository.findOne({ - where: { id: y.posLevelPlannedId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } - _data.createdUserId = request.user.sub; - _data.createdFullName = request.user.name; - _data.lastUpdateUserId = request.user.sub; - _data.lastUpdateFullName = request.user.name; - _data.plannedGoalId = data.id; - await this.plannedGoalPositionRepository.save(_data); - }), - ); + /** + * API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5 + * + * @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab5 # + * + * @param {string} id Id โครงการ + */ + @Put("tab5/{id}") + async UpdateDevelopmentTab5( + @Path() id: string, + @Body() requestBody: UpdateDevelopment5, + @Request() request: { user: Record }, + ) { + const development = await this.developmentRepository.findOne({ + where: { id }, + relations: { + developmentAddresss: true, + }, + }); + if (!development) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + if (requestBody.provinceActualId != null) { + const checkId = await this.provinceRepository.findOne({ + where: { id: requestBody.provinceActualId }, + }); + if (!checkId) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดข้อมูลด้านวิชาการ"); + } + } + Object.assign(development, requestBody); + development.lastUpdateUserId = request.user.sub; + development.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(development); + await this.developmentAddresssRepository.remove(development.developmentAddresss); + await Promise.all( + requestBody.developmentAddresss.map(async (x) => { + const data = Object.assign(new DevelopmentAddress(), x); + const chkProvince = await this.provinceRepository.find({ + where: { + id: x.provinceId, + }, + }); + if (chkProvince == null) return; + data.createdUserId = request.user.sub; + data.createdFullName = request.user.name; + data.lastUpdateUserId = request.user.sub; + data.lastUpdateFullName = request.user.name; + data.developmentId = development.id; + await this.developmentAddresssRepository.save(data); }), ); return new HttpSuccess(development.id); @@ -417,6 +763,10 @@ export class DevelopmentController extends Controller { developmentPlannedPeoples: true, developmentActualGoals: true, developmentPlannedGoals: true, + developmentProjectTypes: true, + developmentProjectTechniques: true, + developmentEvaluations: true, + developmentAddresss: true, }, }); if (!development) { @@ -436,6 +786,12 @@ export class DevelopmentController extends Controller { await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); await this.actualGoalRepository.remove(development.developmentActualGoals); await this.plannedGoalRepository.remove(development.developmentPlannedGoals); + await this.developmentProjectTypeRepository.remove(development.developmentProjectTypes); + await this.developmentProjectTechniqueRepository.remove( + development.developmentProjectTechniques, + ); + await this.developmentEvaluationRepository.remove(development.developmentEvaluations); + await this.developmentAddresssRepository.remove(development.developmentAddresss); await this.developmentRepository.remove(development); return new HttpSuccess(); } @@ -451,6 +807,7 @@ export class DevelopmentController extends Controller { @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("year") year: number, + @Query("status") status: string, @Query("keyword") keyword?: string, ) { const [development, total] = await AppDataSource.getRepository(Development) @@ -458,6 +815,9 @@ export class DevelopmentController extends Controller { .andWhere(year > 0 ? "development.year LIKE :year" : "1=1", { year: `${year.toString()}`, }) + .andWhere(status != undefined ? "development.status LIKE :status" : "1=1", { + status: `%${status}%`, + }) .andWhere(keyword != undefined ? "development.projectName LIKE :keyword" : "1=1", { keyword: `%${keyword}%`, }) @@ -472,14 +832,106 @@ export class DevelopmentController extends Controller { } /** - * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม + * API ปิดโครงการ * - * @summary DEV_005 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรม #5 + * @summary DEV_00 - ปิดโครงการ # * * @param {string} id Id โครงการ */ - @Get("{id}") - async GetDevelopemtById(@Path() id: string) { + @Get("finish/{id}") + async FinishDevelopemtById( + @Path() id: string, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + getDevelopment.status = "FINISH"; + getDevelopment.lastUpdateUserId = request.user.sub; + getDevelopment.lastUpdateFullName = request.user.name; + await this.developmentRepository.save(getDevelopment); + return new HttpSuccess(getDevelopment); + } + + /** + * API สถานะโครงการ + * + * @summary DEV_00 - สถานะโครงการ # + * + * @param {string} id Id โครงการ + */ + @Get("status/{id}") + async StatusDevelopemtById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + select: ["id", "status"], + }); + return new HttpSuccess(getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab1 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab1 # + * + * @param {string} id Id โครงการ + */ + @Get("tab1/{id}") + async GetDevelopemtTab1ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + select: ["id", "year", "projectName", "reason", "objective"], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + return new HttpSuccess(getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab2 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab2 # + * + * @param {string} id Id โครงการ + */ + @Get("tab2/{id}") + async GetDevelopemtTab2ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = { + id: getDevelopment.id, + actualPeoples: getDevelopment.developmentActualPeoples, + plannedPeoples: getDevelopment.developmentPlannedPeoples, + actualGoals: getDevelopment.developmentActualGoals, + plannedGoals: getDevelopment.developmentPlannedGoals, + }; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab3 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab3 # + * + * @param {string} id Id โครงการ + */ + @Get("tab3/{id}") + async GetDevelopemtTab3ById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, relations: [ @@ -507,4 +959,167 @@ export class DevelopmentController extends Controller { delete _getDevelopment.developmentPlannedGoals; return new HttpSuccess(_getDevelopment); } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab4 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab4 # + * + * @param {string} id Id โครงการ + */ + @Get("tab4/{id}") + async GetDevelopemtTab4ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab5 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab5 # + * + * @param {string} id Id โครงการ + */ + @Get("tab5/{id}") + async GetDevelopemtTab5ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6 + * + * @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 # + * + * @param {string} id Id โครงการ + */ + @Get("tab6/{id}") + async GetDevelopemtTab6ById(@Path() id: string) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + let _getDevelopment: any = getDevelopment; + _getDevelopment.actualPeoples = getDevelopment.developmentActualPeoples; + _getDevelopment.plannedPeoples = getDevelopment.developmentPlannedPeoples; + _getDevelopment.actualGoals = getDevelopment.developmentActualGoals; + _getDevelopment.plannedGoals = getDevelopment.developmentPlannedGoals; + // _getDevelopment.provinces = getDevelopment.provinces.map(x=>x.developmentProvinces); + delete _getDevelopment.developmentActualPeoples; + delete _getDevelopment.developmentPlannedPeoples; + delete _getDevelopment.developmentActualGoals; + delete _getDevelopment.developmentPlannedGoals; + return new HttpSuccess(_getDevelopment); + } + + /** + * API upload User + * + * @summary DEV_0 - upload User # + * + * @param {string} id Id โครงการ + */ + @Get("zxczxc/{id}") + async UploadUserDevelopemtById( + @Path() id: string, + @Request() request: { user: Record }, + ) { + const getDevelopment = await this.developmentRepository.findOne({ + where: { id: id }, + relations: ["developmentHistory"], + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); + } + await this.developmentHistoryRepository.remove(getDevelopment.developmentHistorys); + + // await Promise.all( + // positions.map(async (x) => { + // const data = Object.assign(new DevelopmentHistory(), x); + // if (x.posTypeId != null) { + // const checkId = await this.posTypeRepository.findOne({ + // where: { id: x.posTypeId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลประเภทตำแหน่ง"); + // } + // } + // if (x.posLevelId != null) { + // const checkId = await this.posLevelRepository.findOne({ + // where: { id: x.posLevelId }, + // }); + // if (!checkId) { + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่ง"); + // } + // } + // data.developmentId = getDevelopment.id; + // data.createdUserId = request.user.sub; + // data.createdFullName = request.user.name; + // data.lastUpdateUserId = request.user.sub; + // data.lastUpdateFullName = request.user.name; + // await this.plannedGoalPositionRepository.save(data); + // }), + // ); + + return new HttpSuccess(); + } } diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 10b552b..3ef6c50 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -313,6 +313,7 @@ export class DevelopmentScholarshipController extends Controller { : null, totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, status: getDevelopment.status ? getDevelopment.status : null, + profileId: getDevelopment.profileId ? getDevelopment.profileId : null, }; return new HttpSuccess(formattedData); } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index ca6d988..bae93d3 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -6,9 +6,22 @@ import { CreatePlannedPeople, PlannedPeople } from "./PlannedPeople"; import { ActualGoal, CreateActualGoal } from "./ActualGoal"; import { CreatePlannedGoal, PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; +import { DevelopmentProjectType } from "./DevelopmentProjectType"; +import { DevelopmentProjectTechnique } from "./DevelopmentProjectTechnique"; +import { CreateDevelopmentEvaluation, DevelopmentEvaluation } from "./DevelopmentEvaluation"; +import { CreateDevelopmentAddress, DevelopmentAddress } from "./DevelopmentAddress"; @Entity("development") export class Development extends EntityBase { + @Column({ + // กำลังดำเนินการ (ONGOING) + // เสร็จสิ้น (FINISH) + nullable: true, + comment: "สถานะ", + default: "ONGOING", + }) + status: string; + ////////////////////////////////////////tab ข้อมูลเบื้องต้น @Column({ nullable: true, comment: "ปีงบประมาณ", @@ -35,61 +48,118 @@ export class Development extends EntityBase { }) objective: string; + ////////////////////////////////////////tab เป้าหมาย + @OneToMany( + () => ActualPeople, + (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, + ) + developmentActualPeoples: ActualPeople[]; + + @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.developmentActualGoal) + developmentActualGoals: ActualGoal[]; + + @OneToMany( + () => PlannedPeople, + (plannedPeople: PlannedPeople) => plannedPeople.developmentPlannedPeople, + ) + developmentPlannedPeoples: PlannedPeople[]; + + @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) + developmentPlannedGoals: PlannedGoal[]; + + ////////////////////////////////////////tab ลักษณะโครงการ + @OneToMany( + () => DevelopmentProjectType, + (developmentProjectType: DevelopmentProjectType) => developmentProjectType.development, + ) + developmentProjectTypes: DevelopmentProjectType[]; + @Column({ - nullable: true, - comment: "ประเภทตัวชี้วัด", - default: null, + comment: "ไป-กลับ", + default: false, }) - metricType: string; + isBackPlanned: boolean; + + @Column({ + comment: "พักค้าง", + default: false, + }) + isHoldPlanned: boolean; @Column({ nullable: true, - comment: "ตัวชี้วัด", + comment: "จำนวน(วัน)(ไป-กลับ)", default: null, }) - indicators: string; + projectDayBackPlanned: number; @Column({ nullable: true, - comment: "เป้าหมาย", + comment: "จำนวน(วัน)(พักค้าง)", default: null, }) - target: string; + projectDayHoldPlanned: number; @Column({ nullable: true, - comment: "วิธีการคำนวณ/เครื่องมือ", + comment: "จำนวน(คืน)(พักค้าง)", default: null, }) - calculation: string; + projectNigthHoldPlanned: number; + + @Column({ + comment: "ไป-กลับ", + default: false, + }) + isBackActual: boolean; + + @Column({ + comment: "พักค้าง", + default: false, + }) + isHoldActual: boolean; @Column({ nullable: true, - comment: "ระยะเวลาวัดผล", + comment: "จำนวน(วัน)(ไป-กลับ)", default: null, }) - measuRement: string; + projectDayBackActual: number; @Column({ nullable: true, - comment: "ผลการดำเนิน", + comment: "จำนวน(วัน)(พักค้าง)", default: null, }) - results: string; + projectDayHoldActual: number; @Column({ nullable: true, - comment: "ปัญหาอุปสรรค", + comment: "จำนวน(คืน)(พักค้าง)", default: null, }) - obstacles: string; + projectNigthHoldActual: number; + + @OneToMany( + () => DevelopmentProjectTechnique, + (developmentProjectTechnique: DevelopmentProjectTechnique) => + developmentProjectTechnique.development, + ) + developmentProjectTechniques: DevelopmentProjectTechnique[]; @Column({ nullable: true, - comment: "ข้อเสนอเเนะ", + comment: "จำนวน(รุ่น)", default: null, }) - suggestions: string; + projectModal: number; + + ////////////////////////////////////////tab ผลประเมิน + @OneToMany( + () => DevelopmentEvaluation, + (developmentEvaluation: DevelopmentEvaluation) => developmentEvaluation.development, + ) + developmentEvaluations: DevelopmentEvaluation[]; @Column({ nullable: true, @@ -129,6 +199,7 @@ export class Development extends EntityBase { }) isOutBudget: boolean; + ////////////////////////////////////////tab อื่นๆ @Column({ nullable: true, type: "datetime", @@ -152,12 +223,11 @@ export class Development extends EntityBase { }) totalDate: number; - @Column({ - nullable: true, - comment: "ที่อยู่", - default: null, - }) - address: string; + @OneToMany( + () => DevelopmentAddress, + (developmentAddress: DevelopmentAddress) => developmentAddress.development, + ) + developmentAddresss: DevelopmentAddress[]; @Column({ nullable: true, @@ -166,6 +236,16 @@ export class Development extends EntityBase { }) budget: string; + @Column({ + // เงินบำรุง = MAINTENANCE + // เงินกองทุน = FUND + // เงินอุดหนุน = SUBSIDY + nullable: true, + comment: "ประเภทย่อย", + default: null, + }) + budgetSub: string; + @Column({ nullable: true, comment: "จํานวนงบประมาณที่ขอรับการจัดสรรฯ", @@ -210,14 +290,14 @@ export class Development extends EntityBase { comment: "โอกาสที่จะเกิด", default: null, }) - chance: string; + chance: number; @Column({ nullable: true, comment: "ผลกระทบจากการเกิด", default: null, }) - effects: string; + effects: number; @Column({ nullable: true, @@ -254,6 +334,17 @@ export class Development extends EntityBase { }) addressAcademic: string; + @Column({ + nullable: true, + comment: "จังหวัด(ข้อมูลวิชาการ)", + default: null, + }) + provinceActualId: string; + + @ManyToOne(() => Province, (province: Province) => province.developmentActuals) + @JoinColumn({ name: "provinceActualId" }) + provinceActual: Province; + @Column({ nullable: true, type: "datetime", @@ -270,105 +361,6 @@ export class Development extends EntityBase { }) dateStudyEnd: Date; - @Column({ - // STRATEGIC_PROJECT = โครงการตามยุทธศาสตร์ - // MISSION_PROJECT = โครงการตามภารกิจประจำของหน่วยงาน - // NEW_PROJECT = โครงการใหม่ - // ONGOING_PROJECT = โครงการต่อเนื่อง - nullable: true, - comment: "ประเภทโครงการ", - default: null, - }) - projectType: string; - - @Column({ - // GO_BACK = ไป-กลับ - // HOLD = พักค้าง - // GO_BACK_HOLD = ไป-กลับและพักค้าง - nullable: true, - comment: "ลักษณะ", - default: null, - }) - projectCharacteristics: string; - - @Column({ - nullable: true, - comment: "จำนวน(วัน)", - default: null, - }) - projectDay: number; - - @Column({ - nullable: true, - comment: "จำนวน(คืน)", - default: null, - }) - projectNigth: number; - - @Column({ - // TRAINING = การอบรม - // MEETING = การประชุม - // SEMINAR = การสัมมนา - // STUDY_TOUR = การศึกษาดูงาน - // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ - // WORKSHOP = การสัมมนาเชิงปฏิบัติการ - // SPECIAL_LECTURE = การบรรยายพิเศษ - // STUDY_TRAINING = การฝึกศึกษา - nullable: true, - comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", - default: null, - }) - projectTechniques: string; - - @Column({ - nullable: true, - comment: "จำนวน(รุ่น)", - default: null, - }) - projectModal: number; - - @Column({ - // เงินบำรุง = MAINTENANCE - // เงินกองทุน = FUND - // เงินอุดหนุน = SUBSIDY - nullable: true, - comment: "ประเภทย่อย", - default: null, - }) - budgetSub: string; - - @Column({ - nullable: true, - comment: "จังหวัด(ข้อมูลวิชาการ)", - default: null, - }) - provinceActualId: string; - - @ManyToOne(() => Province, (province: Province) => province.developmentActuals) - @JoinColumn({ name: "provinceActualId" }) - provinceActual: Province; - - @ManyToMany(() => Province, (provinces) => provinces.developmentProvinces) - provinces: Province[]; - - @OneToMany( - () => ActualPeople, - (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, - ) - developmentActualPeoples: ActualPeople[]; - - @OneToMany( - () => PlannedPeople, - (plannedPeople: PlannedPeople) => plannedPeople.developmentPlannedPeople, - ) - developmentPlannedPeoples: PlannedPeople[]; - - @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.developmentActualGoal) - developmentActualGoals: ActualGoal[]; - - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal) - developmentPlannedGoals: PlannedGoal[]; - @OneToMany( () => DevelopmentHistory, (developmentHistory: DevelopmentHistory) => developmentHistory.development, @@ -380,105 +372,9 @@ export class CreateDevelopment { year: number; @Column() projectName: string; - @Column() - reason: string | null; - @Column() - objective: string | null; - @Column() - metricType: string | null; - @Column() - indicators: string | null; - @Column() - target: string | null; - @Column() - calculation: string | null; - @Column() - measuRement: string | null; - @Column() - results: string | null; - @Column() - obstacles: string | null; - @Column() - suggestions: string | null; - @Column() - project: string | null; - @Column() - isPassAllocate: boolean; - @Column() - isPassNoAllocate: boolean; - @Column() - isNoPass: boolean; - @Column() - isBudget: boolean; - @Column() - isOutBudget: boolean; - @Column() - dateStart: Date | null; - @Column() - dateEnd: Date | null; - @Column() - totalDate: number | null; - @Column() - address: string | null; - @Column() - provinceIds: string[]; - @Column() - budget: string | null; - @Column() - accept: Double | null; - @Column() - receive: Double | null; - @Column() - approved: Double | null; - @Column() - budgetPay: Double | null; - @Column() - issues: string | null; - @Column() - chance: string | null; - @Column() - effects: string | null; - @Column() - riskLevel: string | null; - @Column() - riskManagement: string | null; - @Column() - expect: string | null; - @Column() - topicAcademic: string | null; - @Column() - addressAcademic: string | null; - @Column() - provinceActualId: string | null; - @Column() - dateStudyStart?: Date | null; - @Column() - dateStudyEnd?: Date | null; - @Column() - projectType: string | null; - @Column() - projectCharacteristics: string | null; - @Column() - projectDay: number | null; - @Column() - projectNigth: number | null; - @Column() - projectTechniques: string | null; - @Column() - projectModal: number | null; - @Column() - budgetSub: string | null; - @Column() - actualPeoples: CreateActualPeople[]; - @Column() - plannedPeoples: CreatePlannedPeople[]; - @Column() - actualGoals: CreateActualGoal[]; - @Column() - plannedGoals: CreatePlannedGoal[]; } -export class UpdateDevelopment { +export class UpdateDevelopment1 { @Column() year: number; @Column() @@ -487,22 +383,50 @@ export class UpdateDevelopment { reason: string | null; @Column() objective: string | null; +} +export class UpdateDevelopment2_1 { @Column() - metricType: string | null; + actualGoals: CreateActualGoal[]; @Column() - indicators: string | null; + plannedGoals: CreatePlannedGoal[]; +} +export class UpdateDevelopment2_2 { @Column() - target: string | null; + actualPeoples: CreateActualPeople[]; @Column() - calculation: string | null; + plannedPeoples: CreatePlannedPeople[]; +} +export class UpdateDevelopment3 { @Column() - measuRement: string | null; + developmentProjectTypes?: string[]; @Column() - results: string | null; + isBackPlanned?: boolean | null; @Column() - obstacles: string | null; + isHoldPlanned?: boolean | null; @Column() - suggestions: string | null; + projectDayBackPlanned?: number | null; + @Column() + projectDayHoldPlanned?: number | null; + @Column() + projectNigthHoldPlanned?: number | null; + @Column() + isBackActual?: boolean | null; + @Column() + isHoldActual?: boolean | null; + @Column() + projectDayBackActual?: number | null; + @Column() + projectDayHoldActual?: number | null; + @Column() + projectNigthHoldActual?: number | null; + @Column() + developmentProjectTechniques?: string[]; + @Column() + projectModal?: number | null; +} +export class UpdateDevelopment4 { + @Column() + developmentEvaluations: CreateDevelopmentEvaluation[]; @Column() project: string | null; @Column() @@ -515,6 +439,8 @@ export class UpdateDevelopment { isBudget: boolean; @Column() isOutBudget: boolean; +} +export class UpdateDevelopment5 { @Column() dateStart: Date | null; @Column() @@ -522,12 +448,12 @@ export class UpdateDevelopment { @Column() totalDate: number | null; @Column() - address: string | null; - @Column() - provinceIds: string[]; + developmentAddresss: CreateDevelopmentAddress[]; @Column() budget: string | null; @Column() + budgetSub: string | null; + @Column() accept: Double | null; @Column() receive: Double | null; @@ -538,9 +464,9 @@ export class UpdateDevelopment { @Column() issues: string | null; @Column() - chance: string | null; + chance: number | null; @Column() - effects: string | null; + effects: number | null; @Column() riskLevel: string | null; @Column() @@ -554,29 +480,7 @@ export class UpdateDevelopment { @Column() provinceActualId: string | null; @Column() - dateStudyStart?: Date | null; + dateStudyStart: Date | null; @Column() - dateStudyEnd?: Date | null; - @Column() - projectType?: string | null; - @Column() - projectCharacteristics?: string | null; - @Column() - projectDay?: number | null; - @Column() - projectNigth?: number | null; - @Column() - projectTechniques?: string | null; - @Column() - projectModal?: number | null; - @Column() - budgetSub: string | null; - @Column() - actualPeoples: CreateActualPeople[]; - @Column() - plannedPeoples: CreatePlannedPeople[]; - @Column() - actualGoals: CreateActualGoal[]; - @Column() - plannedGoals: CreatePlannedGoal[]; + dateStudyEnd: Date | null; } diff --git a/src/entities/DevelopmentAddress.ts b/src/entities/DevelopmentAddress.ts new file mode 100644 index 0000000..e1490c8 --- /dev/null +++ b/src/entities/DevelopmentAddress.ts @@ -0,0 +1,42 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; +import { Province } from "./Province"; + +@Entity("developmentAddress") +export class DevelopmentAddress extends EntityBase { + @Column({ + nullable: true, + comment: "ที่อยู่", + default: null, + }) + address: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + provinceId: string; + + @ManyToOne(() => Province, (province: Province) => province.developmentAddresss) + @JoinColumn({ name: "provinceId" }) + province: Province; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentAddresss) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentAddress { + @Column() + address: string | null; + @Column() + provinceId: string; +} diff --git a/src/entities/DevelopmentEvaluation.ts b/src/entities/DevelopmentEvaluation.ts new file mode 100644 index 0000000..0e4a4c4 --- /dev/null +++ b/src/entities/DevelopmentEvaluation.ts @@ -0,0 +1,90 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentEvaluation") +export class DevelopmentEvaluation extends EntityBase { + @Column({ + nullable: true, + comment: "ตัวชี้วัด", + default: null, + }) + indicators: string; + + @Column({ + nullable: true, + comment: "เป้าหมาย", + default: null, + }) + target: number; + + @Column({ + nullable: true, + comment: "ประเภทตัวชี้วัด", + default: null, + }) + metricType: string; + + @Column({ + nullable: true, + comment: "วิธีการคำนวณ/เครื่องมือ", + default: null, + }) + calculation: string; + + @Column({ + nullable: true, + comment: "ระยะเวลาวัดผล", + default: null, + }) + measuRement: string; + + @Column({ + nullable: true, + comment: "ผลการดำเนิน", + default: null, + }) + results: string; + + @Column({ + nullable: true, + comment: "ปัญหาอุปสรรค", + default: null, + }) + obstacles: string; + + @Column({ + nullable: true, + comment: "ข้อเสนอเเนะ", + default: null, + }) + suggestions: string; + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentEvaluations) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentEvaluation { + @Column() + indicators: string | null; + @Column() + target: number | null; + @Column() + metricType: string | null; + @Column() + calculation: string | null; + @Column() + measuRement: string | null; + @Column() + results: string | null; + @Column() + obstacles: string | null; + @Column() + suggestions: string | null; +} diff --git a/src/entities/DevelopmentProjectTechnique.ts b/src/entities/DevelopmentProjectTechnique.ts new file mode 100644 index 0000000..2d3ac30 --- /dev/null +++ b/src/entities/DevelopmentProjectTechnique.ts @@ -0,0 +1,39 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentProjectTechnique") +export class DevelopmentProjectTechnique extends EntityBase { + @Column({ + // TRAINING = การอบรม + // MEETING = การประชุม + // SEMINAR = การสัมมนา + // STUDY_TOUR = การศึกษาดูงาน + // ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ + // WORKSHOP = การสัมมนาเชิงปฏิบัติการ + // SPECIAL_LECTURE = การบรรยายพิเศษ + // STUDY_TRAINING = การฝึกศึกษา + nullable: true, + comment: "เทคนิควิธีการที่ใช้ในการพัฒนา", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne( + () => Development, + (development: Development) => development.developmentProjectTechniques, + ) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentProjectTechnique { + @Column() + name: number; +} diff --git a/src/entities/DevelopmentProjectType.ts b/src/entities/DevelopmentProjectType.ts new file mode 100644 index 0000000..447dbbd --- /dev/null +++ b/src/entities/DevelopmentProjectType.ts @@ -0,0 +1,32 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Development } from "./Development"; + +@Entity("developmentProjectType") +export class DevelopmentProjectType extends EntityBase { + @Column({ + // STRATEGIC_PROJECT = โครงการตามยุทธศาสตร์ + // MISSION_PROJECT = โครงการตามภารกิจประจำของหน่วยงาน + // NEW_PROJECT = โครงการใหม่ + // ONGOING_PROJECT = โครงการต่อเนื่อง + nullable: true, + comment: "ประเภทโครงการ", + default: null, + }) + name: string; + + @Column({ + nullable: true, + comment: "โครงการ/หลักสูตรการฝึกอบรม", + default: null, + }) + developmentId: string; + + @ManyToOne(() => Development, (development: Development) => development.developmentProjectTypes) + @JoinColumn({ name: "developmentId" }) + development: Development; +} +export class CreateDevelopmentProjectType { + @Column() + name: string; +} diff --git a/src/entities/Province.ts b/src/entities/Province.ts index e251957..7ba8848 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -1,6 +1,7 @@ import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; +import { DevelopmentAddress } from "./DevelopmentAddress"; @Entity("province") export class Province extends EntityBase { @@ -12,9 +13,11 @@ export class Province extends EntityBase { }) name: string; - @ManyToMany(() => Development, (development) => development.provinces) - @JoinTable() - developmentProvinces: Development[]; + @OneToMany( + () => DevelopmentAddress, + (developmentAddress: DevelopmentAddress) => developmentAddress.province, + ) + developmentAddresss: DevelopmentAddress[]; @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; diff --git a/src/migration/1712778363784-update_table_dev_refresh1.ts b/src/migration/1712778363784-update_table_dev_refresh1.ts new file mode 100644 index 0000000..859005e --- /dev/null +++ b/src/migration/1712778363784-update_table_dev_refresh1.ts @@ -0,0 +1,92 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevRefresh11712778363784 implements MigrationInterface { + name = 'UpdateTableDevRefresh11712778363784' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`developmentAddress\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`address\` varchar(255) NULL COMMENT 'ที่อยู่', \`provinceId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentProjectType\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'ประเภทโครงการ', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentProjectTechnique\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`name\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`developmentEvaluation\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด', \`target\` int NULL COMMENT 'เป้าหมาย', \`metricType\` varchar(255) NULL COMMENT 'ประเภทตัวชี้วัด', \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ', \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล', \`results\` varchar(255) NULL COMMENT 'ผลการดำเนิน', \`obstacles\` varchar(255) NULL COMMENT 'ปัญหาอุปสรรค', \`suggestions\` varchar(255) NULL COMMENT 'ข้อเสนอเเนะ', \`developmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`metricType\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`indicators\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`target\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`calculation\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`measuRement\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`results\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`obstacles\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`suggestions\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`address\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyStart\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectType\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectCharacteristics\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDay\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigth\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectTechniques\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`status\` varchar(255) NULL COMMENT 'สถานะ' DEFAULT 'ONGOING'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isBackPlanned\` tinyint NOT NULL COMMENT 'ไป-กลับ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isHoldPlanned\` tinyint NOT NULL COMMENT 'พักค้าง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackPlanned\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldPlanned\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldPlanned\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isBackActual\` tinyint NOT NULL COMMENT 'ไป-กลับ' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`isHoldActual\` tinyint NOT NULL COMMENT 'พักค้าง' DEFAULT 0`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackActual\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldActual\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldActual\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`chance\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`effects\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด'`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_e2721b3f440256b56ce83a04fb2\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` ADD CONSTRAINT \`FK_de5eb0e55892aa0cf019afb284d\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentProjectType\` ADD CONSTRAINT \`FK_e9c5a726024b87bb10f23570a98\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechnique\` ADD CONSTRAINT \`FK_902408e69fa1cf0ed815859e089\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD CONSTRAINT \`FK_1714596cf3e3e8311a766800289\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP FOREIGN KEY \`FK_1714596cf3e3e8311a766800289\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectTechnique\` DROP FOREIGN KEY \`FK_902408e69fa1cf0ed815859e089\``); + await queryRunner.query(`ALTER TABLE \`developmentProjectType\` DROP FOREIGN KEY \`FK_e9c5a726024b87bb10f23570a98\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_de5eb0e55892aa0cf019afb284d\``); + await queryRunner.query(`ALTER TABLE \`developmentAddress\` DROP FOREIGN KEY \`FK_e2721b3f440256b56ce83a04fb2\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`effects\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`effects\` varchar(255) NULL COMMENT 'ผลกระทบจากการเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`chance\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`chance\` varchar(255) NULL COMMENT 'โอกาสที่จะเกิด'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`isBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectTechniques\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigth\` int NULL COMMENT 'จำนวน(คืน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDay\` int NULL COMMENT 'จำนวน(วัน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectCharacteristics\` varchar(255) NULL COMMENT 'ลักษณะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectType\` varchar(255) NULL COMMENT 'ประเภทโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyEnd\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyStart\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`address\` varchar(255) NULL COMMENT 'ที่อยู่'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`suggestions\` varchar(255) NULL COMMENT 'ข้อเสนอเเนะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`obstacles\` varchar(255) NULL COMMENT 'ปัญหาอุปสรรค'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`results\` varchar(255) NULL COMMENT 'ผลการดำเนิน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`target\` varchar(255) NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`metricType\` varchar(255) NULL COMMENT 'ประเภทตัวชี้วัด'`); + await queryRunner.query(`DROP TABLE \`developmentEvaluation\``); + await queryRunner.query(`DROP TABLE \`developmentProjectTechnique\``); + await queryRunner.query(`DROP TABLE \`developmentProjectType\``); + await queryRunner.query(`DROP TABLE \`developmentAddress\``); + } + +} diff --git a/src/migration/1712779710145-update_table_dev_refresh2.ts b/src/migration/1712779710145-update_table_dev_refresh2.ts new file mode 100644 index 0000000..74635f4 --- /dev/null +++ b/src/migration/1712779710145-update_table_dev_refresh2.ts @@ -0,0 +1,16 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevRefresh21712779710145 implements MigrationInterface { + name = 'UpdateTableDevRefresh21712779710145' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyStart\` datetime NULL COMMENT 'วันเริ่มต้นการศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`dateStudyEnd\` datetime NULL COMMENT 'วันสิ้นสุดการศึกษาดูงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyEnd\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`dateStudyStart\``); + } + +}