This commit is contained in:
AdisakKanthawilang 2024-02-16 16:15:53 +07:00
parent 6740cf5dd8
commit 4663ff3504
3 changed files with 37 additions and 63 deletions

View file

@ -18,12 +18,13 @@ 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";
import { randomUUID } from "crypto";
@Route("api/v1/salary")
@Tags("Salary")
@ -260,7 +261,7 @@ export class Salary extends Controller {
return error;
}
}
/**
* API
*
@ -335,63 +336,41 @@ export class Salary extends Controller {
}
}
// /**
// * API copy ผังเงินเดือน
// *
// * @summary SLR_008 - copy ผังเงินเดือน #8
// *
// */
// @Post("copy")
// async copySalary(
// @Body() body: { id: string },
// @Request() request: { user: Record<string, any> }
// ) {
// const salary = await this.salaryRepository.findOne({
// relations: ["posLevel_", "posType_", "salaryRanks_"],
// where:{id:body.id}
// });
/**
* API copy
*
* @summary SLR_008 - copy #8
*
*/
@Post("copy")
async copySalary(
@Body() body: { id: string },
@Request() request: { user: Record<string, any> },
) {
const salary = await this.salaryRepository.findOne({
relations: ["posLevel_", "posType_", "salaryRanks_"],
where: { id: body.id },
});
// if(!salary){
// throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id)
// }
if (!salary) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเงินเดือนจากไอดีนี้ : " + body.id);
}
// const salaryRank = await this.salaryRankRepository.find({
// where:{salaryId:salary?.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
// newSalary.createdUserId = request.user.sub,
// newSalary.createdFullName = request.user.name,
// newSalary.createdAt = new Date(),
// newSalary.lastUpdateUserId = request.user.sub,
// newSalary.lastUpdateFullName = request.user.name,
// newSalary.lastUpdatedAt = new Date(),
// await this.salaryRepository.save(newSalary);
const newSalary = { ...salary, id: randomUUID() };
// const newRanks = salary.salaryRanks_.map((rank) => {
// newRanks.forEach(async (x: any) => {
// var dataId = x.id;
// delete x.id;
// const data = Object.assign(new SalaryRanks(), x);
// data.salaryId = newSalary.id,
// data.createdUserId = request.user.sub,
// data.createdFullName = request.user.name,
// data.createdAt = new Date(),
// data.lastUpdateUserId = request.user.sub,
// data.lastUpdateFullName = request.user.name,
// data.lastUpdatedAt = new Date(),
// await this.salaryRankRepository.save(data);
// });
// });
// return new HttpSuccess({ id: newSalary.id });
// } catch (error) {
// return error;
// }
// }
await this.salaryRepository.save(newSalary);
await Promise.all(
salaryRank.map(async (v) => {
const newSalaryRank = { ...v, id: randomUUID() };
await this.salaryRankRepository.save(newSalaryRank);
}),
);
return new HttpSuccess({ id: newSalary.id });
}
}

View file

@ -23,7 +23,7 @@ import {
import { Salarys } from "../entities/Salarys";
@Route("api/v1/salary/rate")
@Tags("SalaryRank")
// @Security("bearerAuth")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",