แก้คำสั่ง tab2
This commit is contained in:
parent
a7022b0cec
commit
8040172131
2 changed files with 105 additions and 38 deletions
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue