sort profile send report

This commit is contained in:
kittapath 2024-09-25 16:17:06 +07:00
parent e2939cae3a
commit 7697d6d46a
7 changed files with 169 additions and 14 deletions

View file

@ -19,7 +19,7 @@ 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, LessThan, MoreThan } from "typeorm";
import { Brackets, LessThan, MoreThan, Double } from "typeorm";
import { CommandType } from "../entities/CommandType";
import { CommandSend } from "../entities/CommandSend";
import { Profile } from "../entities/Profile";
@ -123,6 +123,7 @@ export class CommandController extends Controller {
assignFullName: _data.createdFullName,
createdFullName: _data.createdFullName,
status: _data.status,
issue: _data.issue,
}));
return new HttpSuccess({ data, total });
@ -261,15 +262,21 @@ export class CommandController extends Controller {
commandSalaryId: command.commandSalaryId,
commandSalary: command.commandSalary?.name || null,
positionDetail: command.positionDetail,
sendCC: command.commandRecives
commandRecives: command.commandRecives
.sort((a, b) => a.order - b.order)
.map((x) => ({
id: x.id,
citizenId: x.citizenId,
prefix: x.prefix,
fristName: x.fristName,
lastName: x.lastName,
profileId: x.profileId,
order: x.order,
remarkVertical: x.remarkVertical,
remarkHorizontal: x.remarkHorizontal,
amount: x.amount,
positionSalaryAmount: x.positionSalaryAmount,
mouthSalaryAmount: x.mouthSalaryAmount,
})),
};
return new HttpSuccess(_command);
@ -354,6 +361,41 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
/**
* API body Tab2
*
* @summary API body Tab2
*
* @param {string} id Id
*/
@Put("tab2/recive/{commandReciveId}")
async PutTab2Recive(
@Path() commandReciveId: string,
@Body()
requestBody: {
remarkVertical: string | null;
remarkHorizontal: string | null;
amount: Double | null;
positionSalaryAmount: Double | null;
mouthSalaryAmount: Double | null;
},
@Request() request: RequestWithUser,
) {
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: commandReciveId },
});
if (!commandRecive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง");
}
const data = new CommandRecive();
Object.assign(data, { ...commandRecive, ...requestBody });
data.lastUpdateUserId = request.user.sub;
data.lastUpdateFullName = request.user.name;
data.lastUpdatedAt = new Date();
await this.commandReciveRepository.save(data);
return new HttpSuccess();
}
/**
* API
*
@ -361,15 +403,27 @@ export class CommandController extends Controller {
*
* @param {string} id Id
*/
@Delete("tab2/{id}")
async DeleteTab2(@Path() id: string) {
@Delete("tab2/{commandReciveId}")
async DeleteTab2(@Path() commandReciveId: string) {
const commandRecive = await this.commandReciveRepository.findOne({
where: { id: id },
where: { id: commandReciveId },
});
if (!commandRecive) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับคำสั่ง");
}
await this.commandReciveRepository.delete(commandRecive.id);
const commandId = commandRecive.commandId;
// await this.commandReciveRepository.delete(commandRecive.id);
const commandReciveList = await this.commandReciveRepository.find({
where: {
commandId: commandId,
},
order: { order: "ASC" },
});
commandReciveList.map(async (p, i) => {
p.order = i + 1;
await this.commandReciveRepository.save(p);
});
return new HttpSuccess();
}