diff --git a/src/controllers/SalaryController.ts b/src/controllers/SalaryController.ts index 1f0d748..0405c4f 100644 --- a/src/controllers/SalaryController.ts +++ b/src/controllers/SalaryController.ts @@ -18,16 +18,19 @@ import { Salarys, CreateSalary, UpdateSalary } from "../entities/Salarys"; import { PosType } from "../entities/PosType"; import { PosLevel } from "../entities/PosLevel"; import { AppDataSource } from "../database/data-source"; -import { In, IsNull, Not } from "typeorm"; +import { In, IsNull, 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"; @Route("api/v1/salary") @Tags("Salary") @Security("bearerAuth") export class Salary extends Controller { private salaryRepository = AppDataSource.getRepository(Salarys); + private salaryRankRepository = AppDataSource.getRepository(SalaryRanks); private poTypeRepository = AppDataSource.getRepository(PosType); private posLevelRepository = AppDataSource.getRepository(PosLevel); @@ -294,7 +297,9 @@ export class Salary extends Controller { const formattedData = filteredSalary.map((item) => ({ id: item.id, salaryType: item.salaryType, + posTypeId: item.posType_?.id, posType: item.posType_?.posTypeName, + posLevelId: item.posLevel_?.id, posLevel: item.posLevel_?.posLevelName, isActive: item.isActive, date: item.date, @@ -313,7 +318,9 @@ export class Salary extends Controller { const formattedData = salary.map((item) => ({ id: item.id, salaryType: item.salaryType, + posTypeId: item.posType_?.id, posType: item.posType_?.posTypeName, + posLevelId: item.posLevel_?.id, posLevel: item.posLevel_?.posLevelName, isActive: item.isActive, date: item.date, @@ -327,4 +334,49 @@ export class Salary extends Controller { return error; } } + + // /** + // * API copy ผังเงินเดือน + // * + // * @summary SLR_008 - copy ผังเงินเดือน #8 + // * + // */ + // @Post("copy") + // async copySalary(@Body() body: { id: string }) { + // const salary = await this.salaryRepository.findOne({ + // relations: ["posLevel_", "posType_", "salaryRanks_"], + // where:{id:body.id} + // }); + + // if(!salary){ + // throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id) + // } + + // const salaryRank = await this.salaryRankRepository.find({ + // where:{salaryId:salary?.id} + // }); + + // try { + // const newSalary = new Salarys(); + // newSalary.isActive = false; + // newSalary.salaryType = salary.salaryType; + // newSalary.posTypeId = salary.posTypeId + // newSalary.posLevelId = salary.posLevelId + // await this.salaryRepository.save(newSalary); + + // const newRanks = salary.salaryRanks_.map((rank) => { + // const newRank = this.salaryRankRepository.create({ + // ...rank, // เก็บทุก property จาก rank + // salaryId: newSalary.id, + // }); + // return newRank; + // }); + + // await this.salaryRankRepository.save(newRanks); + + // return new HttpSuccess({ id: newSalary.id }); + // } catch (error) { + // return error; + // } + // } }