add devproject
This commit is contained in:
parent
7092d67973
commit
0ded2dc6b0
4 changed files with 152 additions and 1 deletions
|
|
@ -26,6 +26,7 @@ import {
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||
import { Not, Like, Brackets } from "typeorm";
|
||||
import { DevelopmentProject } from "../entities/developmentProject";
|
||||
|
||||
@Route("api/v1/kpi/user/achievement/development")
|
||||
@Tags("KpiUserDevelopment")
|
||||
|
|
@ -38,6 +39,7 @@ import { Not, Like, Brackets } from "typeorm";
|
|||
export class KpiUserDevelopmentController extends Controller {
|
||||
private kpiUserDevelopmentRepository = AppDataSource.getRepository(KpiUserDevelopment);
|
||||
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
||||
private developmentProjectRepository = AppDataSource.getRepository(DevelopmentProject);
|
||||
|
||||
/**
|
||||
* API เพิ่มพัฒนาตนเอง
|
||||
|
|
@ -90,6 +92,22 @@ export class KpiUserDevelopmentController extends Controller {
|
|||
kpiUserDevelopment.lastUpdateUserId = request.user.sub;
|
||||
kpiUserDevelopment.lastUpdateFullName = request.user.name;
|
||||
await this.kpiUserDevelopmentRepository.save(kpiUserDevelopment);
|
||||
|
||||
if (requestBody.developmentProjects != null) {
|
||||
await Promise.all(
|
||||
requestBody.developmentProjects.map(async (x) => {
|
||||
let data = new DevelopmentProject();
|
||||
data.name = x;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.kpiUserDevelopmentId = kpiUserDevelopment.id;
|
||||
await this.developmentProjectRepository.save(data);
|
||||
}),
|
||||
);
|
||||
}
|
||||
|
||||
return new HttpSuccess(kpiUserDevelopment.id);
|
||||
}
|
||||
|
||||
|
|
@ -106,10 +124,30 @@ export class KpiUserDevelopmentController extends Controller {
|
|||
@Body() requestBody: UpdateKpiUserDevelopment,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ where: { id } });
|
||||
const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({
|
||||
where: { id },
|
||||
relations: {
|
||||
developmentProjects: true,
|
||||
},
|
||||
});
|
||||
if (!kpiUserDevelopment) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลพัฒนาตนเองนี้");
|
||||
}
|
||||
await this.developmentProjectRepository.remove(kpiUserDevelopment.developmentProjects);
|
||||
if (requestBody.developmentProjects != null) {
|
||||
await Promise.all(
|
||||
requestBody.developmentProjects.map(async (x) => {
|
||||
let data = new DevelopmentProject();
|
||||
data.name = x;
|
||||
data.createdUserId = request.user.sub;
|
||||
data.createdFullName = request.user.name;
|
||||
data.lastUpdateUserId = request.user.sub;
|
||||
data.lastUpdateFullName = request.user.name;
|
||||
data.kpiUserDevelopmentId = kpiUserDevelopment.id;
|
||||
await this.developmentProjectRepository.save(data);
|
||||
}),
|
||||
);
|
||||
}
|
||||
const chkUserEvaluation = await this.kpiUserEvaluationRepository.findOne({
|
||||
where: { id: requestBody.kpiUserEvaluationId },
|
||||
});
|
||||
|
|
@ -198,6 +236,12 @@ export class KpiUserDevelopmentController extends Controller {
|
|||
isDevelopment70: getKpiUserDevelopment.isDevelopment70,
|
||||
isDevelopment20: getKpiUserDevelopment.isDevelopment20,
|
||||
isDevelopment10: getKpiUserDevelopment.isDevelopment10,
|
||||
reasonDevelopment70: getKpiUserDevelopment.reasonDevelopment70,
|
||||
reasonDevelopment20: getKpiUserDevelopment.reasonDevelopment20,
|
||||
reasonDevelopment10: getKpiUserDevelopment.reasonDevelopment10,
|
||||
developmentProjectTechniqueActuals: getKpiUserDevelopment.developmentProjects
|
||||
.map((x) => x.name)
|
||||
.sort(),
|
||||
};
|
||||
|
||||
return new HttpSuccess(mapKpiUserDevelopment);
|
||||
|
|
|
|||
41
src/entities/developmentProject.ts
Normal file
41
src/entities/developmentProject.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { KpiUserDevelopment } from "./kpiUserDevelopment";
|
||||
|
||||
@Entity("developmentProject")
|
||||
export class DevelopmentProject extends EntityBase {
|
||||
@Column({
|
||||
// TRAINING = การอบรม
|
||||
// MEETING = การประชุม
|
||||
// SEMINAR = การสัมมนา
|
||||
// STUDY_TOUR = การศึกษาดูงาน
|
||||
// ACADEMIC_SEMINAR = การสัมมนาทางวิชาการ
|
||||
// WORKSHOP = การสัมมนาเชิงปฏิบัติการ
|
||||
// SPECIAL_LECTURE = การบรรยายพิเศษ
|
||||
// LECTURE = การบรรยาย
|
||||
// STUDY_TRAINING = การฝึกศึกษา
|
||||
// OTHER = อื่น
|
||||
nullable: true,
|
||||
comment: "เทคนิควิธีการที่ใช้ในการพัฒนา",
|
||||
default: null,
|
||||
})
|
||||
name: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "โครงการ/หลักสูตรการฝึกอบรม",
|
||||
default: null,
|
||||
})
|
||||
kpiUserDevelopmentId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => KpiUserDevelopment,
|
||||
(kpiUserDevelopment: KpiUserDevelopment) => kpiUserDevelopment.developmentProjects,
|
||||
)
|
||||
@JoinColumn({ name: "kpiUserDevelopmentId" })
|
||||
kpiUserDevelopment: KpiUserDevelopment;
|
||||
}
|
||||
export class CreateDevelopmentProject {
|
||||
@Column()
|
||||
name: string;
|
||||
}
|
||||
|
|
@ -2,6 +2,7 @@ import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm";
|
|||
import { EntityBase } from "./base/Base";
|
||||
import { KpiUserEvaluation } from "./kpiUserEvaluation";
|
||||
import { KpiUserEvaluationReasonDevelopment } from "./kpiUserEvaluationReasonDevelopment";
|
||||
import { DevelopmentProject } from "./developmentProject";
|
||||
|
||||
@Entity("kpiUserDevelopment")
|
||||
export class KpiUserDevelopment extends EntityBase {
|
||||
|
|
@ -73,6 +74,33 @@ export class KpiUserDevelopment extends EntityBase {
|
|||
})
|
||||
isDevelopment10: boolean;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 70 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment70: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 20 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment20: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "รายละเอียดอื่นๆ 10 แผน",
|
||||
default: null,
|
||||
})
|
||||
reasonDevelopment10: string;
|
||||
|
||||
@OneToMany(
|
||||
() => DevelopmentProject,
|
||||
(developmentProject: DevelopmentProject) => developmentProject.kpiUserDevelopment,
|
||||
)
|
||||
developmentProjects: DevelopmentProject[];
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
|
|
@ -104,6 +132,14 @@ export class CreateKpiUserDevelopment {
|
|||
@Column()
|
||||
achievement0?: string | null;
|
||||
@Column()
|
||||
developmentProjects?: string[];
|
||||
@Column()
|
||||
reasonDevelopment70?: string;
|
||||
@Column()
|
||||
reasonDevelopment20?: string;
|
||||
@Column()
|
||||
reasonDevelopment10?: string;
|
||||
@Column()
|
||||
isDevelopment70: boolean;
|
||||
@Column()
|
||||
isDevelopment20: boolean;
|
||||
|
|
@ -125,6 +161,14 @@ export class UpdateKpiUserDevelopment {
|
|||
@Column()
|
||||
achievement0?: string | null;
|
||||
@Column()
|
||||
developmentProjects?: string[];
|
||||
@Column()
|
||||
reasonDevelopment70?: string;
|
||||
@Column()
|
||||
reasonDevelopment20?: string;
|
||||
@Column()
|
||||
reasonDevelopment10?: string;
|
||||
@Column()
|
||||
isDevelopment70: boolean;
|
||||
@Column()
|
||||
isDevelopment20: boolean;
|
||||
|
|
|
|||
22
src/migration/1721189944874-add_table_dev_add_reasondev70.ts
Normal file
22
src/migration/1721189944874-add_table_dev_add_reasondev70.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class AddTableDevAddReasondev701721189944874 implements MigrationInterface {
|
||||
name = 'AddTableDevAddReasondev701721189944874'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`developmentProject\` (\`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 'เทคนิควิธีการที่ใช้ในการพัฒนา', \`kpiUserDevelopmentId\` varchar(255) NULL COMMENT 'โครงการ/หลักสูตรการฝึกอบรม', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` ADD \`reasonDevelopment70\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 70 แผน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` ADD \`reasonDevelopment20\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 20 แผน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` ADD \`reasonDevelopment10\` varchar(255) NULL COMMENT 'รายละเอียดอื่นๆ 10 แผน'`);
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` ADD CONSTRAINT \`FK_7ebd46d508d388b25dd45a17c9b\` FOREIGN KEY (\`kpiUserDevelopmentId\`) REFERENCES \`kpiUserDevelopment\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`developmentProject\` DROP FOREIGN KEY \`FK_7ebd46d508d388b25dd45a17c9b\``);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` DROP COLUMN \`reasonDevelopment10\``);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` DROP COLUMN \`reasonDevelopment20\``);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserDevelopment\` DROP COLUMN \`reasonDevelopment70\``);
|
||||
await queryRunner.query(`DROP TABLE \`developmentProject\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue