diff --git a/src/controllers/CommandController.ts b/src/controllers/CommandController.ts index 714a4247..76351837 100644 --- a/src/controllers/CommandController.ts +++ b/src/controllers/CommandController.ts @@ -19,13 +19,16 @@ import HttpSuccess from "../interfaces/http-success"; import HttpStatusCode from "../interfaces/http-status"; import HttpError from "../interfaces/http-error"; import { Command } from "../entities/Command"; -import { Brackets } from "typeorm"; +import { Brackets, LessThan, MoreThan } from "typeorm"; import { CommandType } from "../entities/CommandType"; import { CommandSend } from "../entities/CommandSend"; import { Profile } from "../entities/Profile"; import { RequestWithUser } from "../middlewares/user"; import { OrgRevision } from "../entities/OrgRevision"; import { CommandSendCC } from "../entities/CommandSendCC"; +import { CommandSalary } from "../entities/CommandSalary"; +import { CommandRecive } from "../entities/CommandRecive"; +import HttpStatus from "../interfaces/http-status"; @Route("api/v1/org/command") @Tags("Command") @@ -40,6 +43,8 @@ export class CommandController extends Controller { private commandTypeRepository = AppDataSource.getRepository(CommandType); private commandSendRepository = AppDataSource.getRepository(CommandSend); private commandSendCCRepository = AppDataSource.getRepository(CommandSendCC); + private commandSalaryRepository = AppDataSource.getRepository(CommandSalary); + private commandReciveRepository = AppDataSource.getRepository(CommandRecive); private profileRepository = AppDataSource.getRepository(Profile); private orgRevisionRepo = AppDataSource.getRepository(OrgRevision); @@ -282,14 +287,8 @@ export class CommandController extends Controller { @Path() id: string, @Body() requestBody: { - commandNo: string | null; - commandYear: number | null; - issue: string | null; - detailHeader: string | null; - detailBody: string | null; - detailFooter: string | null; - commandAffectDate: Date | null; - commandExcecuteDate: Date | null; + positionDetail: string | null; + commandSalaryId: string | null; }, @Request() request: RequestWithUser, ) { @@ -297,6 +296,14 @@ export class CommandController extends Controller { if (!command) { throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้"); } + if (requestBody.commandSalaryId != undefined && requestBody.commandSalaryId != null) { + const commandSalary = await this.commandSalaryRepository.findOne({ + where: { id: requestBody.commandSalaryId }, + }); + if (!commandSalary) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลต้นแบบ"); + } + } const data = new Command(); Object.assign(data, { ...command, ...requestBody }); data.lastUpdateUserId = request.user.sub; @@ -306,6 +313,66 @@ export class CommandController extends Controller { return new HttpSuccess(); } + @Get("tap2/swap/{direction}/{commandReciveId}") + public async swapSalary( + @Path() direction: string, + commandReciveId: string, + @Request() req: RequestWithUser, + ) { + const source_item = await this.commandReciveRepository.findOne({ + where: { id: commandReciveId }, + }); + if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); + const sourceOrder = source_item.order; + if (direction.trim().toUpperCase() == "UP") { + const dest_item = await this.commandReciveRepository.findOne({ + where: { commandId: source_item.commandId, order: LessThan(sourceOrder) }, + order: { order: "DESC" }, + }); + if (dest_item == null) return new HttpSuccess(); + var destOrder = dest_item.order; + dest_item.order = sourceOrder; + source_item.order = destOrder; + await Promise.all([ + this.commandReciveRepository.save(source_item), + this.commandReciveRepository.save(dest_item), + ]); + } else { + const dest_item = await this.commandReciveRepository.findOne({ + where: { commandId: source_item.commandId, order: MoreThan(sourceOrder) }, + order: { order: "ASC" }, + }); + if (dest_item == null) return new HttpSuccess(); + var destOrder = dest_item.order; + dest_item.order = sourceOrder; + source_item.order = destOrder; + await Promise.all([ + this.commandReciveRepository.save(source_item), + this.commandReciveRepository.save(dest_item), + ]); + } + return new HttpSuccess(); + } + + /** + * API ลบรายการผู้ได้รับคำสั่ง + * + * @summary API ลบรายการผู้ได้รับคำสั่ง + * + * @param {string} id Id ผู้ได้รับคำสั่ง + */ + @Delete("tab2/{id}") + async DeleteTab2(@Path() id: string) { + const commandRecive = await this.commandReciveRepository.findOne({ + where: { id: id }, + }); + if (!commandRecive) { + throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง"); + } + await this.commandReciveRepository.delete(commandRecive.id); + return new HttpSuccess(); + } + /** * API รายละเอียดรายการคำสั่ง tab3 * diff --git a/src/entities/ProfileDevelopment.ts b/src/entities/ProfileDevelopment.ts index ee3f3d4f..f279bb09 100644 --- a/src/entities/ProfileDevelopment.ts +++ b/src/entities/ProfileDevelopment.ts @@ -136,53 +136,53 @@ export class ProfileDevelopment extends EntityBase { export class CreateProfileDevelopment { profileId: string | null; - name: string; + name: string | null; target: string | null; achievement10?: string | null; achievement5?: string | null; achievement0?: string | null; kpiDevelopmentId?: string | null; - reasonDevelopment70?: string; - reasonDevelopment20?: string; - reasonDevelopment10?: string; - isDevelopment70: boolean; - isDevelopment20: boolean; - isDevelopment10: boolean; - summary?: number; - point?: number; + reasonDevelopment70?: string | null; + reasonDevelopment20?: string | null; + reasonDevelopment10?: string | null; + isDevelopment70: boolean | null; + isDevelopment20: boolean | null; + isDevelopment10: boolean | null; + summary?: number | null; + point?: number | null; } export class CreateProfileEmployeeDevelopment { profileEmployeeId: string | null; - name: string; + name: string | null; target: string | null; achievement10?: string | null; achievement5?: string | null; achievement0?: string | null; - kpiDevelopmentId?: string; - reasonDevelopment70?: string; - reasonDevelopment20?: string; - reasonDevelopment10?: string; - isDevelopment70: boolean; - isDevelopment20: boolean; - isDevelopment10: boolean; - summary?: number; - point?: number; + kpiDevelopmentId?: string | null; + reasonDevelopment70?: string | null; + reasonDevelopment20?: string | null; + reasonDevelopment10?: string | null; + isDevelopment70: boolean | null; + isDevelopment20: boolean | null; + isDevelopment10: boolean | null; + summary?: number | null; + point?: number | null; } export type UpdateProfileDevelopment = { - name: string; + name: string | null; target: string | null; achievement10?: string | null; achievement5?: string | null; achievement0?: string | null; - kpiDevelopmentId?: string; - reasonDevelopment70?: string; - reasonDevelopment20?: string; - reasonDevelopment10?: string; - isDevelopment70: boolean; - isDevelopment20: boolean; - isDevelopment10: boolean; - summary?: number; - point?: number; + kpiDevelopmentId?: string | null; + reasonDevelopment70?: string | null; + reasonDevelopment20?: string | null; + reasonDevelopment10?: string | null; + isDevelopment70: boolean | null; + isDevelopment20: boolean | null; + isDevelopment10: boolean | null; + summary?: number | null; + point?: number | null; };