เพิ่มตำแหน่งเจ้าหน้าที่
This commit is contained in:
parent
3b0d8c24a7
commit
6f11eecb8f
15 changed files with 771 additions and 33 deletions
|
|
@ -21,6 +21,10 @@ import HttpError from "../interfaces/http-error";
|
|||
import { Command } from "../entities/Command";
|
||||
import { Brackets } 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";
|
||||
|
||||
@Route("api/v1/org/command")
|
||||
@Tags("Command")
|
||||
|
|
@ -33,6 +37,9 @@ import { CommandType } from "../entities/CommandType";
|
|||
export class CommandController extends Controller {
|
||||
private commandRepository = AppDataSource.getRepository(Command);
|
||||
private commandTypeRepository = AppDataSource.getRepository(CommandType);
|
||||
private commandSendRepository = AppDataSource.getRepository(CommandSend);
|
||||
private profileRepository = AppDataSource.getRepository(Profile);
|
||||
private orgRevisionRepo = AppDataSource.getRepository(OrgRevision);
|
||||
|
||||
/**
|
||||
* API list รายการคำสั่ง
|
||||
|
|
@ -74,9 +81,14 @@ export class CommandController extends Controller {
|
|||
: `${status.trim().toLocaleUpperCase()}`,
|
||||
},
|
||||
)
|
||||
.andWhere(year != null && year != undefined && year != 0 ? "command.commandYear = :commandYear" : "1=1", {
|
||||
commandYear: year == null || year == undefined || year == 0 ? null : `${year}`,
|
||||
})
|
||||
.andWhere(
|
||||
year != null && year != undefined && year != 0
|
||||
? "command.commandYear = :commandYear"
|
||||
: "1=1",
|
||||
{
|
||||
commandYear: year == null || year == undefined || year == 0 ? null : `${year}`,
|
||||
},
|
||||
)
|
||||
.andWhere(
|
||||
commandTypeId != null && commandTypeId != undefined && commandTypeId != ""
|
||||
? "command.commandTypeId = :commandTypeId"
|
||||
|
|
@ -120,7 +132,7 @@ export class CommandController extends Controller {
|
|||
commandNo: string | null;
|
||||
commandYear: number | null;
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = Object.assign(new Command(), requestBody);
|
||||
|
||||
|
|
@ -132,6 +144,7 @@ export class CommandController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
|
||||
}
|
||||
command.status = "DRAFT";
|
||||
command.issue = commandType.name;
|
||||
command.createdUserId = request.user.sub;
|
||||
command.createdFullName = request.user.name;
|
||||
command.createdAt = new Date();
|
||||
|
|
@ -153,21 +166,25 @@ export class CommandController extends Controller {
|
|||
async GetByIdTab1(@Path() id: string) {
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id },
|
||||
select: [
|
||||
"id",
|
||||
"status",
|
||||
"commandNo",
|
||||
"commandYear",
|
||||
"issue",
|
||||
"detailHeader",
|
||||
"detailBody",
|
||||
"detailFooter",
|
||||
],
|
||||
relations: ["commandType", "commandType.commandTypeSys"],
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
return new HttpSuccess(command);
|
||||
|
||||
const _command = {
|
||||
id: command.id,
|
||||
status: command.status,
|
||||
commandNo: command.commandNo,
|
||||
commandYear: command.commandYear,
|
||||
issue: command.issue,
|
||||
detailHeader: command.detailHeader,
|
||||
detailBody: command.detailBody,
|
||||
detailFooter: command.detailFooter,
|
||||
commandTypeName: command.commandType?.name || null,
|
||||
commandSysId: command.commandType?.commandSysId || null,
|
||||
};
|
||||
return new HttpSuccess(_command);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -189,7 +206,7 @@ export class CommandController extends Controller {
|
|||
detailBody: string | null;
|
||||
detailFooter: string | null;
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
|
|
@ -204,6 +221,166 @@ export class CommandController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการคำสั่ง tab3
|
||||
*
|
||||
* @summary API รายละเอียดรายการคำสั่ง tab3
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Get("tab3/{id}")
|
||||
async GetByIdTab3(@Path() id: string) {
|
||||
const command = await this.commandRepository.findOne({
|
||||
where: { id },
|
||||
relations: ["commandSends"],
|
||||
});
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
|
||||
const _command = command.commandSends.map((item) => ({
|
||||
id: item.id,
|
||||
citizenId: item.citizenId,
|
||||
prefix: item.prefix,
|
||||
fristName: item.fristName,
|
||||
lastName: item.lastName,
|
||||
position: item.position,
|
||||
org: item.org,
|
||||
sendCC: item.sendCC,
|
||||
profileId: item.profileId,
|
||||
}));
|
||||
return new HttpSuccess(_command);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @summary API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Put("tab3-add/{id}")
|
||||
async PutTab3Add(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: {
|
||||
profileId: string[];
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
let _null: any = null;
|
||||
|
||||
await Promise.all(
|
||||
requestBody.profileId.map(async (item) => {
|
||||
const commandSendCheck = await this.commandSendRepository.findOne({
|
||||
where: { profileId: item, commandId: command.id },
|
||||
});
|
||||
if (commandSendCheck) return;
|
||||
|
||||
let profile = await this.profileRepository.findOne({
|
||||
where: { id: item },
|
||||
relations: ["current_holders", "current_holders.orgRoot"],
|
||||
});
|
||||
if (!profile) return;
|
||||
|
||||
const findRevision = await this.orgRevisionRepo.findOne({
|
||||
where: { orgRevisionIsCurrent: true },
|
||||
});
|
||||
|
||||
const commandSend = new CommandSend();
|
||||
commandSend.citizenId = profile.citizenId;
|
||||
commandSend.prefix =
|
||||
profile.rank != null && profile.rank != "" ? profile.rank : profile.prefix;
|
||||
commandSend.fristName = profile.firstName;
|
||||
commandSend.lastName = profile.lastName;
|
||||
commandSend.position = profile.position;
|
||||
commandSend.org =
|
||||
profile.current_holders?.find((x) => x.orgRevisionId == findRevision?.id)?.orgRoot
|
||||
?.orgRootName || _null;
|
||||
commandSend.profileId = profile.id;
|
||||
commandSend.commandId = command.id;
|
||||
commandSend.createdUserId = request.user.sub;
|
||||
commandSend.createdFullName = request.user.name;
|
||||
commandSend.createdAt = new Date();
|
||||
commandSend.lastUpdateUserId = request.user.sub;
|
||||
commandSend.lastUpdateFullName = request.user.name;
|
||||
commandSend.lastUpdatedAt = new Date();
|
||||
await this.commandSendRepository.save(commandSend);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @summary API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Put("tab3/{id}")
|
||||
async PutTab3Update(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: {
|
||||
commandSend: {
|
||||
id: string;
|
||||
sendCC: string;
|
||||
}[];
|
||||
},
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
|
||||
await Promise.all(
|
||||
requestBody.commandSend.map(async (item) => {
|
||||
const commandSend = await this.commandSendRepository.findOne({
|
||||
where: { id: item.id },
|
||||
});
|
||||
if (!commandSend) return;
|
||||
|
||||
commandSend.sendCC = item.sendCC;
|
||||
commandSend.lastUpdateUserId = request.user.sub;
|
||||
commandSend.lastUpdateFullName = request.user.name;
|
||||
commandSend.lastUpdatedAt = new Date();
|
||||
await this.commandSendRepository.save(commandSend);
|
||||
}),
|
||||
);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @summary API แก้ไขรายการ body คำสั่ง Tab3
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Delete("tab3/{commandSendId}")
|
||||
async DeleteTab3Update(
|
||||
@Path() commandSendId: string,
|
||||
@Body()
|
||||
requestBody: { reason?: string | null },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandSendRepository.findOne({ where: { id: commandSendId } });
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ได้รับสำเนาคำสั่ง");
|
||||
}
|
||||
|
||||
await this.commandSendRepository.delete(commandSendId);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API คัดลอก
|
||||
*
|
||||
|
|
@ -215,8 +392,8 @@ export class CommandController extends Controller {
|
|||
async PutCopy(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: { commandNo?: string | null; commandYear?: string | null },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
requestBody: { commandNo?: string | null; commandYear?: number | null },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
|
|
@ -246,7 +423,7 @@ export class CommandController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: { reason?: string | null },
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
|
|
@ -260,6 +437,32 @@ export class CommandController extends Controller {
|
|||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ทำคำสั่งใหม่
|
||||
*
|
||||
* @summary API ทำคำสั่งใหม่
|
||||
*
|
||||
* @param {string} id Id คำสั่ง
|
||||
*/
|
||||
@Put("resume/{id}")
|
||||
async PutDraft(
|
||||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: { reason?: string | null },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const command = await this.commandRepository.findOne({ where: { id: id } });
|
||||
if (!command) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
|
||||
}
|
||||
command.status = "DRAFT";
|
||||
command.lastUpdateUserId = request.user.sub;
|
||||
command.lastUpdateFullName = request.user.name;
|
||||
command.lastUpdatedAt = new Date();
|
||||
await this.commandRepository.save(command);
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบรายการคำสั่ง
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue