From ff39403172d80331ac734e88a4766b5d53d7a7be Mon Sep 17 00:00:00 2001 From: Kittapath Date: Thu, 14 Mar 2024 16:20:47 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=80=E0=B8=81=E0=B8=99=E0=B9=80=E0=B8=87?= =?UTF-8?q?=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99?= =?UTF-8?q?=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryEmployeeController.ts | 14 +- .../SalaryFormulaEmployeeController.ts | 245 ++++++++++++++++++ .../SalaryRankEmployeeController.ts | 14 +- src/entities/EmployeePosLevel.ts | 47 ++++ src/entities/EmployeePosType.ts | 34 +++ .../{SalaryEmployees.ts => SalaryEmployee.ts} | 24 +- src/entities/SalaryFormulaEmployee.ts | 140 ++++++++++ ...RankEmployees.ts => SalaryRankEmployee.ts} | 10 +- ...546008-add_table_salaryFormulaEmployees.ts | 34 +++ ...16994-add_table_salaryFormulaEmployees1.ts | 34 +++ 10 files changed, 570 insertions(+), 26 deletions(-) create mode 100644 src/controllers/SalaryFormulaEmployeeController.ts create mode 100644 src/entities/EmployeePosLevel.ts create mode 100644 src/entities/EmployeePosType.ts rename src/entities/{SalaryEmployees.ts => SalaryEmployee.ts} (68%) create mode 100644 src/entities/SalaryFormulaEmployee.ts rename src/entities/{SalaryRankEmployees.ts => SalaryRankEmployee.ts} (81%) create mode 100644 src/migration/1710405546008-add_table_salaryFormulaEmployees.ts create mode 100644 src/migration/1710408016994-add_table_salaryFormulaEmployees1.ts diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index d2beea6..93acc77 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -14,24 +14,24 @@ import { Query, } from "tsoa"; import { - SalaryEmployees, + SalaryEmployee, CreateSalaryEmployee, UpdateSalaryEmployee, -} from "../entities/SalaryEmployees"; +} from "../entities/SalaryEmployee"; import { AppDataSource } from "../database/data-source"; import { Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; -import { SalaryRankEmployees } from "../entities/SalaryRankEmployees"; +import { SalaryRankEmployee } from "../entities/SalaryRankEmployee"; import { randomUUID } from "crypto"; @Route("api/v1/salary/employee") @Tags("SalaryEmployee") @Security("bearerAuth") export class SalaryEmployeeController extends Controller { - private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployees); - private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); + private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee); + private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployee); /** * API สร้างผังเงินเดือนลูกจ้าง @@ -52,7 +52,7 @@ export class SalaryEmployeeController extends Controller { @Body() requestBody: CreateSalaryEmployee, @Request() request: { user: Record }, ) { - const salarys = Object.assign(new SalaryEmployees(), requestBody); + const salarys = Object.assign(new SalaryEmployee(), requestBody); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); } @@ -126,7 +126,7 @@ export class SalaryEmployeeController extends Controller { }); } - const mergeData = Object.assign(new SalaryEmployees(), requestBody); + const mergeData = Object.assign(new SalaryEmployee(), requestBody); chk_Salary.lastUpdateUserId = request.user.sub; chk_Salary.lastUpdateFullName = request.user.name; diff --git a/src/controllers/SalaryFormulaEmployeeController.ts b/src/controllers/SalaryFormulaEmployeeController.ts new file mode 100644 index 0000000..034f7f7 --- /dev/null +++ b/src/controllers/SalaryFormulaEmployeeController.ts @@ -0,0 +1,245 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Patch, + Route, + Security, + Tags, + Body, + Path, + Request, + Example, + SuccessResponse, + Response, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import { PosLevel, CreatePosLevel, UpdatePosLevel } from "../entities/PosLevel"; +import HttpError from "../interfaces/http-error"; +import { In, Not } from "typeorm"; +import { + CreateSalaryFormulaEmployee, + SalaryFormulaEmployee, + UpdateSalaryFormulaEmployee, +} from "../entities/SalaryFormulaEmployee"; +import { EmployeePosLevel } from "../entities/EmployeePosLevel"; +import { EmployeePosType } from "../entities/EmployeePosType"; +import { SalaryEmployee } from "../entities/SalaryEmployee"; + +@Route("api/v1/salary/formula") +@Tags("SalaryFormula") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class SalaryFormulaEmployeeController extends Controller { + private salaryFormulaEmployeeRepository = AppDataSource.getRepository(SalaryFormulaEmployee); + private employeePosLevelRepository = AppDataSource.getRepository(EmployeePosLevel); + private employeePosTypeRepository = AppDataSource.getRepository(EmployeePosType); + private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee); + + /** + * API เพิ่มหลักเกณฑ์ + * + * + */ + @Post() + async createFormula( + @Body() + requestBody: CreateSalaryFormulaEmployee, + @Request() request: { user: Record }, + ) { + const formula = Object.assign(new SalaryFormulaEmployee(), requestBody); + + const chkPosLevel = await this.employeePosLevelRepository.findOne({ + where: { + id: requestBody.posLevelId, + }, + }); + if (!chkPosLevel) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); + + const chkPosType = await this.employeePosTypeRepository.findOne({ + where: { + id: requestBody.posTypeId, + }, + }); + if (!chkPosType) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานตำแหน่งนี้"); + + const chkSalaryEmployee = await this.salaryEmployeeRepository.findOne({ + where: { + id: requestBody.salaryEmployeeId, + }, + }); + if (!chkSalaryEmployee) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้"); + + const chkFormula = await this.salaryFormulaEmployeeRepository.findOne({ + where: { + position: requestBody.position, + posTypeId: requestBody.posTypeId, + posLevelId: requestBody.posLevelId, + }, + }); + if (chkFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "หลักเกณฑ์นี้มีอยู่ในระบบแล้ว"); + + const chkSalaryEmployeeMin = await this.salaryEmployeeRepository.find({ + where: { + id: In(requestBody.salaryEmployeeMinIds), + }, + }); + + formula.salaryEmployeeMins = chkSalaryEmployeeMin; + formula.createdUserId = request.user.sub; + formula.createdFullName = request.user.name; + formula.lastUpdateUserId = request.user.sub; + formula.lastUpdateFullName = request.user.name; + await this.salaryFormulaEmployeeRepository.save(formula); + return new HttpSuccess(formula); + } + + /** + * API แก้ไขหลักเกณฑ์ + * + * + * @param {string} id Id หลักเกณฑ์ + */ + @Put("{id}") + async editFormula( + @Path() id: string, + @Body() requestBody: UpdateSalaryFormulaEmployee, + @Request() request: { user: Record }, + ) { + const formula = await this.salaryFormulaEmployeeRepository.findOne({ where: { id } }); + if (!formula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลหลักเกณฑ์นี้"); + + const chkFormula = await this.salaryFormulaEmployeeRepository.findOne({ + where: { + id: Not(id), + position: requestBody.position, + posTypeId: requestBody.posTypeId, + posLevelId: requestBody.posLevelId, + }, + }); + if (chkFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "หลักเกณฑ์นี้มีอยู่ในระบบแล้ว"); + + const chkPosLevel = await this.employeePosLevelRepository.findOne({ + where: { + id: requestBody.posLevelId, + }, + }); + if (!chkPosLevel) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับตำแหน่งนี้"); + + const chkPosType = await this.employeePosTypeRepository.findOne({ + where: { + id: requestBody.posTypeId, + }, + }); + if (!chkPosType) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานตำแหน่งนี้"); + + const chkSalaryEmployee = await this.salaryEmployeeRepository.findOne({ + where: { + id: requestBody.salaryEmployeeId, + }, + }); + if (!chkSalaryEmployee) + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้"); + + const chkSalaryEmployeeMin = await this.salaryEmployeeRepository.find({ + where: { + id: In(requestBody.salaryEmployeeMinIds), + }, + }); + formula.position = requestBody.position; + formula.salaryMin = requestBody.salaryMin; + formula.salary = requestBody.salary; + formula.salaryMax = requestBody.salaryMax; + formula.details = requestBody.details; + formula.salaryEmployeeId = requestBody.salaryEmployeeId; + formula.posTypeId = requestBody.posTypeId; + formula.posLevelId = requestBody.posLevelId; + formula.salaryEmployeeMins = chkSalaryEmployeeMin; + formula.lastUpdateUserId = request.user.sub; + formula.lastUpdateFullName = request.user.name; + await this.salaryFormulaEmployeeRepository.save(formula); + return new HttpSuccess(formula.id); + } + + /** + * API ลบหลักเกณฑ์ + * + * + * @param {string} id Id หลักเกณฑ์ + */ + @Delete("{id}") + async deleteFormula(@Path() id: string) { + const delFormula = await this.salaryFormulaEmployeeRepository.findOne({ where: { id } }); + if (!delFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้"); + + await this.salaryFormulaEmployeeRepository.remove(delFormula); + return new HttpSuccess(); + } + + /** + * API รายละเอียดหลักเกณฑ์ + * + * + * @param {string} id Id หลักเกณฑ์ + */ + @Get("{id}") + async getFormulaDetail(@Path() id: string) { + const getFormula = await this.salaryFormulaEmployeeRepository.findOne({ + relations: ["salaryEmployee", "posType", "posLevel"], + where: { id: id }, + }); + if (!getFormula) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังค่าจ้างนี้"); + + const mapFormula = { + id: getFormula.id, + posLevelId: getFormula.posLevelId, + position: getFormula.position, + posTypeId: getFormula.posTypeId, + details: getFormula.details, + salaryMin: getFormula.salaryMin, + salary: getFormula.salary, + salaryMax: getFormula.salaryMax, + salaryEmployeeId: getFormula.salaryEmployeeId, + }; + + return new HttpSuccess(mapFormula); + } + + /** + * API รายการหลักเกณฑ์ + * + * + */ + @Get() + async getFormula() { + const getFormula = await this.salaryFormulaEmployeeRepository.find({ + relations: ["salaryEmployee", "posType", "posLevel"], + }); + + const mapFormula = getFormula.map((item) => ({ + id: item.id, + // posLevelId: item.posLevelId, + posLevel: item.posLevel != null ? item.posLevel.posLevelName : null, + position: item.position, + // posTypeId: item.posTypeId, + posType: item.posType != null ? item.posType.posTypeName : null, + details: item.details, + salaryMin: item.salaryMin, + salary: item.salary, + salaryMax: item.salaryMax, + // salaryEmployeeId: item.salaryEmployeeId, + group: item.salaryEmployee != null ? item.salaryEmployee.group : null, + })); + return new HttpSuccess(mapFormula); + } +} diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts index cbd5535..ae5dacc 100644 --- a/src/controllers/SalaryRankEmployeeController.ts +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -20,10 +20,10 @@ import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { CreateSalaryRankEmployee, - SalaryRankEmployees, + SalaryRankEmployee, UpdateSalaryRankEmployee, -} from "../entities/SalaryRankEmployees"; -import { SalaryEmployees } from "../entities/SalaryEmployees"; +} from "../entities/SalaryRankEmployee"; +import { SalaryEmployee } from "../entities/SalaryEmployee"; @Route("api/v1/salary/rate/employee") @Tags("SalaryRankEmployee") @Security("bearerAuth") @@ -32,9 +32,9 @@ import { SalaryEmployees } from "../entities/SalaryEmployees"; "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", ) @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") -export class SalaryRankEmployeesController extends Controller { - private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); - private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployees); +export class SalaryRankEmployeeController extends Controller { + private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployee); + private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployee); /** * API สร้างอัตราเงินเดือนลูกจ้าง @@ -54,7 +54,7 @@ export class SalaryRankEmployeesController extends Controller { if (!checkSalary) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } - const salaryRankEmployee = Object.assign(new SalaryRankEmployees(), requestBody); + const salaryRankEmployee = Object.assign(new SalaryRankEmployee(), requestBody); salaryRankEmployee.createdUserId = request.user.sub; salaryRankEmployee.createdFullName = request.user.name; salaryRankEmployee.lastUpdateUserId = request.user.sub; diff --git a/src/entities/EmployeePosLevel.ts b/src/entities/EmployeePosLevel.ts new file mode 100644 index 0000000..fd2c681 --- /dev/null +++ b/src/entities/EmployeePosLevel.ts @@ -0,0 +1,47 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { EmployeePosType } from "./EmployeePosType"; +import { SalaryFormulaEmployee } from "./SalaryFormulaEmployee"; + +enum EmployeePosLevelAuthoritys { + HEAD = "HEAD", + DEPUTY = "DEPUTY", + GOVERNOR = "GOVERNOR", +} +@Entity("employeePosLevel") +export class EmployeePosLevel extends EntityBase { + @Column({ + comment: "ชื่อระดับชั้นงาน", + type: "int", + }) + posLevelName: number; + + @Column({ + comment: "ระดับของระดับชั้นงาน", + type: "int", + }) + posLevelRank: number; + + @Column({ + nullable: true, + comment: + "ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ", + type: "enum", + enum: EmployeePosLevelAuthoritys, + default: null, + }) + posLevelAuthority: EmployeePosLevelAuthoritys; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง employeePosType", + }) + posTypeId: string; + + @ManyToOne(() => EmployeePosType, (posType) => posType.posLevels) + @JoinColumn({ name: "posTypeId" }) + posType: EmployeePosType; + + @OneToMany(() => SalaryFormulaEmployee, (salaryFormulaEmployee) => salaryFormulaEmployee.posLevel) + salaryPosLevels: SalaryFormulaEmployee[]; +} diff --git a/src/entities/EmployeePosType.ts b/src/entities/EmployeePosType.ts new file mode 100644 index 0000000..e64908a --- /dev/null +++ b/src/entities/EmployeePosType.ts @@ -0,0 +1,34 @@ +import { Entity, Column, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { EmployeePosLevel } from "./EmployeePosLevel"; +import { SalaryFormulaEmployee } from "./SalaryFormulaEmployee"; + +@Entity("employeePosType") +export class EmployeePosType extends EntityBase { + @Column({ + nullable: true, + comment: "ชื่อกลุ่มงาน", + length: 255, + default: null, + }) + posTypeName: string; + + @Column({ + comment: "ระดับของกลุ่มงาน", + }) + posTypeRank: number; + + @Column({ + nullable: true, + comment: "ชื่อย่อกลุ่มงาน", + length: 255, + default: null, + }) + posTypeShortName: string; + + @OneToMany(() => EmployeePosLevel, (posLevel) => posLevel.posType) + posLevels: EmployeePosLevel[]; + + @OneToMany(() => SalaryFormulaEmployee, (salaryFormulaEmployee) => salaryFormulaEmployee.posType) + salaryPosTypes: SalaryFormulaEmployee[]; +} diff --git a/src/entities/SalaryEmployees.ts b/src/entities/SalaryEmployee.ts similarity index 68% rename from src/entities/SalaryEmployees.ts rename to src/entities/SalaryEmployee.ts index 7e0bd1a..fa9bd81 100644 --- a/src/entities/SalaryEmployees.ts +++ b/src/entities/SalaryEmployee.ts @@ -1,9 +1,10 @@ -import { Entity, Column, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany, ManyToMany } from "typeorm"; import { EntityBase } from "./base/Base"; -import { SalaryRankEmployees } from "./SalaryRankEmployees"; +import { SalaryRankEmployee } from "./SalaryRankEmployee"; +import { SalaryFormulaEmployee } from "./SalaryFormulaEmployee"; -@Entity("salaryEmployees") -export class SalaryEmployees extends EntityBase { +@Entity("salaryEmployee") +export class SalaryEmployee extends EntityBase { @Column({ comment: "ชื่อผัง", length: 255, @@ -54,11 +55,20 @@ export class SalaryEmployees extends EntityBase { }) details: string; + @OneToMany(() => SalaryRankEmployee, (salaryRankEmployee) => salaryRankEmployee.salaryEmployee_) + salaryRankEmployees_: SalaryRankEmployee[]; + @OneToMany( - () => SalaryRankEmployees, - (salaryRankEmployees) => salaryRankEmployees.salaryEmployees_, + () => SalaryFormulaEmployee, + (salaryFormulaEmployee) => salaryFormulaEmployee.salaryEmployee, ) - salaryRankEmployees_: SalaryRankEmployees[]; + salaryFormulaEmployees: SalaryFormulaEmployee[]; + + @ManyToMany( + () => SalaryFormulaEmployee, + (salaryFormulaEmployee) => salaryFormulaEmployee.salaryEmployeeMins, + ) + salaryFormulaEmployeeMins: SalaryFormulaEmployee[]; } export class CreateSalaryEmployee { diff --git a/src/entities/SalaryFormulaEmployee.ts b/src/entities/SalaryFormulaEmployee.ts new file mode 100644 index 0000000..0f9bc9e --- /dev/null +++ b/src/entities/SalaryFormulaEmployee.ts @@ -0,0 +1,140 @@ +import { Entity, Column, ManyToOne, JoinColumn, ManyToMany, JoinTable } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { SalaryEmployee } from "./SalaryEmployee"; +import { EmployeePosType } from "./EmployeePosType"; +import { EmployeePosLevel } from "./EmployeePosLevel"; + +@Entity("salaryFormulaEmployee") +export class SalaryFormulaEmployee extends EntityBase { + @Column({ + nullable: true, + comment: "ตำแหน่ง", + length: 255, + default: null, + }) + position: string; + + @Column({ + nullable: true, + type: "double", + comment: "ขั้นต่ำสุด", + default: null, + }) + salaryMin?: number | null; + + @Column({ + nullable: true, + type: "double", + comment: "ขั้นสูงสุดเดิม", + default: null, + }) + salary?: number | null; + + @Column({ + nullable: true, + type: "double", + comment: "อัตราค่าจ้างขั้นสูงใหม่", + default: null, + }) + salaryMax?: number | null; + + @Column({ + nullable: true, + comment: "หมายเหตุ", + length: 255, + default: null, + }) + details?: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง salaryEmployee", + }) + salaryEmployeeId: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง employeePosType", + }) + posTypeId: string; + + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง employeePosLevel", + }) + posLevelId: string; + + @ManyToOne(() => SalaryEmployee, (salaryEmployee) => salaryEmployee.salaryFormulaEmployees) + @JoinColumn({ name: "salaryEmployeeId" }) + salaryEmployee: SalaryEmployee; + + @ManyToOne(() => EmployeePosType, (posType) => posType.salaryPosTypes) + @JoinColumn({ name: "posTypeId" }) + posType: EmployeePosType; + + @ManyToOne(() => EmployeePosLevel, (posLevel) => posLevel.salaryPosLevels) + @JoinColumn({ name: "posLevelId" }) + posLevel: EmployeePosLevel; + + @ManyToMany(() => SalaryEmployee, (salaryEmployee) => salaryEmployee.salaryFormulaEmployeeMins) + @JoinTable() + salaryEmployeeMins: SalaryEmployee[]; +} + +export class CreateSalaryFormulaEmployee { + @Column() + position: string; + + @Column() + salaryMin?: number | null; + + @Column() + salary?: number | null; + + @Column() + salaryMax?: number | null; + + @Column() + details?: string; + + @Column() + salaryEmployeeId: string; + + @Column() + posTypeId: string; + + @Column() + posLevelId: string; + + @Column() + salaryEmployeeMinIds: string[]; +} + +export class UpdateSalaryFormulaEmployee { + @Column() + position: string; + + @Column() + salaryMin?: number | null; + + @Column() + salary?: number | null; + + @Column() + salaryMax?: number | null; + + @Column() + details?: string; + + @Column() + salaryEmployeeId: string; + + @Column() + posTypeId: string; + + @Column() + posLevelId: string; + + @Column() + salaryEmployeeMinIds: string[]; +} diff --git a/src/entities/SalaryRankEmployees.ts b/src/entities/SalaryRankEmployee.ts similarity index 81% rename from src/entities/SalaryRankEmployees.ts rename to src/entities/SalaryRankEmployee.ts index 0dbdcd0..4a5aeb4 100644 --- a/src/entities/SalaryRankEmployees.ts +++ b/src/entities/SalaryRankEmployee.ts @@ -1,9 +1,9 @@ import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; -import { SalaryEmployees } from "./SalaryEmployees"; +import { SalaryEmployee } from "./SalaryEmployee"; -@Entity("salaryRankEmployees") -export class SalaryRankEmployees extends EntityBase { +@Entity("salaryRankEmployee") +export class SalaryRankEmployee extends EntityBase { @Column({ length: 40, comment: "คีย์นอก(FK)ของตาราง salaryEmployee", @@ -32,9 +32,9 @@ export class SalaryRankEmployees extends EntityBase { }) salaryDay: number | null; - @ManyToOne(() => SalaryEmployees, (salaryEmployees) => salaryEmployees.salaryRankEmployees_) + @ManyToOne(() => SalaryEmployee, (salaryEmployee) => salaryEmployee.salaryRankEmployees_) @JoinColumn({ name: "salaryEmployeeId" }) - salaryEmployees_: SalaryEmployees; + salaryEmployee_: SalaryEmployee; } export class CreateSalaryRankEmployee { diff --git a/src/migration/1710405546008-add_table_salaryFormulaEmployees.ts b/src/migration/1710405546008-add_table_salaryFormulaEmployees.ts new file mode 100644 index 0000000..eabc00b --- /dev/null +++ b/src/migration/1710405546008-add_table_salaryFormulaEmployees.ts @@ -0,0 +1,34 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableSalaryFormulaEmployees1710405546008 implements MigrationInterface { + name = 'AddTableSalaryFormulaEmployees1710405546008' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`employeePosLevel\` (\`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', \`posLevelName\` int NOT NULL COMMENT 'ชื่อระดับชั้นงาน', \`posLevelRank\` int NOT NULL COMMENT 'ระดับของระดับชั้นงาน', \`posLevelAuthority\` enum ('HEAD', 'DEPUTY', 'GOVERNOR') NULL COMMENT 'ผู้มีอำนาจสั่งบรรจุของระดับนี้ head = หัวหน้าหน่วยงาน , deputy = ปลัด , governor = ผู้ว่าฯ', \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`employeePosType\` (\`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', \`posTypeName\` varchar(255) NULL COMMENT 'ชื่อกลุ่มงาน', \`posTypeRank\` int NOT NULL COMMENT 'ระดับของกลุ่มงาน', \`posTypeShortName\` varchar(255) NULL COMMENT 'ชื่อย่อกลุ่มงาน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`salaryFormulaEmployees\` (\`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 'ตำแหน่ง', \`salaryMin\` double NULL COMMENT 'ขั้นต่ำสุด', \`salary\` double NULL COMMENT 'ขั้นสูงสุดเดิม', \`salaryMix\` double NULL COMMENT 'อัตราค่าจ้างขั้นสูงใหม่', \`details\` varchar(255) NULL COMMENT 'หมายเหตุ', \`salaryEmployeeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salaryEmployee', \`postypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', \`posLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosLevel', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\` (\`salaryFormulaEmployeesId\` varchar(36) NOT NULL, \`salaryEmployeesId\` varchar(36) NOT NULL, INDEX \`IDX_dcc6e39a2e169fbaf4c477b1f8\` (\`salaryFormulaEmployeesId\`), INDEX \`IDX_b7e8fed20263673e4be15b3ca3\` (\`salaryEmployeesId\`), PRIMARY KEY (\`salaryFormulaEmployeesId\`, \`salaryEmployeesId\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`employeePosLevel\` ADD CONSTRAINT \`FK_7fb9ab868f3f46b44f460c984f1\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` ADD CONSTRAINT \`FK_57e0a12357e1fe6dba2e34c2325\` FOREIGN KEY (\`salaryEmployeeId\`) REFERENCES \`salaryEmployees\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` ADD CONSTRAINT \`FK_4fc21fb89eb2cc9baa6c7301b14\` FOREIGN KEY (\`postypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` ADD CONSTRAINT \`FK_239beab5c2ff5a1d9a80f29516b\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\` ADD CONSTRAINT \`FK_dcc6e39a2e169fbaf4c477b1f88\` FOREIGN KEY (\`salaryFormulaEmployeesId\`) REFERENCES \`salaryFormulaEmployees\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\` ADD CONSTRAINT \`FK_b7e8fed20263673e4be15b3ca30\` FOREIGN KEY (\`salaryEmployeesId\`) REFERENCES \`salaryEmployees\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\` DROP FOREIGN KEY \`FK_b7e8fed20263673e4be15b3ca30\``); + await queryRunner.query(`ALTER TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\` DROP FOREIGN KEY \`FK_dcc6e39a2e169fbaf4c477b1f88\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` DROP FOREIGN KEY \`FK_239beab5c2ff5a1d9a80f29516b\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` DROP FOREIGN KEY \`FK_4fc21fb89eb2cc9baa6c7301b14\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployees\` DROP FOREIGN KEY \`FK_57e0a12357e1fe6dba2e34c2325\``); + await queryRunner.query(`ALTER TABLE \`employeePosLevel\` DROP FOREIGN KEY \`FK_7fb9ab868f3f46b44f460c984f1\``); + await queryRunner.query(`DROP INDEX \`IDX_b7e8fed20263673e4be15b3ca3\` ON \`salary_formula_employees_salary_employee_mins_salary_employees\``); + await queryRunner.query(`DROP INDEX \`IDX_dcc6e39a2e169fbaf4c477b1f8\` ON \`salary_formula_employees_salary_employee_mins_salary_employees\``); + await queryRunner.query(`DROP TABLE \`salary_formula_employees_salary_employee_mins_salary_employees\``); + await queryRunner.query(`DROP TABLE \`salaryFormulaEmployees\``); + await queryRunner.query(`DROP TABLE \`employeePosType\``); + await queryRunner.query(`DROP TABLE \`employeePosLevel\``); + } + +} diff --git a/src/migration/1710408016994-add_table_salaryFormulaEmployees1.ts b/src/migration/1710408016994-add_table_salaryFormulaEmployees1.ts new file mode 100644 index 0000000..92facd8 --- /dev/null +++ b/src/migration/1710408016994-add_table_salaryFormulaEmployees1.ts @@ -0,0 +1,34 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableSalaryFormulaEmployees11710408016994 implements MigrationInterface { + name = 'AddTableSalaryFormulaEmployees11710408016994' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`salaryFormulaEmployee\` (\`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 'ตำแหน่ง', \`salaryMin\` double NULL COMMENT 'ขั้นต่ำสุด', \`salary\` double NULL COMMENT 'ขั้นสูงสุดเดิม', \`salaryMax\` double NULL COMMENT 'อัตราค่าจ้างขั้นสูงใหม่', \`details\` varchar(255) NULL COMMENT 'หมายเหตุ', \`salaryEmployeeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salaryEmployee', \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosType', \`posLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง employeePosLevel', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`salaryEmployee\` (\`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) NOT NULL COMMENT 'ชื่อผัง', \`group\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง', \`isActive\` tinyint NOT NULL COMMENT 'สถานะการใช้งาน', \`date\` datetime NULL COMMENT 'ให้ไว้ ณ วันที่', \`startDate\` datetime NULL COMMENT 'วันที่มีผลบังคับใช้', \`endDate\` datetime NULL COMMENT 'วันที่สิ้นสุดบังคับใช้', \`details\` varchar(255) NULL COMMENT 'คำอธิบาย', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`salaryRankEmployee\` (\`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', \`salaryEmployeeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salaryEmployee', \`step\` double NOT NULL COMMENT 'ลำดับขั้น', \`salaryMonth\` double NULL COMMENT 'ค่าจ้างรายเดือน', \`salaryDay\` double NULL COMMENT 'ค่าจ้างรายวัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`CREATE TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\` (\`salaryFormulaEmployeeId\` varchar(36) NOT NULL, \`salaryEmployeeId\` varchar(36) NOT NULL, INDEX \`IDX_fa3ec296ae6f28977d5d8a768e\` (\`salaryFormulaEmployeeId\`), INDEX \`IDX_5988accf9d5e64e7ecdfa9328d\` (\`salaryEmployeeId\`), PRIMARY KEY (\`salaryFormulaEmployeeId\`, \`salaryEmployeeId\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` ADD CONSTRAINT \`FK_664ca569737038da8f19f80d91a\` FOREIGN KEY (\`salaryEmployeeId\`) REFERENCES \`salaryEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` ADD CONSTRAINT \`FK_0af8cb9cfd0d5de909488070102\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`employeePosType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` ADD CONSTRAINT \`FK_5a379c5a2203681fd7113da4f16\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`employeePosLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryRankEmployee\` ADD CONSTRAINT \`FK_ab870f5dfb24b1e266056ab3753\` FOREIGN KEY (\`salaryEmployeeId\`) REFERENCES \`salaryEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\` ADD CONSTRAINT \`FK_fa3ec296ae6f28977d5d8a768e7\` FOREIGN KEY (\`salaryFormulaEmployeeId\`) REFERENCES \`salaryFormulaEmployee\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`); + await queryRunner.query(`ALTER TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\` ADD CONSTRAINT \`FK_5988accf9d5e64e7ecdfa9328d0\` FOREIGN KEY (\`salaryEmployeeId\`) REFERENCES \`salaryEmployee\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\` DROP FOREIGN KEY \`FK_5988accf9d5e64e7ecdfa9328d0\``); + await queryRunner.query(`ALTER TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\` DROP FOREIGN KEY \`FK_fa3ec296ae6f28977d5d8a768e7\``); + await queryRunner.query(`ALTER TABLE \`salaryRankEmployee\` DROP FOREIGN KEY \`FK_ab870f5dfb24b1e266056ab3753\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` DROP FOREIGN KEY \`FK_5a379c5a2203681fd7113da4f16\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` DROP FOREIGN KEY \`FK_0af8cb9cfd0d5de909488070102\``); + await queryRunner.query(`ALTER TABLE \`salaryFormulaEmployee\` DROP FOREIGN KEY \`FK_664ca569737038da8f19f80d91a\``); + await queryRunner.query(`DROP INDEX \`IDX_5988accf9d5e64e7ecdfa9328d\` ON \`salary_formula_employee_salary_employee_mins_salary_employee\``); + await queryRunner.query(`DROP INDEX \`IDX_fa3ec296ae6f28977d5d8a768e\` ON \`salary_formula_employee_salary_employee_mins_salary_employee\``); + await queryRunner.query(`DROP TABLE \`salary_formula_employee_salary_employee_mins_salary_employee\``); + await queryRunner.query(`DROP TABLE \`salaryRankEmployee\``); + await queryRunner.query(`DROP TABLE \`salaryEmployee\``); + await queryRunner.query(`DROP TABLE \`salaryFormulaEmployee\``); + } + +}