no message

This commit is contained in:
kittapath 2024-12-12 11:36:11 +07:00
parent 992a48b787
commit 9abdeca45b
5 changed files with 197 additions and 181 deletions

View file

@ -700,10 +700,10 @@ export class CommandController extends Controller {
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if(commandSend && commandSend.id) {
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for(let i=0; i<_ccName.length; i++) {
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
@ -943,7 +943,7 @@ export class CommandController extends Controller {
await new permission().PermissionGet(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id },
relations: ["commandType"]
relations: ["commandType"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
@ -1148,88 +1148,88 @@ export class CommandController extends Controller {
return new HttpSuccess();
}
/**
/**
* API
*
* @summary API
*
* @param {string} id Id
*/
@Put("testRabbit/{id}")
async testRabbit(
@Path() id: string,
@Body()
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives",],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
command.isSign = true;
if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
@Put("testRabbit/{id}")
async testRabbit(
@Path() id: string,
@Body()
requestBody: { sign?: boolean },
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "COMMAND");
const command = await this.commandRepository.findOne({
where: { id: id },
relations: ["commandType", "commandRecives"],
});
if (!command) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำสั่งนี้");
}
command.isSign = true;
if (command.commandExcecuteDate == null)
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบวันที่คำสั่งมีผล");
let profiles =
command && command.commandRecives.length > 0
? command.commandRecives
.filter((x) => x.profileId != null)
.map((x) => ({
receiverUserId: x.profileId,
notiLink: "",
}))
: [];
let profiles =
command && command.commandRecives.length > 0
? command.commandRecives
.filter((x) => x.profileId != null)
.map((x) => ({
receiverUserId: x.profileId,
notiLink: "",
}))
: [];
await new CallAPI()
.PostData(request, "/placement/noti/profiles", {
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserIds: profiles,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
await new CallAPI()
.PostData(request, "/placement/noti/profiles", {
subject: `${command.issue}`,
body: `${command.issue}`,
receiverUserIds: profiles,
payload: "", //แนบไฟล์
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
if (
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
new Date(
command.commandExcecuteDate.getFullYear(),
command.commandExcecuteDate.getMonth(),
command.commandExcecuteDate.getDate(),
)
) {
command.status = "WAITING";
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
command.lastUpdatedAt = new Date();
await this.commandRepository.save(command);
} else {
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = {
data: {
id: command.id,
status: "REPORTED",
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
},
user: request.user,
token: request.headers["authorization"],
};
sendToQueue(msg);
}
return new HttpSuccess();
}
if (
new Date(new Date().getFullYear(), new Date().getMonth(), new Date().getDate()) <
new Date(
command.commandExcecuteDate.getFullYear(),
command.commandExcecuteDate.getMonth(),
command.commandExcecuteDate.getDate(),
)
) {
command.status = "WAITING";
command.lastUpdateUserId = request.user.sub;
command.lastUpdateFullName = request.user.name;
command.lastUpdatedAt = new Date();
await this.commandRepository.save(command);
} else {
const path = commandTypePath(command.commandType.code);
if (path == null) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบประเภทคำสั่งนี้ในระบบ");
const msg = {
data: {
id: command.id,
status: "REPORTED",
lastUpdateUserId: request.user.sub,
lastUpdateFullName: request.user.name,
lastUpdatedAt: new Date(),
},
user: request.user,
token: request.headers["authorization"],
};
sendToQueue(msg);
}
return new HttpSuccess();
}
async cronjobCommand(@Request() request?: RequestWithUser) {
const today = new Date();
today.setUTCHours(0, 0, 0, 0);
@ -1255,7 +1255,7 @@ export class CommandController extends Controller {
let _data: any = null;
await Promise.all([
await new CallAPI()
.PostDataKeycloak("/realms/bma-ehr/protocol/openid-connect/token", data)
.PostDataKeycloak(`/realms/${process.env.KC_REALM}/protocol/openid-connect/token`, data)
.then(async (x) => {
_data = x;
})
@ -1635,7 +1635,7 @@ export class CommandController extends Controller {
@Request() request: RequestWithUser,
) {
let command = new Command();
let commandCode:string = "";
let commandCode: string = "";
let null_: any = null;
if (
requestBody.commandId != undefined &&
@ -1826,10 +1826,10 @@ export class CommandController extends Controller {
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if(commandSend && commandSend.id) {
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for(let i=0; i<_ccName.length; i++) {
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
@ -1842,7 +1842,7 @@ export class CommandController extends Controller {
});
}
await this.commandSendCCRepository.save(_dataSendCC);
}
}
}),
);
@ -1884,10 +1884,10 @@ export class CommandController extends Controller {
commandSend.lastUpdateFullName = request.user.name;
commandSend.lastUpdatedAt = new Date();
await this.commandSendRepository.save(commandSend);
if(commandSend && commandSend.id) {
if (commandSend && commandSend.id) {
let _ccName = new Array("EMAIL", "INBOX");
let _dataSendCC = new Array();
for(let i=0; i<_ccName.length; i++) {
for (let i = 0; i < _ccName.length; i++) {
_dataSendCC.push({
commandSendId: commandSend.id,
name: _ccName[i],
@ -1936,7 +1936,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile:any = await this.profileRepository.findOneBy({ id: item.profileId });
const profile: any = await this.profileRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทะเบียนประวัตินี้");
}
@ -2058,7 +2058,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile:any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
const profile: any = await this.profileEmployeeRepository.findOneBy({ id: item.profileId });
if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
}
@ -2265,16 +2265,22 @@ export class CommandController extends Controller {
lastName: profile.lastName,
});
// กรณี Keycloak ไม่ถูกลบ ให้ลบซ้ำอีกรอบแล้วสร้างใหม่ และหากยังไม่สามารถลบได้ให้แสดง Error
if (profile.keycloak != null && userKeycloakId && userKeycloakId.errorMessage === "User exists with same username") {
if (
profile.keycloak != null &&
userKeycloakId &&
userKeycloakId.errorMessage === "User exists with same username"
) {
const delUserKeycloak = await deleteUser(profile.keycloak);
if(delUserKeycloak) {
if (delUserKeycloak) {
userKeycloakId = await createUser(profile.citizenId, profile.citizenId, {
firstName: profile.firstName,
lastName: profile.lastName,
});
}
else {
throw new HttpError(HttpStatus.BAD_REQUEST, "พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้");
} else {
throw new HttpError(
HttpStatus.BAD_REQUEST,
"พบข้อผิดพลาด ไม่สามารถจัดการผู้ใช้งานได้",
);
}
}
const list = await getRoles();
@ -2430,7 +2436,7 @@ export class CommandController extends Controller {
) {
await Promise.all(
body.data.map(async (item) => {
const profile:any = await this.profileRepository.findOne({
const profile: any = await this.profileRepository.findOne({
where: { id: item.profileId },
relations: ["roleKeycloaks"],
});
@ -2709,7 +2715,7 @@ export class CommandController extends Controller {
const exceptClear = await checkExceptCommandType(String(item.commandId));
if (item.isLeave == true && !exceptClear) {
await removeProfileInOrganize(_profile.id, "OFFICER");
}
}
//คำสั่งพักราชการ หรือ ให้ออกจากราชการไว้ก่อน solutionเดิม ให้ disable user ไว้แต่ยังไม่ลบ เปลี่ยนเป็นลบ user ออกเลย
else if (item.isLeave == true && exceptClear && _profile.keycloak != null) {
// const enableActive = await enableStatus(_profile.keycloak, false);
@ -3161,7 +3167,7 @@ export class CommandController extends Controller {
where: { profileId: profile.id },
order: { order: "DESC" },
});
const profileSal: any = new ProfileSalary();
const profileSal: any = new ProfileSalary();
Object.assign(profileSal, { ...item.bodySalarys, ...meta });
const salaryHistory = new ProfileSalaryHistory();
Object.assign(salaryHistory, { ...profileSal, id: undefined });
@ -3792,7 +3798,9 @@ export class CommandController extends Controller {
if (
orgRevision != null &&
!["REPORT", "DONE"].includes(
orgRevision.posMasters.find((x) => x.statusReport === "REPORT" || x.statusReport === "DONE")?.statusReport || "",
orgRevision.posMasters.find(
(x) => x.statusReport === "REPORT" || x.statusReport === "DONE",
)?.statusReport || "",
)
) {
await this.orgRevisionRepo.update(orgRevision.id, {