From 2cb7a9ab0764bebe79b631f0f98111d7c49764f7 Mon Sep 17 00:00:00 2001 From: harid Date: Mon, 8 Dec 2025 10:18:41 +0700 Subject: [PATCH 1/2] migrate --- src/controllers/DevelopmentController.ts | 1 + src/entities/ActualGoal.ts | 3 + src/entities/ActualPeople.ts | 3 + src/entities/Development.ts | 36 ++++- src/entities/DevelopmentEvaluation.ts | 6 + src/entities/DevelopmentOther.ts | 2 + src/entities/DevelopmentRisk.ts | 2 + src/entities/DevelopmentScholarship.ts | 2 +- src/entities/PlannedGoal.ts | 3 + src/entities/PlannedGoalPosition.ts | 1 + src/entities/PlannedPeople.ts | 3 + .../1764651579684-update_datatype_fields.ts | 132 ++++++++++++++++++ ...764738754427-update_datatype_fields_two.ts | 42 ++++++ 13 files changed, 232 insertions(+), 4 deletions(-) create mode 100644 src/migration/1764651579684-update_datatype_fields.ts create mode 100644 src/migration/1764738754427-update_datatype_fields_two.ts diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 334c9f2..6871cd8 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -2575,6 +2575,7 @@ export class DevelopmentController extends Controller { isDone: "ASC", isDoneIDP: "ASC", citizenId: "ASC", + type: "DESC", }, }); const _getDevelopment = getDevelopment.map((item) => ({ diff --git a/src/entities/ActualGoal.ts b/src/entities/ActualGoal.ts index 2fe2589..b8fe488 100644 --- a/src/entities/ActualGoal.ts +++ b/src/entities/ActualGoal.ts @@ -71,6 +71,9 @@ export class ActualGoal extends EntityBase { type: string; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คน)", default: null, diff --git a/src/entities/ActualPeople.ts b/src/entities/ActualPeople.ts index 8050810..1215c17 100644 --- a/src/entities/ActualPeople.ts +++ b/src/entities/ActualPeople.ts @@ -12,6 +12,9 @@ export class ActualPeople extends EntityBase { groupTarget: string; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คน)", default: null, diff --git a/src/entities/Development.ts b/src/entities/Development.ts index 94f773b..7775b67 100644 --- a/src/entities/Development.ts +++ b/src/entities/Development.ts @@ -183,8 +183,8 @@ export class Development extends EntityBase { year: number; @Column({ + type: "longtext", comment: "ชื่อโครงการ/กิจกรรม/หลักสูตร", - length: 255, }) projectName: string; @@ -192,7 +192,7 @@ export class Development extends EntityBase { nullable: true, comment: "หลักการและเหตุผล", default: null, - type: "text", + type: "longtext", }) reason: string; @@ -200,7 +200,7 @@ export class Development extends EntityBase { nullable: true, comment: "วัตถุประสงค์", default: null, - type: "text", + type: "longtext", }) objective: string; @@ -254,6 +254,9 @@ export class Development extends EntityBase { isHoldPlanned: boolean; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(วัน)(ไป-กลับ)", default: null, @@ -261,6 +264,9 @@ export class Development extends EntityBase { projectDayBackPlanned: number; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(วัน)(พักค้าง)", default: null, @@ -268,6 +274,9 @@ export class Development extends EntityBase { projectDayHoldPlanned: number; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คืน)(พักค้าง)", default: null, @@ -287,6 +296,9 @@ export class Development extends EntityBase { isHoldActual: boolean; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(วัน)(ไป-กลับ)", default: null, @@ -294,6 +306,9 @@ export class Development extends EntityBase { projectDayBackActual: number; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(วัน)(พักค้าง)", default: null, @@ -301,6 +316,9 @@ export class Development extends EntityBase { projectDayHoldActual: number; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คืน)(พักค้าง)", default: null, @@ -308,6 +326,7 @@ export class Development extends EntityBase { projectNigthHoldActual: number; @Column({ + type: "longtext", nullable: true, comment: "รายละเอียดอื่นๆ 70 แผน", default: null, @@ -315,6 +334,7 @@ export class Development extends EntityBase { reasonPlanned70: string; @Column({ + type: "longtext", nullable: true, comment: "รายละเอียดอื่นๆ 20 แผน", default: null, @@ -322,6 +342,7 @@ export class Development extends EntityBase { reasonPlanned20: string; @Column({ + type: "longtext", nullable: true, comment: "รายละเอียดอื่นๆ 10 แผน", default: null, @@ -400,6 +421,9 @@ export class Development extends EntityBase { developmentProjectTechniqueActuals: DevelopmentProjectTechniqueActual[]; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(รุ่น)ตามแผน", default: null, @@ -407,6 +431,9 @@ export class Development extends EntityBase { projectModalPlanned: number; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(รุ่น)ตามจริง", default: null, @@ -573,6 +600,7 @@ export class Development extends EntityBase { riskManagement: string; @Column({ + type: "longtext", nullable: true, comment: "ประโยชน์ที่คาดว่าจะได้รับ", default: null, @@ -580,6 +608,7 @@ export class Development extends EntityBase { expect: string; @Column({ + type: "longtext", nullable: true, comment: "หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน", default: null, @@ -587,6 +616,7 @@ export class Development extends EntityBase { topicAcademic: string; @Column({ + type: "longtext", nullable: true, comment: "สถานที่ฝึกอบรม ศึกษาดูงาน", default: null, diff --git a/src/entities/DevelopmentEvaluation.ts b/src/entities/DevelopmentEvaluation.ts index 6dff8d6..0574d41 100644 --- a/src/entities/DevelopmentEvaluation.ts +++ b/src/entities/DevelopmentEvaluation.ts @@ -5,6 +5,7 @@ import { Development } from "./Development"; @Entity("developmentEvaluation") export class DevelopmentEvaluation extends EntityBase { @Column({ + type: "longtext", nullable: true, comment: "ตัวชี้วัด", default: null, @@ -12,6 +13,9 @@ export class DevelopmentEvaluation extends EntityBase { indicators: string; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "เป้าหมาย", default: null, @@ -26,6 +30,7 @@ export class DevelopmentEvaluation extends EntityBase { metricType: string; @Column({ + type: "longtext", nullable: true, comment: "วิธีการคำนวณ/เครื่องมือ", default: null, @@ -33,6 +38,7 @@ export class DevelopmentEvaluation extends EntityBase { calculation: string; @Column({ + type: "longtext", nullable: true, comment: "ระยะเวลาวัดผล", default: null, diff --git a/src/entities/DevelopmentOther.ts b/src/entities/DevelopmentOther.ts index 98e145a..f127953 100644 --- a/src/entities/DevelopmentOther.ts +++ b/src/entities/DevelopmentOther.ts @@ -5,6 +5,7 @@ import { Development } from "./Development"; @Entity("developmentOther") export class DevelopmentOther extends EntityBase { @Column({ + type: "longtext", nullable: true, comment: "หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน", default: null, @@ -12,6 +13,7 @@ export class DevelopmentOther extends EntityBase { topicAcademic: string; @Column({ + type: "longtext", nullable: true, comment: "สถานที่ฝึกอบรม ศึกษาดูงาน", default: null, diff --git a/src/entities/DevelopmentRisk.ts b/src/entities/DevelopmentRisk.ts index b146cba..ee2d363 100644 --- a/src/entities/DevelopmentRisk.ts +++ b/src/entities/DevelopmentRisk.ts @@ -5,6 +5,7 @@ import { Development } from "./Development"; @Entity("developmentRisk") export class DevelopmentRisk extends EntityBase { @Column({ + type: "longtext", nullable: true, comment: "ประเด็นความเสี่ยง", default: null, @@ -33,6 +34,7 @@ export class DevelopmentRisk extends EntityBase { riskLevel: string; @Column({ + type: "longtext", nullable: true, comment: "เเนวทางการบริหารความเสี่ยง", default: null, diff --git a/src/entities/DevelopmentScholarship.ts b/src/entities/DevelopmentScholarship.ts index 24745ae..f6e34eb 100644 --- a/src/entities/DevelopmentScholarship.ts +++ b/src/entities/DevelopmentScholarship.ts @@ -318,9 +318,9 @@ export class DevelopmentScholarship extends EntityBase { useOfficialTime: string; @Column({ + type: "longtext", nullable: true, comment: "เปลี่ยนแปลงรายละเอียด", - type: "text", default: null, }) changeDetail: string; diff --git a/src/entities/PlannedGoal.ts b/src/entities/PlannedGoal.ts index 4e070fb..5d6d915 100644 --- a/src/entities/PlannedGoal.ts +++ b/src/entities/PlannedGoal.ts @@ -56,6 +56,9 @@ export class PlannedGoal extends EntityBase { type: string; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คน)", default: null, diff --git a/src/entities/PlannedGoalPosition.ts b/src/entities/PlannedGoalPosition.ts index a5df81d..a37f926 100644 --- a/src/entities/PlannedGoalPosition.ts +++ b/src/entities/PlannedGoalPosition.ts @@ -7,6 +7,7 @@ import { PlannedGoal } from "./PlannedGoal"; @Entity("plannedGoalPosition") export class PlannedGoalPosition extends EntityBase { @Column({ + type: "longtext", nullable: true, comment: "ตำแหน่ง", default: null, diff --git a/src/entities/PlannedPeople.ts b/src/entities/PlannedPeople.ts index 8743fd1..38b3c11 100644 --- a/src/entities/PlannedPeople.ts +++ b/src/entities/PlannedPeople.ts @@ -12,6 +12,9 @@ export class PlannedPeople extends EntityBase { groupTarget: string; @Column({ + type: "decimal", + precision: 65, + scale: 0, nullable: true, comment: "จำนวน(คน)", default: null, diff --git a/src/migration/1764651579684-update_datatype_fields.ts b/src/migration/1764651579684-update_datatype_fields.ts new file mode 100644 index 0000000..37587b9 --- /dev/null +++ b/src/migration/1764651579684-update_datatype_fields.ts @@ -0,0 +1,132 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDatatypeFields1764651579684 implements MigrationInterface { + name = 'UpdateDatatypeFields1764651579684' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`actualPeople\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`actualPeople\` ADD \`amount\` decimal NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` ADD \`amount\` decimal NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`amount\` decimal NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`amount\` decimal NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`changeDetail\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`changeDetail\` longtext NULL COMMENT 'เปลี่ยนแปลงรายละเอียด'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`indicators\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`indicators\` longtext NULL COMMENT 'ตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`target\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`target\` decimal NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`calculation\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`calculation\` longtext NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`measuRement\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`measuRement\` longtext NULL COMMENT 'ระยะเวลาวัดผล'`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP COLUMN \`issues\``); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD \`issues\` longtext NULL COMMENT 'ประเด็นความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP COLUMN \`riskManagement\``); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD \`riskManagement\` longtext NULL COMMENT 'เเนวทางการบริหารความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`topicAcademic\``); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`topicAcademic\` longtext NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`addressAcademic\``); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`addressAcademic\` longtext NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectName\` longtext NOT NULL COMMENT 'ชื่อโครงการ/กิจกรรม/หลักสูตร'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reason\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reason\` longtext NULL COMMENT 'หลักการและเหตุผล'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`objective\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`objective\` longtext NULL COMMENT 'วัตถุประสงค์'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackPlanned\` decimal NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldPlanned\` decimal NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldPlanned\` decimal NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackActual\` decimal NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldActual\` decimal NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldActual\` decimal NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned70\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned70\` longtext NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned20\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned20\` longtext NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned10\` longtext NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalPlanned\` decimal NULL COMMENT 'จำนวน(รุ่น)ตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalActual\` decimal NULL COMMENT 'จำนวน(รุ่น)ตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`expect\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`expect\` longtext NULL COMMENT 'ประโยชน์ที่คาดว่าจะได้รับ'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`topicAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`topicAcademic\` longtext NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`addressAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`addressAcademic\` longtext NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`addressAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`topicAcademic\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`expect\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`expect\` varchar(255) NULL COMMENT 'ประโยชน์ที่คาดว่าจะได้รับ'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalActual\` int NULL COMMENT 'จำนวน(รุ่น)ตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectModalPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectModalPlanned\` int NULL COMMENT 'จำนวน(รุ่น)ตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned10\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned20\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned20\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reasonPlanned70\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reasonPlanned70\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldActual\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldActual\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackActual\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackActual\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectNigthHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectNigthHoldPlanned\` int NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayHoldPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayHoldPlanned\` int NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectDayBackPlanned\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectDayBackPlanned\` int NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`objective\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`objective\` text NULL COMMENT 'วัตถุประสงค์'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`reason\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`reason\` text NULL COMMENT 'หลักการและเหตุผล'`); + await queryRunner.query(`ALTER TABLE \`development\` DROP COLUMN \`projectName\``); + await queryRunner.query(`ALTER TABLE \`development\` ADD \`projectName\` varchar(255) NOT NULL COMMENT 'ชื่อโครงการ/กิจกรรม/หลักสูตร'`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`addressAcademic\``); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`addressAcademic\` varchar(255) NULL COMMENT 'สถานที่ฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentOther\` DROP COLUMN \`topicAcademic\``); + await queryRunner.query(`ALTER TABLE \`developmentOther\` ADD \`topicAcademic\` varchar(255) NULL COMMENT 'หัวข้อ/ประเด็นการฝึกอบรม ศึกษาดูงาน'`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP COLUMN \`riskManagement\``); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP COLUMN \`issues\``); + await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`measuRement\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`measuRement\` varchar(255) NULL COMMENT 'ระยะเวลาวัดผล'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`calculation\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`calculation\` varchar(255) NULL COMMENT 'วิธีการคำนวณ/เครื่องมือ'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`target\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`target\` int NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` DROP COLUMN \`indicators\``); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` ADD \`indicators\` varchar(255) NULL COMMENT 'ตัวชี้วัด'`); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` DROP COLUMN \`changeDetail\``); + await queryRunner.query(`ALTER TABLE \`developmentScholarship\` ADD \`changeDetail\` text NULL COMMENT 'เปลี่ยนแปลงรายละเอียด'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` ADD \`amount\` int NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`actualGoal\` ADD \`amount\` int NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` ADD \`amount\` int NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`actualPeople\` DROP COLUMN \`amount\``); + await queryRunner.query(`ALTER TABLE \`actualPeople\` ADD \`amount\` int NULL COMMENT 'จำนวน(คน)'`); + } + +} diff --git a/src/migration/1764738754427-update_datatype_fields_two.ts b/src/migration/1764738754427-update_datatype_fields_two.ts new file mode 100644 index 0000000..e015d1d --- /dev/null +++ b/src/migration/1764738754427-update_datatype_fields_two.ts @@ -0,0 +1,42 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateDatatypeFieldsTwo1764738754427 implements MigrationInterface { + name = 'UpdateDatatypeFieldsTwo1764738754427' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`actualPeople\` CHANGE \`amount\` \`amount\` decimal(65,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` CHANGE \`amount\` \`amount\` decimal(65,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` CHANGE \`amount\` \`amount\` decimal(65,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`position\` longtext NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` CHANGE \`amount\` \`amount\` decimal(65,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` CHANGE \`target\` \`target\` decimal(65,0) NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayBackPlanned\` \`projectDayBackPlanned\` decimal(65,0) NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayHoldPlanned\` \`projectDayHoldPlanned\` decimal(65,0) NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectNigthHoldPlanned\` \`projectNigthHoldPlanned\` decimal(65,0) NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayBackActual\` \`projectDayBackActual\` decimal(65,0) NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayHoldActual\` \`projectDayHoldActual\` decimal(65,0) NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectNigthHoldActual\` \`projectNigthHoldActual\` decimal(65,0) NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectModalPlanned\` \`projectModalPlanned\` decimal(65,0) NULL COMMENT 'จำนวน(รุ่น)ตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectModalActual\` \`projectModalActual\` decimal(65,0) NULL COMMENT 'จำนวน(รุ่น)ตามจริง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectModalActual\` \`projectModalActual\` decimal(10,0) NULL COMMENT 'จำนวน(รุ่น)ตามจริง'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectModalPlanned\` \`projectModalPlanned\` decimal(10,0) NULL COMMENT 'จำนวน(รุ่น)ตามแผน'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectNigthHoldActual\` \`projectNigthHoldActual\` decimal(10,0) NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayHoldActual\` \`projectDayHoldActual\` decimal(10,0) NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayBackActual\` \`projectDayBackActual\` decimal(10,0) NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectNigthHoldPlanned\` \`projectNigthHoldPlanned\` decimal(10,0) NULL COMMENT 'จำนวน(คืน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayHoldPlanned\` \`projectDayHoldPlanned\` decimal(10,0) NULL COMMENT 'จำนวน(วัน)(พักค้าง)'`); + await queryRunner.query(`ALTER TABLE \`development\` CHANGE \`projectDayBackPlanned\` \`projectDayBackPlanned\` decimal(10,0) NULL COMMENT 'จำนวน(วัน)(ไป-กลับ)'`); + await queryRunner.query(`ALTER TABLE \`developmentEvaluation\` CHANGE \`target\` \`target\` decimal(10,0) NULL COMMENT 'เป้าหมาย'`); + await queryRunner.query(`ALTER TABLE \`plannedGoal\` CHANGE \`amount\` \`amount\` decimal(10,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` DROP COLUMN \`position\``); + await queryRunner.query(`ALTER TABLE \`plannedGoalPosition\` ADD \`position\` varchar(255) NULL COMMENT 'ตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`actualGoal\` CHANGE \`amount\` \`amount\` decimal(10,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`plannedPeople\` CHANGE \`amount\` \`amount\` decimal(10,0) NULL COMMENT 'จำนวน(คน)'`); + await queryRunner.query(`ALTER TABLE \`actualPeople\` CHANGE \`amount\` \`amount\` decimal(10,0) NULL COMMENT 'จำนวน(คน)'`); + } + +} From c6fabbcf166a9af459c6cd2e2885b3d01246c2fd Mon Sep 17 00:00:00 2001 From: kittapath <> Date: Fri, 12 Dec 2025 01:37:44 +0700 Subject: [PATCH 2/2] add permission brother --- src/controllers/DevelopmentController.ts | 35 +++++------ src/interfaces/permission.ts | 78 +++++++++++++++--------- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/src/controllers/DevelopmentController.ts b/src/controllers/DevelopmentController.ts index 6871cd8..5522f9c 100644 --- a/src/controllers/DevelopmentController.ts +++ b/src/controllers/DevelopmentController.ts @@ -1551,7 +1551,7 @@ export class DevelopmentController extends Controller { if (!development) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้"); } - Object.assign(development, { ...requestBody}); + Object.assign(development, { ...requestBody }); development.lastUpdateUserId = request.user.sub; development.lastUpdateFullName = request.user.name; development.lastUpdatedAt = new Date(); @@ -2085,7 +2085,7 @@ export class DevelopmentController extends Controller { _data.child1 != undefined && _data.child1 != null ? _data.child1[0] != null ? `development.child1DnaId IN (:...child1)` - : `development.child1DnaId is null` + : `development.child1DnaId is ${_data.privilege == "PARENT" ? "not null" : "null"}` : "1=1", { child1: _data.child1, @@ -2130,19 +2130,15 @@ export class DevelopmentController extends Controller { "development.child2", "development.child3", "development.child4", - ]) + ]); - if (sortBy) { - query = query.orderBy( - `development.${sortBy}`, - descending ? "DESC" : "ASC" - ); - }else{ - query = query.orderBy("development.year", "DESC") - .addOrderBy("development.createdAt", "DESC") - } + if (sortBy) { + query = query.orderBy(`development.${sortBy}`, descending ? "DESC" : "ASC"); + } else { + query = query.orderBy("development.year", "DESC").addOrderBy("development.createdAt", "DESC"); + } - const [development, total] = await query + const [development, total] = await query .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); @@ -2632,12 +2628,13 @@ export class DevelopmentController extends Controller { }); const developmentAddresss = await this.developmentAddresssRepository.find({ - where: { developmentId: id} - }) - + where: { developmentId: id }, + }); + const places = developmentAddresss - .map(addr => - `- ${addr.address}, ${addr.addressType === "IN_COUNTRY" ? addr.provinceName : addr.country} (${addr.addressType === "IN_COUNTRY" ? "ภายในประเทศ" : "ภายนอกประเทศ"})` + .map( + (addr) => + `- ${addr.address}, ${addr.addressType === "IN_COUNTRY" ? addr.provinceName : addr.country} (${addr.addressType === "IN_COUNTRY" ? "ภายในประเทศ" : "ภายนอกประเทศ"})`, ) .filter(Boolean) .join("\n"); @@ -2768,7 +2765,7 @@ export class DevelopmentController extends Controller { techniqueActuals.length > 0 && dev20Lists.some((item) => techniqueActuals.includes(item)); isDevelopment10 = techniqueActuals.length > 0 && dev10Lists.some((item) => techniqueActuals.includes(item)); - + if (x.type == "OFFICER") { await new CallAPI() .PostData(request, "/org/profile/development", { diff --git a/src/interfaces/permission.ts b/src/interfaces/permission.ts index 6ff8977..a47c923 100644 --- a/src/interfaces/permission.ts +++ b/src/interfaces/permission.ts @@ -94,6 +94,15 @@ class CheckAuth { child4: null, privilege: "ROOT", }; + } else if (privilege == "PARENT") { + data = { + root: [x.orgRootId], + child1: [null], + child2: null, + child3: null, + child4: null, + privilege: "PARENT", + }; } else if (privilege == "CHILD") { data = { root: node >= 0 ? [x.orgRootId] : null, @@ -103,6 +112,15 @@ class CheckAuth { child4: node >= 4 ? [x.orgChild4Id] : null, privilege: "CHILD", }; + } else if (privilege == "BROTHER") { + data = { + // root: node >= 0 ? [x.orgRootId] : null, + root: node >= 0 ? [x.orgRootId] : null, + child1: node >= 2 ? [x.orgChild1Id] : null, + child2: node >= 3 ? [x.orgChild2Id] : null, + child3: node >= 4 ? [x.orgChild3Id] : null, + privilege: "BROTHER", + }; } else if (privilege == "NORMAL") { data = { root: [x.orgRootId], @@ -185,38 +203,38 @@ class CheckAuth { } public async checkOrg(token: any, keycloakId: string) { const redisClient = await this.redis.createClient({ - host: process.env.REDIS_HOST, - port: process.env.REDIS_PORT, - }) - const getAsync = promisify(redisClient.get).bind(redisClient) - try { - let reply = await getAsync("org_" + keycloakId) - if (reply != null) { - reply = JSON.parse(reply) - } else { - if (!keycloakId) throw new Error("No KeycloakId provided") - const x = await new CallAPI().GetData( - { - headers: { authorization: token }, - }, - `/org/permission/checkOrg/${keycloakId}`, - false - ) + host: process.env.REDIS_HOST, + port: process.env.REDIS_PORT, + }); + const getAsync = promisify(redisClient.get).bind(redisClient); + try { + let reply = await getAsync("org_" + keycloakId); + if (reply != null) { + reply = JSON.parse(reply); + } else { + if (!keycloakId) throw new Error("No KeycloakId provided"); + const x = await new CallAPI().GetData( + { + headers: { authorization: token }, + }, + `/org/permission/checkOrg/${keycloakId}`, + false, + ); - const data = { - orgRootId: x.orgRootId, - orgChild1Id: x.orgChild1Id, - orgChild2Id: x.orgChild2Id, - orgChild3Id: x.orgChild3Id, - orgChild4Id: x.orgChild4Id, - } + const data = { + orgRootId: x.orgRootId, + orgChild1Id: x.orgChild1Id, + orgChild2Id: x.orgChild2Id, + orgChild3Id: x.orgChild3Id, + orgChild4Id: x.orgChild4Id, + }; - return data - } - } catch (error) { - console.error("Error calling API:", error) - throw error - } + return data; + } + } catch (error) { + console.error("Error calling API:", error); + throw error; + } } public async PermissionCreate(req: RequestWithUser, system: string) { return await this.Permission(req, system, "CREATE");