migrate
This commit is contained in:
parent
8a36a6c977
commit
6fc0c04a9b
4 changed files with 202 additions and 6 deletions
|
|
@ -27,6 +27,7 @@ import {
|
|||
UpdateDevelopment5,
|
||||
UpdateDevelopment7,
|
||||
UpdateDevelopment8,
|
||||
UpdateDevelopment8_1,
|
||||
} from "../entities/Development";
|
||||
import { ActualPeople, CreateActualPeople } from "../entities/ActualPeople";
|
||||
import { CreatePlannedPeople, PlannedPeople } from "../entities/PlannedPeople";
|
||||
|
|
@ -60,12 +61,14 @@ import { FileInterceptor } from "@nestjs/platform-express";
|
|||
import * as xlsx from "xlsx";
|
||||
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { DevelopmentRisk } from "../entities/DevelopmentRisk";
|
||||
|
||||
@Route("api/v1/development/main")
|
||||
@Tags("Development")
|
||||
@Security("bearerAuth")
|
||||
export class DevelopmentController extends Controller {
|
||||
private developmentRepository = AppDataSource.getRepository(Development);
|
||||
private developmentRiskRepository = AppDataSource.getRepository(DevelopmentRisk);
|
||||
private developmentAddresssRepository = AppDataSource.getRepository(DevelopmentAddress);
|
||||
private developmentEvaluationRepository = AppDataSource.getRepository(DevelopmentEvaluation);
|
||||
private developmentProjectTypeRepository = AppDataSource.getRepository(DevelopmentProjectType);
|
||||
|
|
@ -1410,10 +1413,11 @@ export class DevelopmentController extends Controller {
|
|||
await this.developmentRepository.save(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab6
|
||||
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab7
|
||||
*
|
||||
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab6 #
|
||||
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab7 #
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
|
|
@ -1434,6 +1438,38 @@ export class DevelopmentController extends Controller {
|
|||
return new HttpSuccess(_getDevelopment);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* API รายละเอียดโครงการ/หลักสูตรการฝึกอบรม tab8
|
||||
*
|
||||
* @summary DEV_00 - รายละเอียดโครงการ/หลักสูตรการฝึกอบรมtab8 #
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Get("tab8/{id}")
|
||||
async GetDevelopemtTab8ById(@Path() id: string) {
|
||||
const getDevelopment = await this.developmentRepository.findOne({
|
||||
relations: ["developmentRisks"],
|
||||
where: { id: id },
|
||||
});
|
||||
if (!getDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||
}
|
||||
let _getDevelopment = {
|
||||
developmentRisks:
|
||||
getDevelopment.developmentRisks == null
|
||||
? null
|
||||
: getDevelopment.developmentRisks.sort((a, b) =>
|
||||
(a.id == null ? "" : a.id).localeCompare(
|
||||
b.id == null ? "" : b.id,
|
||||
),
|
||||
),
|
||||
expect: getDevelopment.expect,
|
||||
};
|
||||
|
||||
return new HttpSuccess(_getDevelopment);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรม tab8
|
||||
*
|
||||
|
|
@ -1460,6 +1496,82 @@ export class DevelopmentController extends Controller {
|
|||
await this.developmentRepository.save(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
/**
|
||||
* API เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1
|
||||
*
|
||||
* @summary DEV_00 - เพิ่มโครงการ/หลักสูตรการฝึกอบรมtab8-1 #
|
||||
*
|
||||
* @param {string} id Id โครงการ
|
||||
*/
|
||||
@Put("tab8_1_add/{id}")
|
||||
async CreateDevelopmenttab8_1(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopment8_1,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const development = await this.developmentRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลโครงการ/หลักสูตรการฝึกอบรมนี้");
|
||||
}
|
||||
const before = structuredClone(development);
|
||||
const data = Object.assign(new DevelopmentEvaluation(), requestBody);
|
||||
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.developmentEvaluationRepository.save(data, { data: request });
|
||||
setLogDataDiff(request, { before, after: development });
|
||||
return new HttpSuccess(data.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบโครงการ/หลักสูตรการฝึกอบรมtab8-1
|
||||
*
|
||||
* @summary DEV_00 - ลบโครงการ/หลักสูตรการฝึกอบรมtab8-1 #
|
||||
*
|
||||
* @param {string} id Id รายการ
|
||||
*/
|
||||
@Delete("tab8_1/{id}")
|
||||
async DeleteDevelopmenttab8_1(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const development = await this.developmentEvaluationRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!development) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้เกี่ยวข้องเป้าหมายตามแผน");
|
||||
}
|
||||
await this.developmentEvaluationRepository.remove(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab8-1
|
||||
*
|
||||
* @summary DEV_00 - แก้ไขโครงการ/หลักสูตรการฝึกอบรมtab8-1 #
|
||||
*
|
||||
* @param {string} id Id รายการ
|
||||
*/
|
||||
@Put("tab8_1_edit/{id}")
|
||||
async UpdateDevelopmenttab8_1(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: UpdateDevelopment8_1,
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const development = await this.developmentEvaluationRepository.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.developmentEvaluationRepository.save(development, { data: request });
|
||||
return new HttpSuccess(development.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ค้นหาโครงการ
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ import { StrategyChild4 } from "./StrategyChild4";
|
|||
import { StrategyChild3 } from "./StrategyChild3";
|
||||
import { StrategyChild2 } from "./StrategyChild2";
|
||||
import { StrategyChild1 } from "./StrategyChild1";
|
||||
import { DevelopmentRisk } from "./DevelopmentRisk";
|
||||
|
||||
@Entity("development")
|
||||
export class Development extends EntityBase {
|
||||
|
|
@ -187,7 +188,12 @@ export class Development extends EntityBase {
|
|||
@OneToMany(() => PlannedGoal, (plannedGoal: PlannedGoal) => plannedGoal.developmentPlannedGoal)
|
||||
developmentPlannedGoals: PlannedGoal[];
|
||||
|
||||
////////////////////////////////////////tab ลักษณะโครงการ
|
||||
@OneToMany(
|
||||
() => DevelopmentRisk,
|
||||
(developmentRisk: DevelopmentRisk) => developmentRisk.development,
|
||||
)
|
||||
developmentRisks: DevelopmentRisk[];
|
||||
|
||||
@OneToMany(
|
||||
() => DevelopmentProjectType,
|
||||
(developmentProjectType: DevelopmentProjectType) => developmentProjectType.development,
|
||||
|
|
@ -821,8 +827,6 @@ export class UpdateDevelopment5 {
|
|||
isOutBudget: boolean;
|
||||
//end
|
||||
@Column()
|
||||
expect: string | null;
|
||||
@Column()
|
||||
topicAcademic: string | null;
|
||||
@Column()
|
||||
addressAcademic: string | null;
|
||||
|
|
@ -846,7 +850,7 @@ export class UpdateDevelopment7 {
|
|||
approved: Double | null;
|
||||
//end
|
||||
}
|
||||
export class UpdateDevelopment8 {
|
||||
export class UpdateDevelopment8_1 {
|
||||
//move from tab5
|
||||
@Column()
|
||||
issues: string | null;
|
||||
|
|
@ -860,3 +864,8 @@ export class UpdateDevelopment8 {
|
|||
riskManagement: string | null;
|
||||
//end
|
||||
}
|
||||
|
||||
export class UpdateDevelopment8{
|
||||
@Column()
|
||||
expect: string | null;
|
||||
}
|
||||
59
src/entities/DevelopmentRisk.ts
Normal file
59
src/entities/DevelopmentRisk.ts
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { Development } from "./Development";
|
||||
import { Province } from "./Province";
|
||||
|
||||
@Entity("developmentRisk")
|
||||
export class DevelopmentRisk extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ประเด็นความเสี่ยง",
|
||||
default: null,
|
||||
})
|
||||
issues: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "โอกาสที่จะเกิด",
|
||||
default: null,
|
||||
})
|
||||
chance: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ผลกระทบจากการเกิด",
|
||||
default: null,
|
||||
})
|
||||
effects: number;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "ระดับความเสี่ยง",
|
||||
default: null,
|
||||
})
|
||||
riskLevel: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "เเนวทางการบริหารความเสี่ยง",
|
||||
default: null,
|
||||
})
|
||||
riskManagement: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "คีย์นอก(FK)ของตาราง development",
|
||||
default: null,
|
||||
})
|
||||
developmentId: string;
|
||||
|
||||
@ManyToOne(() => Development, (development: Development) => development.developmentRisks)
|
||||
@JoinColumn({ name: "developmentId" })
|
||||
development: Development;
|
||||
}
|
||||
export class CreateDevelopmentRisk {
|
||||
@Column()
|
||||
address: string | null;
|
||||
@Column()
|
||||
provinceId: string;
|
||||
}
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class UpdateTableMigration2080720241723026794685 implements MigrationInterface {
|
||||
name = 'UpdateTableMigration2080720241723026794685'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`developmentRisk\` (\`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', \`issues\` varchar(255) NULL COMMENT 'ประเด็นความเสี่ยง', \`chance\` int NULL COMMENT 'โอกาสที่จะเกิด', \`effects\` int NULL COMMENT 'ผลกระทบจากการเกิด', \`riskLevel\` varchar(255) NULL COMMENT 'ระดับความเสี่ยง', \`riskManagement\` varchar(255) NULL COMMENT 'เเนวทางการบริหารความเสี่ยง', \`developmentId\` varchar(255) NULL COMMENT 'คีย์นอก(FK)ของตาราง development', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRisk\` ADD CONSTRAINT \`FK_b1990ff92f534f65a4653ef1671\` FOREIGN KEY (\`developmentId\`) REFERENCES \`development\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentRisk\` DROP FOREIGN KEY \`FK_b1990ff92f534f65a4653ef1671\``);
|
||||
await queryRunner.query(`DROP TABLE \`developmentRisk\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue