diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index f093b11..b7013c5 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -14,7 +14,7 @@ import { Example, } from "tsoa"; import { AppDataSource } from "../database/data-source"; -import { Not } from "typeorm"; +import { In, Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; @@ -26,6 +26,7 @@ import { PlannedGoal } from "../entities/PlannedGoal"; import { Province } from "../entities/Province"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; +import { PlannedGoalPosition } from "../entities/PlannedGoalPosition"; @Route("api/v1/development/main") @Tags("Development") @@ -36,6 +37,7 @@ export class DevelopmentController extends Controller { private plannedPeopleRepository = AppDataSource.getRepository(PlannedPeople); private actualGoalRepository = AppDataSource.getRepository(ActualGoal); private plannedGoalRepository = AppDataSource.getRepository(PlannedGoal); + private plannedGoalPositionRepository = AppDataSource.getRepository(PlannedGoalPosition); private provinceRepository = AppDataSource.getRepository(Province); private posTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); @@ -68,14 +70,6 @@ export class DevelopmentController extends Controller { ); } - if (requestBody.provinceId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); - } - } if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, @@ -87,6 +81,15 @@ export class DevelopmentController extends Controller { 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; @@ -143,22 +146,6 @@ export class DevelopmentController extends Controller { ); await Promise.all( requestBody.plannedGoals.map(async (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, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } const data = Object.assign(new PlannedGoal(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -166,6 +153,34 @@ export class DevelopmentController extends Controller { 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); @@ -196,14 +211,6 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - if (requestBody.provinceId != null) { - const checkId = await this.provinceRepository.findOne({ - where: { id: requestBody.provinceId }, - }); - if (!checkId) { - throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลจังหวัดสถานที่ดำเนินการ"); - } - } if (requestBody.provinceActualId != null) { const checkId = await this.provinceRepository.findOne({ where: { id: requestBody.provinceActualId }, @@ -230,6 +237,23 @@ 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); @@ -288,22 +312,6 @@ export class DevelopmentController extends Controller { ); await Promise.all( requestBody.plannedGoals.map(async (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, "ไม่พบข้อมูลระดับตำแหน่ง"); - } - } const data = Object.assign(new PlannedGoal(), x); data.createdUserId = request.user.sub; data.createdFullName = request.user.name; @@ -311,6 +319,34 @@ export class DevelopmentController extends Controller { 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); @@ -387,6 +423,15 @@ export class DevelopmentController extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } + 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); + } await this.actualPeopleRepository.remove(development.developmentActualPeoples); await this.plannedPeopleRepository.remove(development.developmentPlannedPeoples); await this.actualGoalRepository.remove(development.developmentActualGoals); @@ -437,12 +482,15 @@ export class DevelopmentController extends Controller { async GetDevelopemtById(@Path() id: string) { const getDevelopment = await this.developmentRepository.findOne({ where: { id: id }, - relations: { - developmentActualPeoples: true, - developmentPlannedPeoples: true, - developmentActualGoals: true, - developmentPlannedGoals: true, - }, + relations: [ + "developmentActualPeoples", + "developmentPlannedPeoples", + "developmentActualGoals", + "developmentPlannedGoals", + "developmentPlannedGoals.plannedGoalPositions", + "provinces", + // "provinces.developmentProvinces", + ], }); if (!getDevelopment) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); @@ -452,6 +500,7 @@ export class DevelopmentController extends Controller { _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; diff --git a/src/controllers/DevelopmentScholarshipController.ts b/src/controllers/DevelopmentScholarshipController.ts index 295dc9c..3525811 100644 --- a/src/controllers/DevelopmentScholarshipController.ts +++ b/src/controllers/DevelopmentScholarshipController.ts @@ -311,7 +311,37 @@ export class DevelopmentScholarshipController extends Controller { ? getDevelopment.studyAbroadEndDate : null, totalPeriod: getDevelopment.totalPeriod ? getDevelopment.totalPeriod : null, + status: getDevelopment.status ? getDevelopment.status : null, }; return new HttpSuccess(formattedData); } + + /** + * API เปลี่ยนสถานะ + * + * @summary DEV_0 - เปลี่ยนสถานะ # + * + * @param {string} id Id โครงการ + * @param {string} status status สถานะ + */ + @Get("status/{id}/{status}") + async ChangeStatusDevelopemtScholarshipById(@Path() id: string, @Path() status: string) { + const getDevelopment = await this.developmentScholarshipRepository.findOne({ + where: { id: id }, + }); + if (!getDevelopment) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทุนการศึกษา/ฝึกอบรมนี้"); + } + const _status = status.trim().toUpperCase(); + getDevelopment.status = _status; + if (_status == "GRADUATE") { + //xxxxxxxxxxxxxxxxxxxบันทึกลงทะเบียน + } else if (_status == "NOTGRADUATE") { + } else { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบสถานะนี้ในระบบ"); + } + await this.developmentScholarshipRepository.remove(getDevelopment); + + return new HttpSuccess(); + } } diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 08e2a46..ca6d988 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -1,4 +1,4 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany, Double } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany, Double, ManyToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Province } from "./Province"; import { ActualPeople, CreateActualPeople } from "./ActualPeople"; @@ -159,17 +159,6 @@ export class Development extends EntityBase { }) address: string; - @Column({ - nullable: true, - comment: "จังหวัด", - default: null, - }) - provinceId: string; - - @ManyToOne(() => Province, (province: Province) => province.developments) - @JoinColumn({ name: "provinceId" }) - province: Province; - @Column({ nullable: true, comment: "ประเภทงบประมาณ", @@ -281,6 +270,73 @@ 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: "จังหวัด(ข้อมูลวิชาการ)", @@ -292,6 +348,9 @@ export class Development extends EntityBase { @JoinColumn({ name: "provinceActualId" }) provinceActual: Province; + @ManyToMany(() => Province, (provinces) => provinces.developmentProvinces) + provinces: Province[]; + @OneToMany( () => ActualPeople, (actualPeople: ActualPeople) => actualPeople.developmentActualPeople, @@ -362,7 +421,7 @@ export class CreateDevelopment { @Column() address: string | null; @Column() - provinceId: string | null; + provinceIds: string[]; @Column() budget: string | null; @Column() @@ -396,6 +455,20 @@ export class CreateDevelopment { @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[]; @@ -451,7 +524,7 @@ export class UpdateDevelopment { @Column() address: string | null; @Column() - provinceId: string | null; + provinceIds: string[]; @Column() budget: string | null; @Column() @@ -485,6 +558,20 @@ export class UpdateDevelopment { @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[]; diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 847ce4d..1ebb953 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -5,6 +5,17 @@ import { PosType } from "./PosType"; @Entity("developmentScholarship") export class DevelopmentScholarship extends EntityBase { + @Column({ + // PENDING = ค่าเริ่มต้น + // GRADUATE = สำเร็จการศึกษา + // NOTGRADUATE = ไม่จบการศึกษา + nullable: true, + comment: "สถานะ", + length: 40, + default: "PENDING", + }) + status: string; + @Column({ nullable: true, comment: "ยศ", diff --git a/src/entities/PlannedGoal.ts b/src/entities/PlannedGoal.ts index 5758ed8..ec70ffe 100644 --- a/src/entities/PlannedGoal.ts +++ b/src/entities/PlannedGoal.ts @@ -1,8 +1,7 @@ -import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; -import { PosType } from "./PosType"; -import { PosLevel } from "./PosLevel"; +import { CreatePlannedGoalPosition, PlannedGoalPosition } from "./PlannedGoalPosition"; @Entity("plannedGoal") export class PlannedGoal extends EntityBase { @@ -20,41 +19,41 @@ export class PlannedGoal extends EntityBase { }) groupTargetSub: string; - @Column({ - nullable: true, - comment: "ตำแหน่ง", - default: null, - }) - position: string; + // @Column({ + // nullable: true, + // comment: "ตำแหน่ง", + // default: null, + // }) + // position: string; - @Column({ - nullable: true, - comment: "ประเภทตำแหน่ง", - default: null, - }) - posTypePlannedId: string; + // @Column({ + // nullable: true, + // comment: "ประเภทตำแหน่ง", + // default: null, + // }) + // posTypePlannedId: string; - @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoals) - @JoinColumn({ name: "posTypePlannedId" }) - posTypePlanned: PosType; + // @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoals) + // @JoinColumn({ name: "posTypePlannedId" }) + // posTypePlanned: PosType; - @Column({ - nullable: true, - comment: "ระดับตำแหน่ง", - default: null, - }) - posLevelPlannedId: string; + // @Column({ + // nullable: true, + // comment: "ระดับตำแหน่ง", + // default: null, + // }) + // posLevelPlannedId: string; - @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoals) - @JoinColumn({ name: "posLevelPlannedId" }) - posLevelPlanned: PosLevel; + // @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoals) + // @JoinColumn({ name: "posLevelPlannedId" }) + // posLevelPlanned: PosLevel; - @Column({ - nullable: true, - comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", - default: null, - }) - type: string; + // @Column({ + // nullable: true, + // comment: "ประเภท(กลุ่มอาชีพ คุณสมบัติ)", + // default: null, + // }) + // type: string; @Column({ nullable: true, @@ -73,6 +72,12 @@ export class PlannedGoal extends EntityBase { @ManyToOne(() => Development, (development: Development) => development.developmentPlannedGoals) @JoinColumn({ name: "developmentPlannedGoalId" }) developmentPlannedGoal: Development; + + @OneToMany( + () => PlannedGoalPosition, + (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.plannedGoal, + ) + plannedGoalPositions: PlannedGoalPosition[]; } export class CreatePlannedGoal { @@ -81,11 +86,11 @@ export class CreatePlannedGoal { @Column() groupTargetSub: string | null; @Column() - position: string | null; - @Column() - posTypePlannedId: string | null; - @Column() - posLevelPlannedId: string | null; + positions: CreatePlannedGoalPosition[]; + // @Column() + // posTypePlannedId: string | null; + // @Column() + // posLevelPlannedId: string | null; @Column() type: string | null; @Column() diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts new file mode 100644 index 0000000..01a088c --- /dev/null +++ b/src/entities/PlannedGoalPosition.ts @@ -0,0 +1,59 @@ +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { PosType } from "./PosType"; +import { PosLevel } from "./PosLevel"; +import { PlannedGoal } from "./PlannedGoal"; + +@Entity("plannedGoalPosition") +export class PlannedGoalPosition extends EntityBase { + @Column({ + nullable: true, + comment: "ตำแหน่ง", + default: null, + }) + position: string; + + @Column({ + nullable: true, + comment: "ประเภทตำแหน่ง", + default: null, + }) + posTypePlannedId: string; + + @ManyToOne(() => PosType, (posType: PosType) => posType.plannedGoalPositions) + @JoinColumn({ name: "posTypePlannedId" }) + posTypePlanned: PosType; + + @Column({ + nullable: true, + comment: "ระดับตำแหน่ง", + default: null, + }) + posLevelPlannedId: string; + + @ManyToOne(() => PosLevel, (posLevel: PosLevel) => posLevel.plannedGoalPositions) + @JoinColumn({ name: "posLevelPlannedId" }) + posLevelPlanned: PosLevel; + + @Column({ + nullable: true, + comment: "id โครงการ", + default: null, + }) + plannedGoalId: string; + + @ManyToOne(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.plannedGoalPositions) + @JoinColumn({ name: "plannedGoalId" }) + plannedGoal: PlannedGoal; +} + +export class CreatePlannedGoalPosition { + @Column() + position: string | null; + @Column() + posTypePlannedId: string | null; + @Column() + posLevelPlannedId: string | null; +} + +export type UpdatePlannedGoalPosition = Partial; diff --git a/src/entities/PosLevel.ts b/src/entities/PosLevel.ts index e3c526d..705b6b8 100644 --- a/src/entities/PosLevel.ts +++ b/src/entities/PosLevel.ts @@ -2,9 +2,9 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { PosType } from "./PosType"; import { ActualGoal } from "./ActualGoal"; -import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentScholarship } from "./DevelopmentScholarship"; +import { PlannedGoalPosition } from "./PlannedGoalPosition"; enum PosLevelAuthority { HEAD = "HEAD", @@ -51,8 +51,11 @@ export class PosLevel extends EntityBase { @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posLevelActual) actualGoals: ActualGoal[]; - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posLevelPlanned) - plannedGoals: PlannedGoal[]; + @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 6a8574c..d18e7fb 100644 --- a/src/entities/PosType.ts +++ b/src/entities/PosType.ts @@ -5,6 +5,7 @@ import { ActualGoal } from "./ActualGoal"; import { PlannedGoal } from "./PlannedGoal"; import { DevelopmentHistory } from "./DevelopmentHistory"; import { DevelopmentScholarship } from "./DevelopmentScholarship"; +import { PlannedGoalPosition } from "./PlannedGoalPosition"; @Entity("posType") export class PosType extends EntityBase { @@ -30,8 +31,11 @@ export class PosType extends EntityBase { @OneToMany(() => ActualGoal, (actualGoal: ActualGoal) => actualGoal.posTypeActual) actualGoals: ActualGoal[]; - @OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.posTypePlanned) - plannedGoals: PlannedGoal[]; + @OneToMany( + () => PlannedGoalPosition, + (plannedGoalPosition: PlannedGoalPosition) => plannedGoalPosition.posTypePlanned, + ) + plannedGoalPositions: PlannedGoalPosition[]; @OneToMany(() => DevelopmentHistory, (developmentHistory) => developmentHistory.posType) developmentHistorys: DevelopmentHistory[]; diff --git a/src/entities/Province.ts b/src/entities/Province.ts index 0ab83ff..e251957 100644 --- a/src/entities/Province.ts +++ b/src/entities/Province.ts @@ -1,4 +1,4 @@ -import { Entity, Column, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany, ManyToMany, JoinTable } from "typeorm"; import { EntityBase } from "./base/Base"; import { Development } from "./Development"; @@ -12,8 +12,9 @@ export class Province extends EntityBase { }) name: string; - @OneToMany(() => Development, (development: Development) => development.province) - developments: Development[]; + @ManyToMany(() => Development, (development) => development.provinces) + @JoinTable() + developmentProvinces: Development[]; @OneToMany(() => Development, (development: Development) => development.provinceActual) developmentActuals: Development[]; diff --git a/src/migration/1712670681087-update_table_developement_add_projectType.ts b/src/migration/1712670681087-update_table_developement_add_projectType.ts new file mode 100644 index 0000000..f9ee7ca --- /dev/null +++ b/src/migration/1712670681087-update_table_developement_add_projectType.ts @@ -0,0 +1,60 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTableDevelopementAddProjectType1712670681087 implements MigrationInterface { + name = 'UpdateTableDevelopementAddProjectType1712670681087' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_0e6aba627301f35aa3570b44bf5\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP FOREIGN KEY \`FK_308d02f616b878261a3890b4d40\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP FOREIGN KEY \`FK_c7552b4624cc7347144be758e6e\``); + await queryRunner.query(`CREATE TABLE \`plannedGoalPosition\` (\`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', \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง', \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง', \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง', \`plannedGoalId\` varchar(255) NULL COMMENT 'id โครงการ', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`province_development_provinces_development\` (\`provinceId\` varchar(36) NOT NULL, \`developmentId\` varchar(36) NOT NULL, INDEX \`IDX_32e044775dec4423645a09d90e\` (\`provinceId\`), INDEX \`IDX_66246e941aca36d81e7c8e0c88\` (\`developmentId\`), PRIMARY KEY (\`provinceId\`, \`developmentId\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`posTypePlannedId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`posLevelPlannedId\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`type\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`provinceId\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectType\` varchar(255) NULL COMMENT 'ประเภทโครงการ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectCharacteristics\` varchar(255) NULL COMMENT 'ลักษณะ'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDay\` int NULL COMMENT 'จำนวน(วัน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigth\` int NULL COMMENT 'จำนวน(คืน)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectTechniques\` varchar(255) NULL COMMENT 'เทคนิควิธีการที่ใช้ในการพัฒนา'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModal\` int NULL COMMENT 'จำนวน(รุ่น)'`); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`budgetSub\` varchar(255) NULL COMMENT 'ประเภทย่อย'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`status\` varchar(40) NULL COMMENT 'สถานะ' DEFAULT 'PENDING'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_4eef5d8c3ab92f7af4a762150a4\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_8e7e0bf6eebd99f58e9b47c6b05\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD CONSTRAINT \`FK_f2fad93b1a4a3454f0de1c12c62\` FOREIGN KEY (\`plannedGoalId\`) REFERENCES \`plannedGoal\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` ADD CONSTRAINT \`FK_32e044775dec4423645a09d90e6\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` ADD CONSTRAINT \`FK_66246e941aca36d81e7c8e0c888\` 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 \`province_development_provinces_development\` DROP FOREIGN KEY \`FK_66246e941aca36d81e7c8e0c888\``); + await queryRunner.query(`ALTER TABLE \`province_development_provinces_development\` DROP FOREIGN KEY \`FK_32e044775dec4423645a09d90e6\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_f2fad93b1a4a3454f0de1c12c62\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_8e7e0bf6eebd99f58e9b47c6b05\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP FOREIGN KEY \`FK_4eef5d8c3ab92f7af4a762150a4\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`status\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`budgetSub\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModal\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectTechniques\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigth\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDay\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectCharacteristics\``); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectType\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`provinceId\` varchar(255) NULL COMMENT 'จังหวัด'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`type\` varchar(255) NULL COMMENT 'ประเภท(กลุ่มอาชีพ คุณสมบัติ)'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`posLevelPlannedId\` varchar(255) NULL COMMENT 'ระดับตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`posTypePlannedId\` varchar(255) NULL COMMENT 'ประเภทตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`DROP INDEX \`IDX_66246e941aca36d81e7c8e0c88\` ON \`province_development_provinces_development\``); + await queryRunner.query(`DROP INDEX \`IDX_32e044775dec4423645a09d90e\` ON \`province_development_provinces_development\``); + await queryRunner.query(`DROP TABLE \`province_development_provinces_development\``); + await queryRunner.query(`DROP TABLE \`plannedGoalPosition\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD CONSTRAINT \`FK_c7552b4624cc7347144be758e6e\` FOREIGN KEY (\`provinceId\`) REFERENCES \`province\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_308d02f616b878261a3890b4d40\` FOREIGN KEY (\`posTypePlannedId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD CONSTRAINT \`FK_0e6aba627301f35aa3570b44bf5\` FOREIGN KEY (\`posLevelPlannedId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + +}