From 87f29e22e994e8ce5ae9f3ac3af69e32265c5c31 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 09:30:04 +0700 Subject: [PATCH 1/6] =?UTF-8?q?=E0=B8=9C=E0=B8=B1=E0=B8=87=E0=B9=80?= =?UTF-8?q?=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD?= =?UTF-8?q?=E0=B8=99=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryController.ts | 28 +- src/controllers/SalaryEmployeeController.ts | 287 ++++++++++++++++++ src/controllers/SalaryRankController.ts | 38 +-- .../SalaryRankEmployeeController.ts | 149 +++++++++ src/entities/SalaryEmployees.ts | 112 +++++++ src/entities/SalaryRankEmployees.ts | 66 ++++ ...1710296971419-add_table_salaryEmployees.ts | 80 +++++ 7 files changed, 699 insertions(+), 61 deletions(-) create mode 100644 src/controllers/SalaryEmployeeController.ts create mode 100644 src/controllers/SalaryRankEmployeeController.ts create mode 100644 src/entities/SalaryEmployees.ts create mode 100644 src/entities/SalaryRankEmployees.ts create mode 100644 src/migration/1710296971419-add_table_salaryEmployees.ts diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 6801cf6..6b7f500 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -4,7 +4,6 @@ import { Post, Put, Delete, - Patch, Route, Security, Tags, @@ -18,12 +17,11 @@ import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { AppDataSource } from "../database/data-source"; -import { DeepPartial, In, IsNull, Not } from "typeorm"; +import { Not } from "typeorm"; import HttpSuccess from "../interfaces/http-success"; import HttpError from "../interfaces/http-error"; import HttpStatusCode from "../interfaces/http-status"; import { SalaryRanks } from "../entities/SalaryRanks"; -import { query } from "express"; import { randomUUID } from "crypto"; @Route("api/v1/salary") @@ -56,7 +54,6 @@ export class Salary extends Controller { @Body() requestBody: CreateSalary, @Request() request: { user: Record }, ) { - // try { const salarys = Object.assign(new Salarys(), requestBody); if (!salarys) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); @@ -78,7 +75,6 @@ export class Salary extends Controller { const chk_3fields = await this.salaryRepository.findOne({ where: { - name: salarys.name, posTypeId: salarys.posTypeId, posLevelId: salarys.posLevelId, }, @@ -94,9 +90,6 @@ export class Salary extends Controller { salarys.lastUpdateFullName = request.user.name; await this.salaryRepository.save(salarys); return new HttpSuccess(salarys.id); - // } catch (error: any) { - // throw new Error(error); - // } } /** @@ -122,7 +115,6 @@ export class Salary extends Controller { @Body() requestBody: UpdateSalary, @Request() request: { user: Record }, ) { - // try { const chk_Salary = await this.salaryRepository.findOne({ where: { id: id }, }); @@ -147,7 +139,7 @@ export class Salary extends Controller { }); if (chk_3fields.length > 0 && requestBody.isActive) { - chk_3fields.forEach(async (item) => { + chk_3fields.forEach(async (item) => { item.isActive = false; item.lastUpdateUserId = request.user.sub; item.lastUpdateFullName = request.user.name; @@ -177,9 +169,6 @@ export class Salary extends Controller { this.salaryRepository.merge(chk_Salary, mergeData); await this.salaryRepository.save(chk_Salary); return new HttpSuccess(id); - // } catch (error: any) { - // throw new Error(error); - // } } /** @@ -191,7 +180,6 @@ export class Salary extends Controller { */ @Delete("{id}") async delete_salary(@Path() id: string) { - // try { const chk_Salary = await this.salaryRepository.findOne({ where: { id: id }, }); @@ -210,9 +198,6 @@ export class Salary extends Controller { await this.salaryRankRepository.remove(del_SalaryRank); await this.salaryRepository.remove(chk_Salary); return new HttpSuccess(); - // } catch (error: any) { - // throw new Error(error); - // } } /** @@ -234,7 +219,6 @@ export class Salary extends Controller { detail: "string", //คำอธิบาย }) async GetSalaryById(@Path() id: string) { - // try { const salary = await this.salaryRepository.findOne({ where: { id: id }, select: [ @@ -253,9 +237,6 @@ export class Salary extends Controller { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } return new HttpSuccess(salary); - // } catch (error: any) { - // throw new Error(error); - // } } /** @@ -273,13 +254,12 @@ export class Salary extends Controller { const [salary, total] = await this.salaryRepository.findAndCount({ relations: ["posLevel_", "posType_"], order: { - // startDate: "DESC", isActive: "DESC", posType_: { - posTypeRank: "DESC" + posTypeRank: "DESC", }, posLevel_: { - posLevelRank: "DESC" + posLevelRank: "DESC", }, }, ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts new file mode 100644 index 0000000..2d722e0 --- /dev/null +++ b/src/controllers/SalaryEmployeeController.ts @@ -0,0 +1,287 @@ +import { + Controller, + Get, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + Example, + Query, +} from "tsoa"; +import { + SalaryEmployees, + CreateSalaryEmployee, + UpdateSalaryEmployee, +} from "../entities/SalaryEmployees"; +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 { randomUUID } from "crypto"; + +@Route("api/v1/salary") +@Tags("Salary") +@Security("bearerAuth") +export class Salary extends Controller { + private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployees); + private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); + + /** + * API สร้างผังเงินเดือนลูกจ้าง + * + * + */ + @Post() + @Example({ + name: "string", //*ชื่อผัง + group: "string", //*กลุ่มผัง + isActive: "boolean", //*สถานะการใช้งาน + date: "datetime", //ให้ไว้ ณ วันที่ + startDate: "datetime", //วันที่มีผลบังคับใช้ + endDate: "datetime", //วันที่สิ้นสุดบังคับใช้ + detail: "string", //คำอธิบาย + }) + async create_salary( + @Body() requestBody: CreateSalaryEmployee, + @Request() request: { user: Record }, + ) { + const salarys = Object.assign(new SalaryEmployees(), requestBody); + if (!salarys) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); + } + + const chk_3fields = await this.salaryEmployeeRepository.findOne({ + where: { + group: salarys.group, + }, + }); + if (chk_3fields && salarys.isActive) { + salarys.isActive = false; + } + salarys.createdUserId = request.user.sub; + salarys.createdFullName = request.user.name; + salarys.lastUpdateUserId = request.user.sub; + salarys.lastUpdateFullName = request.user.name; + await this.salaryEmployeeRepository.save(salarys); + return new HttpSuccess(salarys.id); + } + + /** + * API แก้ไขผังเงินเดือนลูกจ้าง + * + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Put("{id}") + @Example({ + name: "string", //*ชื่อผัง + group: "string", //*กลุ่มผัง + isActive: "boolean", //*สถานะการใช้งาน + date: "datetime", //ให้ไว้ ณ วันที่ + startDate: "datetime", //วันที่มีผลบังคับใช้ + endDate: "datetime", //วันที่สิ้นสุดบังคับใช้ + detail: "string", //คำอธิบาย + }) + async update_salary( + @Path() id: string, + @Body() requestBody: UpdateSalaryEmployee, + @Request() request: { user: Record }, + ) { + const chk_Salary = await this.salaryEmployeeRepository.findOne({ + where: { id: id }, + }); + if (!chk_Salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); + } + + if (chk_Salary.isActive && !requestBody.isActive) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถแก้ไขสถานะการใช้งานที่เป็น Default ได้", + ); + } + + const chk_3fields = await this.salaryEmployeeRepository.find({ + where: { + group: requestBody.group, + isActive: true, + id: Not(id), + }, + }); + + if (chk_3fields.length > 0 && requestBody.isActive) { + chk_3fields.forEach(async (item) => { + item.isActive = false; + item.lastUpdateUserId = request.user.sub; + item.lastUpdateFullName = request.user.name; + item.lastUpdatedAt = new Date(); + await this.salaryEmployeeRepository.save(chk_3fields); + }); + } + + const mergeData = Object.assign(new SalaryEmployees(), requestBody); + + chk_Salary.lastUpdateUserId = request.user.sub; + chk_Salary.lastUpdateFullName = request.user.name; + chk_Salary.lastUpdatedAt = new Date(); + this.salaryEmployeeRepository.merge(chk_Salary, mergeData); + await this.salaryEmployeeRepository.save(chk_Salary); + return new HttpSuccess(id); + } + + /** + * API ลบผังเงินเดือนลูกจ้าง + * + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Delete("{id}") + async delete_salary(@Path() id: string) { + const chk_Salary = await this.salaryEmployeeRepository.findOne({ + where: { id: id }, + }); + if (!chk_Salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); + } + if (chk_Salary.isActive) { + throw new HttpError( + HttpStatusCode.NOT_FOUND, + "ไม่สามารถลบข้อมูลนี้ได้ เนื่องจากเปิดใช้งานอยู่", + ); + } + const del_SalaryRank = await this.salaryRankEmployeeRepository.find({ + where: { salaryEmployeeId: chk_Salary.id }, + }); + await this.salaryRankEmployeeRepository.remove(del_SalaryRank); + await this.salaryEmployeeRepository.remove(chk_Salary); + return new HttpSuccess(); + } + + /** + * API รายละเอียดผังเงินเดือนลูกจ้าง + * + * + * @param {string} id Guid, *Id ผังเงินเดือน + */ + @Get("{id}") + @Example({ + name: "string", //*ชื่อผัง + group: "string", //*กลุ่มผัง + isActive: "boolean", //*สถานะการใช้งาน + date: "datetime", //ให้ไว้ ณ วันที่ + startDate: "datetime", //วันที่มีผลบังคับใช้ + endDate: "datetime", //วันที่สิ้นสุดบังคับใช้ + detail: "string", //คำอธิบาย + }) + async GetSalaryById(@Path() id: string) { + const salary = await this.salaryEmployeeRepository.findOne({ + where: { id: id }, + select: ["name", "group", "isActive", "date", "startDate", "endDate", "details"], + }); + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); + } + return new HttpSuccess(salary); + } + + /** + * API รายการผังเงินเดือนลูกจ้าง + * + * + */ + @Get() + async listSalary( + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + ) { + const [salary, total] = await this.salaryEmployeeRepository.findAndCount({ + order: { + isActive: "DESC", + group: "ASC", + }, + ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), + }); + if (keyword != undefined && keyword !== "") { + const filteredSalary = salary.filter( + (x) => + x.name?.toString().includes(keyword) || + x.group?.toString().includes(keyword) || + x.isActive?.toString().includes(keyword) || + x.date?.toString().includes(keyword) || + x.startDate?.toString().includes(keyword) || + x.endDate?.toString().includes(keyword) || + x.details?.toString().includes(keyword), + ); + + const formattedData = filteredSalary.map((item) => ({ + id: item.id, + name: item.name, + group: item.group, + isActive: item.isActive, + date: item.date, + startDate: item.startDate, + endDate: item.endDate, + details: item.details, + })); + const slicedData = formattedData.slice((page - 1) * pageSize, page * pageSize); + return new HttpSuccess({ data: slicedData, total: formattedData.length }); + } + + const formattedData = salary.map((item) => ({ + id: item.id, + name: item.name, + group: item.group, + isActive: item.isActive, + date: item.date, + startDate: item.startDate, + endDate: item.endDate, + details: item.details, + })); + return new HttpSuccess({ data: formattedData, total }); + } + + /** + * API copy ผังเงินเดือนลูกจ้าง + * + * + */ + @Post("copy") + async copySalary( + @Body() body: { id: string }, + @Request() request: { user: Record }, + ) { + const salary = await this.salaryEmployeeRepository.findOne({ + relations: ["salaryRankEmployees_"], + where: { id: body.id }, + }); + + if (!salary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); + } + + const salaryRank = await this.salaryRankEmployeeRepository.find({ + where: { salaryEmployeeId: salary?.id }, + }); + + const newSalary = { ...salary, id: randomUUID(), isActive: false }; + + await this.salaryEmployeeRepository.save(newSalary); + + await Promise.all( + salaryRank.map(async (v) => { + const newSalaryRank = { ...v, id: randomUUID() }; + await this.salaryRankEmployeeRepository.save(newSalaryRank); + }), + ); + + return new HttpSuccess({ id: newSalary.id }); + } +} diff --git a/src/controllers/SalaryRankController.ts b/src/controllers/SalaryRankController.ts index 0de9663..5b48ec4 100644 --- a/src/controllers/SalaryRankController.ts +++ b/src/controllers/SalaryRankController.ts @@ -19,7 +19,6 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { CreateSalaryRank, SalaryRanks, UpdateSalaryRank } from "../entities/SalaryRanks"; -import { Not } from "typeorm"; import { Salarys } from "../entities/Salarys"; @Route("api/v1/salary/rate") @Tags("SalaryRank") @@ -50,10 +49,7 @@ export class SalaryRanksController extends Controller { where: { id: requestBody.salaryId }, }); if (!checkSalary) { - throw new HttpError( - HttpStatusCode.NOT_FOUND, - "ไม่พบข้อมูลผังเงินเดือนนี้" - ); + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); } const salaryRank = Object.assign(new SalaryRanks(), requestBody); salaryRank.createdUserId = request.user.sub; @@ -81,7 +77,6 @@ export class SalaryRanksController extends Controller { requestBody: UpdateSalaryRank, @Request() request: { user: Record }, ) { - // try { const salaryRank = await this.salaryRankRepository.findOne({ where: { id: id } }); if (!salaryRank) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); @@ -91,9 +86,6 @@ export class SalaryRanksController extends Controller { this.salaryRankRepository.merge(salaryRank, requestBody); await this.salaryRankRepository.save(salaryRank); return new HttpSuccess(); - // } catch (error: any) { - // throw new Error(error); - // } } /** @@ -105,7 +97,6 @@ export class SalaryRanksController extends Controller { */ @Delete("{id}") async deleteSalaryRanks(@Path() id: string) { - // try { const delSalaryRanks = await this.salaryRankRepository.findOne({ where: { id }, }); @@ -114,34 +105,8 @@ export class SalaryRanksController extends Controller { } await this.salaryRankRepository.delete({ id: id }); return new HttpSuccess(); - // } catch (error: any) { - // throw new Error(error); - // } } - // /** - // * API รายละเอียดรายการอัตราเงินเดือน - // * - // * @summary ORG_059 - รายละเอียดรายการอัตราเงินเดือน (ADMIN) #65 - // * - // * @param {string} id Id อัตราเงินเดือน - // */ - // @Get("{id}") - // async detailSalaryRanks(@Path() id: string) { - // const salaryRank = await this.salaryRankRepository.findOne({ - // where: { id }, - // select: ["id"], - // }); - // if (!salaryRank) { - // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); - // } - // try { - // return new HttpSuccess(salaryRank); - // } catch (error) { - // return error; - // } - // } - /** * API รายการอัตราเงินเดือน * @@ -156,7 +121,6 @@ export class SalaryRanksController extends Controller { @Query("pageSize") pageSize: number = 10, @Query("keyword") keyword?: string, ) { - const [salaryRank, total] = await this.salaryRankRepository.findAndCount({ where: { salaryId: id, diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts new file mode 100644 index 0000000..8579ad0 --- /dev/null +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -0,0 +1,149 @@ +import { + Controller, + Post, + Put, + Delete, + Route, + Security, + Tags, + Body, + Path, + Request, + SuccessResponse, + Response, + Get, + Query, +} from "tsoa"; +import { AppDataSource } from "../database/data-source"; +import HttpSuccess from "../interfaces/http-success"; +import HttpStatusCode from "../interfaces/http-status"; +import HttpError from "../interfaces/http-error"; +import { + CreateSalaryRankEmployee, + SalaryRankEmployees, + UpdateSalaryRankEmployee, +} from "../entities/SalaryRankEmployees"; +import { Salarys } from "../entities/Salarys"; +@Route("api/v1/salary/rate") +@Tags("SalaryRankEmployee") +@Security("bearerAuth") +@Response( + HttpStatusCode.INTERNAL_SERVER_ERROR, + "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง", +) +@SuccessResponse(HttpStatusCode.OK, "สำเร็จ") +export class SalaryRankEmployeesController extends Controller { + private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); + private salaryRepository = AppDataSource.getRepository(Salarys); + + /** + * API สร้างอัตราเงินเดือนลูกจ้าง + * + * + */ + @Post() + async CreateSalaryRankEmployee( + @Body() + requestBody: CreateSalaryRankEmployee, + @Request() request: { user: Record }, + ) { + try { + const checkSalary = await this.salaryRepository.findOne({ + where: { id: requestBody.salaryEmployeeId }, + }); + if (!checkSalary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผังเงินเดือนนี้"); + } + const salaryRankEmployee = Object.assign(new SalaryRankEmployees(), requestBody); + salaryRankEmployee.createdUserId = request.user.sub; + salaryRankEmployee.createdFullName = request.user.name; + salaryRankEmployee.lastUpdateUserId = request.user.sub; + salaryRankEmployee.lastUpdateFullName = request.user.name; + await this.salaryRankEmployeeRepository.save(salaryRankEmployee); + return new HttpSuccess(); + } catch (error: any) { + throw new Error(error); + } + } + + /** + * API แก้ไขอัตราเงินเดือนลูกจ้าง + * + * + * @param {string} id Id อัตราเงินเดือน + */ + @Put("{id}") + async updateSalaryRankEmployees( + @Path() id: string, + @Body() + requestBody: UpdateSalaryRankEmployee, + @Request() request: { user: Record }, + ) { + const salaryRankEmployee = await this.salaryRankEmployeeRepository.findOne({ + where: { id: id }, + }); + if (!salaryRankEmployee) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); + } + salaryRankEmployee.lastUpdateUserId = request.user.sub; + salaryRankEmployee.lastUpdateFullName = request.user.name; + this.salaryRankEmployeeRepository.merge(salaryRankEmployee, requestBody); + await this.salaryRankEmployeeRepository.save(salaryRankEmployee); + return new HttpSuccess(); + } + + /** + * API ลบอัตราเงินเดือนลูกจ้าง + * + * + * @param {string} id Id อัตราเงินเดือน + */ + @Delete("{id}") + async deleteSalaryRankEmployees(@Path() id: string) { + const delSalaryRankEmployees = await this.salaryRankEmployeeRepository.findOne({ + where: { id }, + }); + if (!delSalaryRankEmployees) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับผังเงินเดือนนี้"); + } + await this.salaryRankEmployeeRepository.delete({ id: id }); + return new HttpSuccess(); + } + + /** + * API รายการอัตราเงินเดือนลูกจ้าง + * + * + * @param {string} id Id ผังเงินเดือน + */ + @Get("{id}") + async listSalaryRankEmployees( + @Path() id: string, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("keyword") keyword?: string, + ) { + const [salaryRankEmployee, total] = await this.salaryRankEmployeeRepository.findAndCount({ + where: { + salaryEmployeeId: id, + }, + select: ["id", "step", "salaryMounth", "salaryDay"], + order: { + step: "ASC", + }, + ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), + }); + if (keyword != undefined && keyword !== "") { + const filteredSalaryRankEmployee = salaryRankEmployee.filter( + (x) => + x.step?.toString().includes(keyword) || + x.salaryMounth?.toString().includes(keyword) || + x.salaryDay?.toString().includes(keyword), + ); + const slicedData = filteredSalaryRankEmployee.slice((page - 1) * pageSize, page * pageSize); + return new HttpSuccess({ data: slicedData, total: filteredSalaryRankEmployee.length }); + } + + return new HttpSuccess({ data: salaryRankEmployee, total }); + } +} diff --git a/src/entities/SalaryEmployees.ts b/src/entities/SalaryEmployees.ts new file mode 100644 index 0000000..1bfa7db --- /dev/null +++ b/src/entities/SalaryEmployees.ts @@ -0,0 +1,112 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { SalaryRanks } from "./SalaryRanks"; +import { PosType } from "./PosType"; +import { PosLevel } from "./PosLevel"; +import { SalaryRankEmployees } from "./SalaryRankEmployees"; + +@Entity("salaryEmployees") +export class SalaryEmployees extends EntityBase { + @Column({ + comment: "ชื่อผัง", + length: 255, + }) + name: string; + + @Column({ + length: 40, + comment: "กลุ่มบัญชีการจ้าง", + }) + group: string; + + @Column({ + comment: "สถานะการใช้งาน", + }) + isActive: boolean; + + @Column({ + nullable: true, + type: "datetime", + comment: "ให้ไว้ ณ วันที่", + default: null, + }) + date: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่มีผลบังคับใช้", + default: null, + }) + startDate: Date; + + @Column({ + nullable: true, + type: "datetime", + comment: "วันที่สิ้นสุดบังคับใช้", + default: null, + }) + endDate: Date; + + @Column({ + nullable: true, + comment: "คำอธิบาย", + length: 255, + default: null, + }) + details: string; + + @OneToMany( + () => SalaryRankEmployees, + (salaryRankEmployees) => salaryRankEmployees.salaryEmployees_, + ) + salaryRankEmployees_: SalaryRankEmployees[]; +} + +export class CreateSalaryEmployee { + @Column() + name: string; + + @Column() + group: string; + + @Column() + isActive: boolean; + + @Column() + date?: Date | null; + + @Column() + startDate?: Date | null; + + @Column() + endDate?: Date | null; + + @Column() + details?: string | null; +} + +export class UpdateSalaryEmployee { + @Column() + name: string; + + @Column() + group: string; + + @Column() + isActive: boolean; + + @Column() + date?: Date | null; + + @Column() + startDate?: Date | null; + + @Column() + endDate?: Date | null; + + @Column() + details?: string | null; +} + +// export type UpdateSalary = Partial ; diff --git a/src/entities/SalaryRankEmployees.ts b/src/entities/SalaryRankEmployees.ts new file mode 100644 index 0000000..d51c68e --- /dev/null +++ b/src/entities/SalaryRankEmployees.ts @@ -0,0 +1,66 @@ +import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { EntityBase } from "./base/Base"; +import { Salarys } from "./Salarys"; +import { SalaryEmployees } from "./SalaryEmployees"; + +@Entity("salaryRankEmployees") +export class SalaryRankEmployees extends EntityBase { + @Column({ + length: 40, + comment: "คีย์นอก(FK)ของตาราง salaryEmployee", + }) + salaryEmployeeId: string; + + @Column({ + type: "double", + comment: "ลำดับขั้น", + }) + step: number; + + @Column({ + nullable: true, + type: "double", + comment: "ค่าจ้างรายเดือน", + default: null, + }) + salaryMounth: number | null; + + @Column({ + nullable: true, + type: "double", + comment: "ค่าจ้างรายวัน", + default: null, + }) + salaryDay: number | null; + + @ManyToOne(() => SalaryEmployees, (salaryEmployees) => salaryEmployees.salaryRankEmployees_) + @JoinColumn({ name: "salaryEmployeeId" }) + salaryEmployees_: SalaryEmployees; +} + +export class CreateSalaryRankEmployee { + @Column("uuid") + salaryEmployeeId: string; + + @Column() + step: number; + + @Column() + salaryMounth?: number | null; + + @Column() + salaryDay?: number | null; +} + +export class UpdateSalaryRankEmployee { + @Column() + step: number; + + @Column() + salaryMounth?: number | null; + + @Column() + salaryDay?: number | null; +} + +// export type UpdateSalaryRank = Partial>>; diff --git a/src/migration/1710296971419-add_table_salaryEmployees.ts b/src/migration/1710296971419-add_table_salaryEmployees.ts new file mode 100644 index 0000000..24ecee2 --- /dev/null +++ b/src/migration/1710296971419-add_table_salaryEmployees.ts @@ -0,0 +1,80 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class AddTableSalaryEmployees1710296971419 implements MigrationInterface { + name = 'AddTableSalaryEmployees1710296971419' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`CREATE TABLE \`salaryEmployees\` (\`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\` varchar(40) NOT 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 \`salaryRankEmployees\` (\`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 'ลำดับขั้น', \`salaryMounth\` double NULL COMMENT 'ค่าจ้างรายเดือน', \`salaryDay\` double NULL COMMENT 'ค่าจ้างรายวัน', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` DROP FOREIGN KEY \`FK_b6c5dca80c76486ebcadf6a4dd9\``); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` CHANGE \`salaryId\` \`salaryId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salary'`); + await queryRunner.query(`ALTER TABLE \`posLevel\` DROP FOREIGN KEY \`FK_66caa3d974b67a8a8b343d029b2\``); + await queryRunner.query(`ALTER TABLE \`posLevel\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง posType'`); + await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_fa211557e2cbee0bb3bbef363f2\``); + await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_683719e5363cc977da591556731\``); + await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง posType'`); + await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`posLevelId\` \`posLevelId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง posLevel'`); + await queryRunner.query(`ALTER TABLE \`salaryPeriod\` CHANGE \`revisionId\` \`revisionId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgRevision'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` DROP FOREIGN KEY \`FK_7fd317035fe8d0e03dc2443cf36\``); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`salaryPeriodId\` \`salaryPeriodId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salaryPeriod'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`rootId\` \`rootId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง orgRoot'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`revisionId\` \`revisionId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgRevision'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP FOREIGN KEY \`FK_d925088feca62ab41c131a87914\``); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`salaryOrgId\` \`salaryOrgId\` varchar(40) NOT NULL COMMENT 'คีย์นอก(FK)ของตาราง salaryOrg'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`rootId\` \`rootId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgRoot'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`root\` \`root\` varchar(255) NULL COMMENT 'ชื่อของหน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child1Id\` \`child1Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgChild1'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child1\` \`child1\` varchar(255) NULL COMMENT 'ชื่อส่วนราชการ'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child2Id\` \`child2Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgChild2'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child2\` \`child2\` varchar(255) NULL COMMENT 'ชื่อส่วนราชการ'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child3Id\` \`child3Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgChild3'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child3\` \`child3\` varchar(255) NULL COMMENT 'ชื่อส่วนราชการ'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child4Id\` \`child4Id\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง orgChild4'`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child4\` \`child4\` varchar(255) NULL COMMENT 'ชื่อส่วนราชการ'`); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` ADD CONSTRAINT \`FK_b6c5dca80c76486ebcadf6a4dd9\` FOREIGN KEY (\`salaryId\`) REFERENCES \`salarys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posLevel\` ADD CONSTRAINT \`FK_66caa3d974b67a8a8b343d029b2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_fa211557e2cbee0bb3bbef363f2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_683719e5363cc977da591556731\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` ADD CONSTRAINT \`FK_7fd317035fe8d0e03dc2443cf36\` FOREIGN KEY (\`salaryPeriodId\`) REFERENCES \`salaryPeriod\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD CONSTRAINT \`FK_d925088feca62ab41c131a87914\` FOREIGN KEY (\`salaryOrgId\`) REFERENCES \`salaryOrg\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryRankEmployees\` ADD CONSTRAINT \`FK_34faa444506fac48ba76ab1e8b0\` FOREIGN KEY (\`salaryEmployeeId\`) REFERENCES \`salaryEmployees\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryRankEmployees\` DROP FOREIGN KEY \`FK_34faa444506fac48ba76ab1e8b0\``); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` DROP FOREIGN KEY \`FK_d925088feca62ab41c131a87914\``); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` DROP FOREIGN KEY \`FK_7fd317035fe8d0e03dc2443cf36\``); + await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_683719e5363cc977da591556731\``); + await queryRunner.query(`ALTER TABLE \`salarys\` DROP FOREIGN KEY \`FK_fa211557e2cbee0bb3bbef363f2\``); + await queryRunner.query(`ALTER TABLE \`posLevel\` DROP FOREIGN KEY \`FK_66caa3d974b67a8a8b343d029b2\``); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` DROP FOREIGN KEY \`FK_b6c5dca80c76486ebcadf6a4dd9\``); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child4\` \`child4\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child4Id\` \`child4Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child3\` \`child3\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child3Id\` \`child3Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child2\` \`child2\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child2Id\` \`child2Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child1\` \`child1\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`child1Id\` \`child1Id\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`root\` \`root\` varchar(255) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`rootId\` \`rootId\` varchar(40) NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` CHANGE \`salaryOrgId\` \`salaryOrgId\` varchar(40) NOT NULL`); + await queryRunner.query(`ALTER TABLE \`salaryProfile\` ADD CONSTRAINT \`FK_d925088feca62ab41c131a87914\` FOREIGN KEY (\`salaryOrgId\`) REFERENCES \`salaryOrg\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`revisionId\` \`revisionId\` varchar(40) NULL COMMENT 'id revision'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`rootId\` \`rootId\` varchar(40) NOT NULL COMMENT 'id หน่วยงาน'`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` CHANGE \`salaryPeriodId\` \`salaryPeriodId\` varchar(40) NOT NULL`); + await queryRunner.query(`ALTER TABLE \`salaryOrg\` ADD CONSTRAINT \`FK_7fd317035fe8d0e03dc2443cf36\` FOREIGN KEY (\`salaryPeriodId\`) REFERENCES \`salaryPeriod\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryPeriod\` CHANGE \`revisionId\` \`revisionId\` varchar(40) NULL COMMENT 'id revision'`); + await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`posLevelId\` \`posLevelId\` varchar(40) NOT NULL COMMENT 'Id ระดับของตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`salarys\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NOT NULL COMMENT 'Id ประเภทของตำแหน่ง'`); + await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_683719e5363cc977da591556731\` FOREIGN KEY (\`posLevelId\`) REFERENCES \`posLevel\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salarys\` ADD CONSTRAINT \`FK_fa211557e2cbee0bb3bbef363f2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`posLevel\` CHANGE \`posTypeId\` \`posTypeId\` varchar(40) NOT NULL COMMENT 'เป็นระดับของประเภทตำแหน่งใด'`); + await queryRunner.query(`ALTER TABLE \`posLevel\` ADD CONSTRAINT \`FK_66caa3d974b67a8a8b343d029b2\` FOREIGN KEY (\`posTypeId\`) REFERENCES \`posType\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` CHANGE \`salaryId\` \`salaryId\` varchar(40) NOT NULL COMMENT 'Id ผังเงินเดือน'`); + await queryRunner.query(`ALTER TABLE \`salaryRanks\` ADD CONSTRAINT \`FK_b6c5dca80c76486ebcadf6a4dd9\` FOREIGN KEY (\`salaryId\`) REFERENCES \`salarys\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`); + await queryRunner.query(`DROP TABLE \`salaryRankEmployees\``); + await queryRunner.query(`DROP TABLE \`salaryEmployees\``); + } + +} From cf44eb68c9d494c82ecf2dd64c4886b273e02fb6 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 09:33:34 +0700 Subject: [PATCH 2/6] =?UTF-8?q?=E0=B9=80=E0=B8=9E=E0=B8=B4=E0=B9=88?= =?UTF-8?q?=E0=B8=A1path=E0=B8=9C=E0=B8=B1=E0=B8=87=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 | 2 +- src/controllers/SalaryRankEmployeeController.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index 2d722e0..5a72c72 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -26,7 +26,7 @@ import HttpStatusCode from "../interfaces/http-status"; import { SalaryRankEmployees } from "../entities/SalaryRankEmployees"; import { randomUUID } from "crypto"; -@Route("api/v1/salary") +@Route("api/v1/salary/employee") @Tags("Salary") @Security("bearerAuth") export class Salary extends Controller { diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts index 8579ad0..6cfa146 100644 --- a/src/controllers/SalaryRankEmployeeController.ts +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -24,7 +24,7 @@ import { UpdateSalaryRankEmployee, } from "../entities/SalaryRankEmployees"; import { Salarys } from "../entities/Salarys"; -@Route("api/v1/salary/rate") +@Route("api/v1/salary/rate/employee") @Tags("SalaryRankEmployee") @Security("bearerAuth") @Response( From 3128103f3aa6747a7994f7ad22b0152b25e0f15a Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 09:52:05 +0700 Subject: [PATCH 3/6] no message --- src/controllers/SalaryController.ts | 2 +- src/controllers/SalaryEmployeeController.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 6b7f500..356b88f 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -27,7 +27,7 @@ import { randomUUID } from "crypto"; @Route("api/v1/salary") @Tags("Salary") @Security("bearerAuth") -export class Salary extends Controller { +export class SalaryController extends Controller { private salaryRepository = AppDataSource.getRepository(Salarys); private salaryRankRepository = AppDataSource.getRepository(SalaryRanks); private poTypeRepository = AppDataSource.getRepository(PosType); diff --git a/src/controllers/SalaryEmployeeController.ts b/src/controllers/SalaryEmployeeController.ts index 5a72c72..d2beea6 100644 --- a/src/controllers/SalaryEmployeeController.ts +++ b/src/controllers/SalaryEmployeeController.ts @@ -27,9 +27,9 @@ import { SalaryRankEmployees } from "../entities/SalaryRankEmployees"; import { randomUUID } from "crypto"; @Route("api/v1/salary/employee") -@Tags("Salary") +@Tags("SalaryEmployee") @Security("bearerAuth") -export class Salary extends Controller { +export class SalaryEmployeeController extends Controller { private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployees); private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); From 5fc5b1bb0658fefc28f09d4f2fc8fe3270f616be Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 11:25:07 +0700 Subject: [PATCH 4/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=8A?= =?UTF-8?q?=E0=B8=B7=E0=B9=88=E0=B8=AD=E0=B8=9F=E0=B8=B4=E0=B8=A7=E0=B8=9C?= =?UTF-8?q?=E0=B8=B1=E0=B8=87=E0=B9=80=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80?= =?UTF-8?q?=E0=B8=94=E0=B8=B7=E0=B8=AD=E0=B8=99=E0=B8=A5=E0=B8=B9=E0=B8=81?= =?UTF-8?q?=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 --- .../SalaryRankEmployeeController.ts | 4 ++-- src/entities/SalaryEmployees.ts | 14 ++++++------- src/entities/SalaryRankEmployees.ts | 9 ++++----- src/entities/SalaryRanks.ts | 2 +- src/entities/Salarys.ts | 2 +- ...-update_type_step_table_SalaryEmployees.ts | 20 +++++++++++++++++++ ...update_type_step_table_SalaryEmployees1.ts | 14 +++++++++++++ 7 files changed, 48 insertions(+), 17 deletions(-) create mode 100644 src/migration/1710302516943-update_type_step_table_SalaryEmployees.ts create mode 100644 src/migration/1710302798280-update_type_step_table_SalaryEmployees1.ts diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts index 6cfa146..829bfd7 100644 --- a/src/controllers/SalaryRankEmployeeController.ts +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -127,7 +127,7 @@ export class SalaryRankEmployeesController extends Controller { where: { salaryEmployeeId: id, }, - select: ["id", "step", "salaryMounth", "salaryDay"], + select: ["id", "step", "salaryMonth", "salaryDay"], order: { step: "ASC", }, @@ -137,7 +137,7 @@ export class SalaryRankEmployeesController extends Controller { const filteredSalaryRankEmployee = salaryRankEmployee.filter( (x) => x.step?.toString().includes(keyword) || - x.salaryMounth?.toString().includes(keyword) || + x.salaryMonth?.toString().includes(keyword) || x.salaryDay?.toString().includes(keyword), ); const slicedData = filteredSalaryRankEmployee.slice((page - 1) * pageSize, page * pageSize); diff --git a/src/entities/SalaryEmployees.ts b/src/entities/SalaryEmployees.ts index 1bfa7db..7e0bd1a 100644 --- a/src/entities/SalaryEmployees.ts +++ b/src/entities/SalaryEmployees.ts @@ -1,8 +1,5 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { Entity, Column, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; -import { SalaryRanks } from "./SalaryRanks"; -import { PosType } from "./PosType"; -import { PosLevel } from "./PosLevel"; import { SalaryRankEmployees } from "./SalaryRankEmployees"; @Entity("salaryEmployees") @@ -14,10 +11,11 @@ export class SalaryEmployees extends EntityBase { name: string; @Column({ - length: 40, + nullable: true, comment: "กลุ่มบัญชีการจ้าง", + default: null, }) - group: string; + group: number; @Column({ comment: "สถานะการใช้งาน", @@ -68,7 +66,7 @@ export class CreateSalaryEmployee { name: string; @Column() - group: string; + group: number; @Column() isActive: boolean; @@ -91,7 +89,7 @@ export class UpdateSalaryEmployee { name: string; @Column() - group: string; + group: number; @Column() isActive: boolean; diff --git a/src/entities/SalaryRankEmployees.ts b/src/entities/SalaryRankEmployees.ts index d51c68e..0dbdcd0 100644 --- a/src/entities/SalaryRankEmployees.ts +++ b/src/entities/SalaryRankEmployees.ts @@ -1,6 +1,5 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; -import { Salarys } from "./Salarys"; import { SalaryEmployees } from "./SalaryEmployees"; @Entity("salaryRankEmployees") @@ -23,7 +22,7 @@ export class SalaryRankEmployees extends EntityBase { comment: "ค่าจ้างรายเดือน", default: null, }) - salaryMounth: number | null; + salaryMonth: number | null; @Column({ nullable: true, @@ -46,7 +45,7 @@ export class CreateSalaryRankEmployee { step: number; @Column() - salaryMounth?: number | null; + salaryMonth?: number | null; @Column() salaryDay?: number | null; @@ -57,7 +56,7 @@ export class UpdateSalaryRankEmployee { step: number; @Column() - salaryMounth?: number | null; + salaryMonth?: number | null; @Column() salaryDay?: number | null; diff --git a/src/entities/SalaryRanks.ts b/src/entities/SalaryRanks.ts index 41998fa..f8ae6ed 100644 --- a/src/entities/SalaryRanks.ts +++ b/src/entities/SalaryRanks.ts @@ -1,4 +1,4 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn } from "typeorm"; import { EntityBase } from "./base/Base"; import { Salarys } from "./Salarys"; diff --git a/src/entities/Salarys.ts b/src/entities/Salarys.ts index b8a3588..c1bb48f 100644 --- a/src/entities/Salarys.ts +++ b/src/entities/Salarys.ts @@ -1,4 +1,4 @@ -import { Entity, Column, ManyToOne, JoinColumn, OneToOne, OneToMany } from "typeorm"; +import { Entity, Column, ManyToOne, JoinColumn, OneToMany } from "typeorm"; import { EntityBase } from "./base/Base"; import { SalaryRanks } from "./SalaryRanks"; import { PosType } from "./PosType"; diff --git a/src/migration/1710302516943-update_type_step_table_SalaryEmployees.ts b/src/migration/1710302516943-update_type_step_table_SalaryEmployees.ts new file mode 100644 index 0000000..1f280d6 --- /dev/null +++ b/src/migration/1710302516943-update_type_step_table_SalaryEmployees.ts @@ -0,0 +1,20 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTypeStepTableSalaryEmployees1710302516943 implements MigrationInterface { + name = 'UpdateTypeStepTableSalaryEmployees1710302516943' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` CHANGE \`group\` \`step\` varchar(40) NOT NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + await queryRunner.query(`ALTER TABLE \`salaryRankEmployees\` CHANGE \`salaryMounth\` \`salaryMonth\` double NULL COMMENT 'ค่าจ้างรายเดือน'`); + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` DROP COLUMN \`step\``); + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` ADD \`step\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` DROP COLUMN \`step\``); + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` ADD \`step\` varchar(40) NOT NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + await queryRunner.query(`ALTER TABLE \`salaryRankEmployees\` CHANGE \`salaryMonth\` \`salaryMounth\` double NULL COMMENT 'ค่าจ้างรายเดือน'`); + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` CHANGE \`step\` \`group\` varchar(40) NOT NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + } + +} diff --git a/src/migration/1710302798280-update_type_step_table_SalaryEmployees1.ts b/src/migration/1710302798280-update_type_step_table_SalaryEmployees1.ts new file mode 100644 index 0000000..a2eb874 --- /dev/null +++ b/src/migration/1710302798280-update_type_step_table_SalaryEmployees1.ts @@ -0,0 +1,14 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class UpdateTypeStepTableSalaryEmployees11710302798280 implements MigrationInterface { + name = 'UpdateTypeStepTableSalaryEmployees11710302798280' + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` CHANGE \`step\` \`group\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`ALTER TABLE \`salaryEmployees\` CHANGE \`group\` \`step\` int NULL COMMENT 'กลุ่มบัญชีการจ้าง'`); + } + +} From c124a05561947750728ceb53a269b928cfba8ca8 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 12:02:43 +0700 Subject: [PATCH 5/6] =?UTF-8?q?=E0=B8=AD=E0=B8=B1=E0=B8=9E=E0=B9=84?= =?UTF-8?q?=E0=B8=9F=E0=B8=A5=E0=B9=8C=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88?= =?UTF-8?q?=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/StorageEmployeeController.ts | 287 +++++++++++++++++++ 1 file changed, 287 insertions(+) create mode 100644 src/controllers/StorageEmployeeController.ts diff --git a/src/controllers/StorageEmployeeController.ts b/src/controllers/StorageEmployeeController.ts new file mode 100644 index 0000000..ec08bca --- /dev/null +++ b/src/controllers/StorageEmployeeController.ts @@ -0,0 +1,287 @@ +import { + Body, + Controller, + Delete, + Example, + Get, + Patch, + Path, + Post, + Route, + Security, + SuccessResponse, + Tags, +} from "tsoa"; +import HttpStatus from "../interfaces/http-status"; +import { + createFile, + createFolder, + deleteFile, + deleteFolder, + downloadFile, + listFile, + updateFile, +} from "../services/edm"; + +@Route("api/v1/salary/file/employee") +@Security("bearerAuth") +@Tags("Document") +export class DocumentEmployeeController extends Controller { + /** + * @example id "00000000-0000-0000-0000-000000000000" + * + * @summary รายการเอกสารอ้างอิงผังเงินเดือน + */ + @Get("{id}") + @SuccessResponse(200, "สำเร็จ") + @Example([ + { + pathname: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000/เอกสาร 1.docx", + path: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000", + title: "เอกสาร 1", + description: "", + author: "นายก", + metadata: { tag: 1 }, + keyword: [], + category: [], + fileName: "เอกสาร 1.docx", + fileType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + fileSize: 1024, + upload: true, + createdAt: "2021-07-20T12:33:13.018Z", + createdBy: "service-account-ext-api", + updatedAt: "2021-07-20T12:33:13.018Z", + updatedBy: "service-account-ext-api", + }, + ]) + public async getFile(@Path() id: string) { + const list = await listFile(["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน", id]); + if (!list) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์"); + return list; + } + + /** + * ข้อควรระวัง: หากลิงก์ยาวเกินไปอาจทำให้ไม่สามารถอัปโหลดได้ + * + * @example id "00000000-0000-0000-0000-000000000000" + * @example file "เอกสาร 1.docx" + * + * @summary ข้อมูลเอกสารพร้อมลิงก์ดาวน์โหลด + */ + @Get("/{id}/{file}") + @SuccessResponse(200, "สำเร็จ") + @Example({ + pathname: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000/เอกสาร 1.docx", + path: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000", + title: "เอกสาร 1", + description: "", + author: "นายก", + keyword: [], + category: [], + metadata: { tag: 1 }, + fileName: "เอกสาร 1.docx", + fileType: "application/vnd.openxmlformats-officedocument.wordprocessingml.document", + fileSize: 1024, + hidden: false, + upload: true, + createdAt: "2021-07-20T12:33:13.018Z", + createdBy: "service-account-ext-api", + updatedAt: "2021-07-20T12:33:13.018Z", + updatedBy: "service-account-ext-api", + downloadUrl: "https://.../...", // Presigned Download URL 7 Days Exp + }) + public async getFileDownload(@Path() id: string, @Path() file: string) { + const data = await downloadFile( + ["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน", id], + file, + ); + if (!data) throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์"); + return data; + } + + /** + * ข้อควรระวัง: หากลิงก์ภาษาไทยยาวเกินไปอาจทำให้ไม่สามารถอัปโหลดได้ (น่าจะเป็นปัญหาทางด้านเทคนิคของ DNS) + * + * เมื่ออัปโหลดไฟล์โดย PUT Method จำเป็นต้องแนบ Content-Type ที่ถูกต้องของไฟล์ไปด้วยเพื่อให้ระบบรู้จักไฟล์นั้นๆ + * โดย Content-Type จะเป็น mime-type เช่น docx เป็น application/vnd.openxmlformats-officedocument.wordprocessingml.document + * ทั้งนี้ Content-Type อาจจะต่างกันแม้นามสกุลจะเหมือนกันได้ + * + * โดยปกติเมื่อเลือกไฟล์แล้ว Browser จะเก็บประเภทของไฟล์ไว้ด้วย ซึ่งเป็น Object ของ File มี attribute ชื่อ type ซึ่งเก็บ mime-type ไว้ + * + * หากไม่มีการป้อนชื่อ title ระบบ EDM จะใช้ title เป็นชื่อเดียวกับ ชื่อไฟล์โดยอัตโนมัติ + * + * @example id "00000000-0000-0000-0000-000000000000" + * + * @summary SLR_013 - เพิ่มเอกสารอ้างอิงผังเงินเดือน + */ + @Post("{id}") + @Example([ + { + pathname: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000/เอกสาร 1.docx", + path: "ระบบเงินเดือนลูกจ้าง/00000000-0000-0000-0000-000000000000", + title: "เอกสาร 1", + description: "", + author: "นายก", + keyword: [], + category: [], + metadata: { + tag: 1, + }, + fileName: "เอกสาร 1.docx", + fileSize: 0, + fileType: "", + hidden: false, + upload: false, + createdAt: "2021-07-20T12:33:13.018Z", + createdBy: "service-account-ext-api", + updatedAt: "2021-07-20T12:33:13.018Z", + updatedBy: "service-account-ext-api", + uploadUrl: "https://.../...", // Presigned Upload URL 7 Days Exp + }, + ]) + @SuccessResponse(200, "Success") + public async uploadFile( + @Path() id: string, + @Body() + body: { + /** + * @example [ + * { "fileName": "เอกสาร 1.docx" }, + * { "fileName": "เอกสาร 2.docx", "title": "เอกสาร 2" } + * ] + */ + fileList: { + fileName: string; + title?: string; + description?: string; + keyword?: string[]; + category?: string[]; + author?: string; + metadata?: { + [key: string]: unknown; + }; + }[]; + /** + * @example false + */ + replace?: boolean; + }, + ) { + const path = ["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน", id]; + + if (!(await createFolder(path.slice(0, -1), id, true))) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถสร้างแฟ้มได้"); + } + + const list = await listFile(path); + + if (!list || !Array.isArray(list)) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ เข้าถึงรายการไฟล์ได้"); + } + + let used: string[] = []; + + let fileList = !body.replace + ? body.fileList.map(({ fileName, ...props }) => { + const dotIndex = fileName.lastIndexOf("."); + const originalName = + dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(0, dotIndex) : fileName; + const extension = + dotIndex !== -1 && !fileName.startsWith(".") ? fileName.slice(dotIndex) : ""; + + let i = 1; + while (list.findIndex((v) => v.fileName === fileName) !== -1 || used.includes(fileName)) { + fileName = `${originalName} (${i++})`; + if (dotIndex !== -1) fileName += extension; + } + + props.author = "ไม่พบข้อมูล"; + + used.push(fileName); + + return { fileName: fileName, ...props }; + }) + : body.fileList; + + const map = fileList.map(async ({ fileName, ...props }) => [ + fileName, + await createFile(path, fileName, props), + ]); + + const result = await Promise.all(map).catch((e) => + console.error(`Storage Service Error: ${e}`), + ); + + if (!result || result.some((v) => !v[1])) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถอัปโหลดไฟล์ได้"); + } + + return Object.fromEntries(result); + } + /** + * @example id "00000000-0000-0000-0000-000000000000" + * @example file "เอกสาร 1.docx" + * + * @summary แก้ไขข้อมูลไฟล์ของ id นั้นๆ + */ + @Patch("{id}/{file}") + public async updateFile( + @Path() id: string, + @Path() file: string, + @Body() + body: { + title?: string; + description?: string; + keyword?: string[]; + category?: string[]; + author?: string; + metadata?: { [key: string]: unknown }; + }, + ) { + const props = body; + const result = await updateFile( + ["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน", id], + file, + props, + ); + + if (!result) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถแก้ไขไฟล์ได้"); + } + return this.setStatus(HttpStatus.NO_CONTENT); + } + + /** + * @example id "00000000-0000-0000-0000-000000000000" + * + * @summary ลบไฟล์ทั้งหมดของ id นั้นๆ + */ + @Delete("{id}") + public async deleteFolder(@Path() id: string) { + const result = await deleteFolder(["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน"], id); + + if (!result) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถลบแฟ้มได้"); + } + return this.setStatus(HttpStatus.NO_CONTENT); + } + + /** + * @example id "00000000-0000-0000-0000-000000000000" + * @example file "เอกสาร 1.docx" + * + * @summary SLR_014 - ลบเอกสารอ้างอิงผังเงินเดือน + */ + @Delete("{id}/{file}") + public async deleteFile(@Path() id: string, @Path() file: string) { + const result = await deleteFile( + ["ระบบเงินเดือนลูกจ้าง", "เอกสารอ้างอิงผังเงินเดือน", id], + file, + ); + + if (!result) { + throw new Error("เกิดข้อผิดพลาดกับระบบจัดการไฟล์ ไม่สามารถลบไฟล์ ได้"); + } + return this.setStatus(HttpStatus.NO_CONTENT); + } +} From 9fa5e03d248696133bc9c4b7481bdb52252e20c8 Mon Sep 17 00:00:00 2001 From: Kittapath Date: Wed, 13 Mar 2024 13:45:57 +0700 Subject: [PATCH 6/6] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B9=80?= =?UTF-8?q?=E0=B8=8A=E0=B9=87=E0=B8=84=E0=B8=AD=E0=B8=B1=E0=B8=88=E0=B8=A3?= =?UTF-8?q?=E0=B8=B2=E0=B9=83=E0=B8=99=E0=B8=9C=E0=B8=B1=E0=B8=87=E0=B9=80?= =?UTF-8?q?=E0=B8=87=E0=B8=B4=E0=B8=99=E0=B9=80=E0=B8=94=E0=B8=B7=E0=B8=AD?= =?UTF-8?q?=E0=B8=99=E0=B8=A5=E0=B8=B9=E0=B8=81=E0=B8=88=E0=B9=89=E0=B8=B2?= =?UTF-8?q?=E0=B8=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/SalaryRankEmployeeController.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/controllers/SalaryRankEmployeeController.ts b/src/controllers/SalaryRankEmployeeController.ts index 829bfd7..cbd5535 100644 --- a/src/controllers/SalaryRankEmployeeController.ts +++ b/src/controllers/SalaryRankEmployeeController.ts @@ -23,7 +23,7 @@ import { SalaryRankEmployees, UpdateSalaryRankEmployee, } from "../entities/SalaryRankEmployees"; -import { Salarys } from "../entities/Salarys"; +import { SalaryEmployees } from "../entities/SalaryEmployees"; @Route("api/v1/salary/rate/employee") @Tags("SalaryRankEmployee") @Security("bearerAuth") @@ -34,7 +34,7 @@ import { Salarys } from "../entities/Salarys"; @SuccessResponse(HttpStatusCode.OK, "สำเร็จ") export class SalaryRankEmployeesController extends Controller { private salaryRankEmployeeRepository = AppDataSource.getRepository(SalaryRankEmployees); - private salaryRepository = AppDataSource.getRepository(Salarys); + private salaryEmployeeRepository = AppDataSource.getRepository(SalaryEmployees); /** * API สร้างอัตราเงินเดือนลูกจ้าง @@ -48,7 +48,7 @@ export class SalaryRankEmployeesController extends Controller { @Request() request: { user: Record }, ) { try { - const checkSalary = await this.salaryRepository.findOne({ + const checkSalary = await this.salaryEmployeeRepository.findOne({ where: { id: requestBody.salaryEmployeeId }, }); if (!checkSalary) {