digital sign

This commit is contained in:
kittapath 2024-11-01 19:53:26 +07:00
parent 0b2650e17c
commit 016fb3da91
5 changed files with 193 additions and 53 deletions

View file

@ -59,6 +59,7 @@ import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate"; import { CreateProfileCertificate, ProfileCertificate } from "../entities/ProfileCertificate";
import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory"; import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { CommandSign } from "../entities/CommandSign";
@Route("api/v1/org/command") @Route("api/v1/org/command")
@Tags("Command") @Tags("Command")
@ -93,6 +94,7 @@ export class CommandController extends Controller {
private certificateRepo = AppDataSource.getRepository(ProfileCertificate); private certificateRepo = AppDataSource.getRepository(ProfileCertificate);
private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory); private certificateHistoryRepo = AppDataSource.getRepository(ProfileCertificateHistory);
private orgRevisionRepository = AppDataSource.getRepository(OrgRevision); private orgRevisionRepository = AppDataSource.getRepository(OrgRevision);
private commandSignRepository = AppDataSource.getRepository(CommandSign);
/** /**
* API list * API list
@ -249,9 +251,16 @@ export class CommandController extends Controller {
new Brackets((qb) => { new Brackets((qb) => {
qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", { qb.where(keyword != null && keyword != "" ? "command.commandNo LIKE :keyword" : "1=1", {
keyword: `%${keyword}%`, keyword: `%${keyword}%`,
}).orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", { })
keyword: `%${keyword}%`, .orWhere(keyword != null && keyword != "" ? "command.issue LIKE :keyword" : "1=1", {
}); keyword: `%${keyword}%`,
})
.orWhere(
keyword != null && keyword != "" ? "command.createdFullName LIKE :keyword" : "1=1",
{
keyword: `%${keyword}%`,
},
);
}), }),
) )
.orderBy("command.createdAt", "DESC") .orderBy("command.createdAt", "DESC")
@ -1219,14 +1228,13 @@ export class CommandController extends Controller {
if (issue == null) issue = "..................................."; if (issue == null) issue = "...................................";
let res: any[] = []; let res: any[] = [];
if(command.commandRecives.length > 0) { if (command.commandRecives.length > 0) {
await new CallAPI() await new CallAPI()
.GetData(request, `/probation/report/command10/appoints/${command.commandRecives[0].refId}`) .GetData(request, `/probation/report/command10/appoints/${command.commandRecives[0].refId}`)
.then((x) => { .then((x) => {
res = x.data res = x;
}) })
.catch((x) => { .catch((x) => {});
});
} }
let _command = { let _command = {
@ -1253,18 +1261,22 @@ export class CommandController extends Controller {
authorizedUserFullName: "...................................", authorizedUserFullName: "...................................",
authorizedPosition: "...................................", authorizedPosition: "...................................",
commandAffectDate: "...................................", commandAffectDate: "...................................",
name1: res && res.length > 0 name1:
? `${res[0].name}..........................${res[0].role}` res && res.length > 0
: "", ? `๑. ${res[0].name}.........${res[0].role}`
name2: res && res.length > 1 : "๑. ..........................ประธาน",
? `${res[1].name}..........................${res[1].role}` name2:
: "", res && res.length > 1
name3: res && res.length > 2 ? `๒. ${res[1].name}.........${res[1].role}`
? `${res[2].name}..........................${res[2].role}` : "๒. ..........................กรรมการ",
: "", name3:
name4: res && res.length > 3 res && res.length > 2
? `${res[3].name}..........................${res[3].role}` ? `๓. ${res[2].name}.........${res[2].role}`
: "", : "๓. ..........................กรรมการ",
name4:
res && res.length > 3
? `๔. ${res[3].name}.........${res[3].role}`
: "๔. ..........................กรรมการ",
}; };
return new HttpSuccess({ return new HttpSuccess({
@ -1363,6 +1375,118 @@ export class CommandController extends Controller {
}); });
} }
/**
* API step
*
* @summary API step
*
* @param {string} id Id
*/
@Get("step/{id}")
async GetByIdStep(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandSigns"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const _command = command.commandSigns.map((item) => ({
id: item.id,
prefix: item.prefix,
firstName: item.firstName,
lastName: item.lastName,
position: item.position,
profileId: item.profileId,
}));
return new HttpSuccess(_command);
}
/**
* API body step
*
* @summary API body step
*
* @param {string} id Id
*/
@Put("step-add/{id}")
async PutStepAdd(
@Path() id: string,
@Body()
requestBody: {
profileId: string;
isSignatory: boolean;
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({ where: { id: id } });
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
const profile = await this.profileRepository.findOne({ where: { id: requestBody.profileId } });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ใช้งานนี้");
}
command.status = "PENDING";
command.isDraft = true;
const commandSign = new CommandSign();
commandSign.prefix = profile.prefix;
commandSign.firstName = profile.firstName;
commandSign.lastName = profile.lastName;
commandSign.position = profile.position;
commandSign.isSignatory = requestBody.isSignatory;
commandSign.profileId = requestBody.profileId;
commandSign.commandId = command.id;
commandSign.createdUserId = request.user.sub;
commandSign.createdFullName = request.user.name;
commandSign.createdAt = new Date();
commandSign.lastUpdateUserId = request.user.sub;
commandSign.lastUpdateFullName = request.user.name;
commandSign.lastUpdatedAt = new Date();
await this.commandSignRepository.save(commandSign);
await this.commandRepository.save(command);
return new HttpSuccess();
}
/**
* API body step-comment
*
* @summary API body step-comment
*
* @param {string} id Id
*/
@Put("step-comment/{id}")
async PutStepComment(
@Path() id: string,
@Body()
requestBody: {
comment: string;
},
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const commandSign = await this.commandSignRepository.findOne({
where: { id: id },
relations: ["command"],
});
if (!commandSign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
commandSign.comment = requestBody.comment;
commandSign.lastUpdateUserId = request.user.sub;
commandSign.lastUpdateFullName = request.user.name;
commandSign.lastUpdatedAt = new Date();
await this.commandSignRepository.save(commandSign);
if(commandSign.isSignatory == true)
await this.PutSelectPending(commandSign.commandId, { sign: true }, request);
return new HttpSuccess();
}
/** /**
* API body * API body
* *

View file

@ -120,8 +120,8 @@ export class CommandTypeController extends Controller {
if (!_commandType) { if (!_commandType) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
if(_commandType.code == "C-PM-10") { if (_commandType.code == "C-PM-10") {
let _commandType10: any let _commandType10: any;
_commandType10 = { _commandType10 = {
id: _commandType.id, id: _commandType.id,
name: _commandType.name, name: _commandType.name,
@ -135,11 +135,11 @@ export class CommandTypeController extends Controller {
detailFooter: _commandType.detailFooter, detailFooter: _commandType.detailFooter,
subtitle: _commandType.subtitle, subtitle: _commandType.subtitle,
isAttachment: _commandType.isAttachment, isAttachment: _commandType.isAttachment,
name1: "..........................ประธาน", name1: "๑. ..........................ประธาน",
name2: "..........................ผู้บังคับบัญชา", name2: "๒. ..........................กรรมการ",
name3: "..........................ผู้ดูแล", name3: "๓. ..........................กรรมการ",
name4: "..........................ผู้ดูแล", name4: "๔. ..........................กรรมการ",
} };
_commandType = _commandType10; _commandType = _commandType10;
} }
return new HttpSuccess(_commandType); return new HttpSuccess(_commandType);

View file

@ -49,7 +49,7 @@ export class CommandSign extends EntityBase {
comment: "เป็นผู้มีอำนาจลงนาม", comment: "เป็นผู้มีอำนาจลงนาม",
default: false, default: false,
}) })
isActive: boolean; isSignatory: boolean;
@Column({ @Column({
length: 40, length: 40,

View file

@ -52,30 +52,32 @@ class CallAPI {
api_key: process.env.API_KEY, api_key: process.env.API_KEY,
}, },
}); });
if (log) addLogSequence(request, { if (log)
action: "request", addLogSequence(request, {
status: "success", action: "request",
description: "connected", status: "success",
request: { description: "connected",
method: "POST", request: {
url: url, method: "POST",
payload: JSON.stringify(sendData), url: url,
response: JSON.stringify(response.data.result), payload: JSON.stringify(sendData),
}, response: JSON.stringify(response.data.result),
}); },
});
return response.data.result; return response.data.result;
} catch (error) { } catch (error) {
if (log) addLogSequence(request, { if (log)
action: "request", addLogSequence(request, {
status: "error", action: "request",
description: "unconnected", status: "error",
request: { description: "unconnected",
method: "POST", request: {
url: url, method: "POST",
payload: JSON.stringify(sendData), url: url,
response: JSON.stringify(error), payload: JSON.stringify(sendData),
}, response: JSON.stringify(error),
}); },
});
throw error; throw error;
} }
} }

View file

@ -0,0 +1,14 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class AddTableCommandSign11730463698383 implements MigrationInterface {
name = 'AddTableCommandSign11730463698383'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandSign\` CHANGE \`isActive\` \`isSignatory\` tinyint NOT NULL COMMENT 'เป็นผู้มีอำนาจลงนาม' DEFAULT '0'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`commandSign\` CHANGE \`isSignatory\` \`isActive\` tinyint NOT NULL COMMENT 'เป็นผู้มีอำนาจลงนาม' DEFAULT '0'`);
}
}