fix remove await and addLogSequence of exprofile system
This commit is contained in:
parent
66d8ba089d
commit
6c31cd42c0
5 changed files with 186 additions and 171 deletions
|
|
@ -2497,12 +2497,12 @@ export class CommandController extends Controller {
|
||||||
@Put("change-creator/{id}")
|
@Put("change-creator/{id}")
|
||||||
async ChangeCreator(
|
async ChangeCreator(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() req: { assignId: string; },
|
@Body() req: { assignId: string },
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "COMMAND");
|
await new permission().PermissionUpdate(request, "COMMAND");
|
||||||
const command = await this.commandRepository.findOne({
|
const command = await this.commandRepository.findOne({
|
||||||
where: { id: id }
|
where: { id: id },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!command) {
|
if (!command) {
|
||||||
|
|
@ -4048,8 +4048,11 @@ export class CommandController extends Controller {
|
||||||
const executeDate = commandResign
|
const executeDate = commandResign
|
||||||
? new Date(commandResign.command.commandExcecuteDate).setHours(0, 0, 0, 0)
|
? new Date(commandResign.command.commandExcecuteDate).setHours(0, 0, 0, 0)
|
||||||
: today;
|
: today;
|
||||||
if (commandResign && _command.status !== "REPORTED" &&
|
if (
|
||||||
(_command.status !== "WAITING" || today < executeDate)) {
|
commandResign &&
|
||||||
|
_command.status !== "REPORTED" &&
|
||||||
|
(_command.status !== "WAITING" || today < executeDate)
|
||||||
|
) {
|
||||||
await reOrderCommandRecivesAndDelete(commandResign!.id);
|
await reOrderCommandRecivesAndDelete(commandResign!.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4322,6 +4325,7 @@ export class CommandController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
req,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
@ -4450,8 +4454,11 @@ export class CommandController extends Controller {
|
||||||
const executeDate = commandResign
|
const executeDate = commandResign
|
||||||
? new Date(commandResign.command.commandExcecuteDate).setHours(0, 0, 0, 0)
|
? new Date(commandResign.command.commandExcecuteDate).setHours(0, 0, 0, 0)
|
||||||
: today;
|
: today;
|
||||||
if (commandResign && _command.status !== "REPORTED" &&
|
if (
|
||||||
(_command.status !== "WAITING" || today < executeDate)) {
|
commandResign &&
|
||||||
|
_command.status !== "REPORTED" &&
|
||||||
|
(_command.status !== "WAITING" || today < executeDate)
|
||||||
|
) {
|
||||||
await reOrderCommandRecivesAndDelete(commandResign!.id);
|
await reOrderCommandRecivesAndDelete(commandResign!.id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4572,7 +4579,8 @@ export class CommandController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
req,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
@ -4842,7 +4850,8 @@ export class CommandController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
req,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
@ -5473,7 +5482,8 @@ export class CommandController extends Controller {
|
||||||
? `${profile.posLevel?.posLevelName}`
|
? `${profile.posLevel?.posLevelName}`
|
||||||
: `${profile.posType?.posTypeName} ${profile.posLevel?.posLevelName}`;
|
: `${profile.posType?.posTypeName} ${profile.posLevel?.posLevelName}`;
|
||||||
|
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
req,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
@ -6249,7 +6259,8 @@ export class CommandController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
req,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import {
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
|
import { addLogSequence } from "../interfaces/utils";
|
||||||
|
|
||||||
interface CachedToken {
|
interface CachedToken {
|
||||||
token: string;
|
token: string;
|
||||||
|
|
@ -171,6 +172,7 @@ async function getToken(ClientID: string, ClientSecret: string): Promise<string>
|
||||||
|
|
||||||
// function post retire data to exprofile system
|
// function post retire data to exprofile system
|
||||||
export async function PostRetireToExprofile(
|
export async function PostRetireToExprofile(
|
||||||
|
request: any,
|
||||||
citizenID: string,
|
citizenID: string,
|
||||||
prefix: string,
|
prefix: string,
|
||||||
firstName: string,
|
firstName: string,
|
||||||
|
|
@ -225,19 +227,6 @@ export async function PostRetireToExprofile(
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// addLogSequence(request, {
|
|
||||||
// action: "request",
|
|
||||||
// status: "success",
|
|
||||||
// description: "connected",
|
|
||||||
// request: {
|
|
||||||
// method: "POST",
|
|
||||||
// url: url,
|
|
||||||
// payload: JSON.stringify(sendData),
|
|
||||||
// response: JSON.stringify(response.data.result),
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
if (error.response?.status === 500 && retryCount < maxRetries - 1) {
|
if (error.response?.status === 500 && retryCount < maxRetries - 1) {
|
||||||
|
|
@ -245,6 +234,18 @@ export async function PostRetireToExprofile(
|
||||||
retryCount++;
|
retryCount++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addLogSequence(request, {
|
||||||
|
action: "request",
|
||||||
|
status: "error",
|
||||||
|
description: "unconnected to exprofile api",
|
||||||
|
request: {
|
||||||
|
method: "POST",
|
||||||
|
url: API_URL_BANGKOK + "/importData",
|
||||||
|
response: JSON.stringify(error),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถติดต่อ API ได้");
|
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถติดต่อ API ได้");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11013,7 +11013,8 @@ export class ProfileController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
request,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
|
||||||
|
|
@ -2290,13 +2290,13 @@ export class ProfileEmployeeController extends Controller {
|
||||||
@Get("history/user")
|
@Get("history/user")
|
||||||
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
|
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
where: { keycloak: request.user.sub }
|
where: { keycloak: request.user.sub },
|
||||||
});
|
});
|
||||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const profileHistory = await this.profileHistoryRepo.find({
|
const profileHistory = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: profile.id },
|
where: { profileEmployeeId: profile.id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (profileHistory.length == 0) {
|
if (profileHistory.length == 0) {
|
||||||
|
|
@ -2305,12 +2305,12 @@ export class ProfileEmployeeController extends Controller {
|
||||||
...profile,
|
...profile,
|
||||||
birthDateOld: profile?.birthDate,
|
birthDateOld: profile?.birthDate,
|
||||||
profileEmployeeId: profile.id,
|
profileEmployeeId: profile.id,
|
||||||
id: undefined
|
id: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const firstRecord = await this.profileHistoryRepo.find({
|
const firstRecord = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: profile.id },
|
where: { profileEmployeeId: profile.id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(firstRecord);
|
return new HttpSuccess(firstRecord);
|
||||||
}
|
}
|
||||||
|
|
@ -3207,13 +3207,13 @@ export class ProfileEmployeeController extends Controller {
|
||||||
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
|
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
|
||||||
//await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id); ไม่แน่ใจEMPปิดไว้ก่อน;
|
//await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id); ไม่แน่ใจEMPปิดไว้ก่อน;
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
where: { id: id }
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const profileHistory = await this.profileHistoryRepo.find({
|
const profileHistory = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: id },
|
where: { profileEmployeeId: id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (profileHistory.length == 0) {
|
if (profileHistory.length == 0) {
|
||||||
|
|
@ -3222,12 +3222,12 @@ export class ProfileEmployeeController extends Controller {
|
||||||
...profile,
|
...profile,
|
||||||
birthDateOld: profile?.birthDate,
|
birthDateOld: profile?.birthDate,
|
||||||
profileEmployeeId: id,
|
profileEmployeeId: id,
|
||||||
id: undefined
|
id: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const firstRecord = await this.profileHistoryRepo.find({
|
const firstRecord = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: id },
|
where: { profileEmployeeId: id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(firstRecord);
|
return new HttpSuccess(firstRecord);
|
||||||
}
|
}
|
||||||
|
|
@ -5450,7 +5450,8 @@ export class ProfileEmployeeController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
request,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
|
||||||
|
|
@ -1295,13 +1295,13 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
@Get("history/user")
|
@Get("history/user")
|
||||||
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
|
async getHistoryProfileByUser(@Request() request: RequestWithUser) {
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
where: { keycloak: request.user.sub }
|
where: { keycloak: request.user.sub },
|
||||||
});
|
});
|
||||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const profileHistory = await this.profileHistoryRepo.find({
|
const profileHistory = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: profile.id },
|
where: { profileEmployeeId: profile.id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (profileHistory.length == 0) {
|
if (profileHistory.length == 0) {
|
||||||
|
|
@ -1310,12 +1310,12 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
...profile,
|
...profile,
|
||||||
birthDateOld: profile?.birthDate,
|
birthDateOld: profile?.birthDate,
|
||||||
profileEmployeeId: profile.id,
|
profileEmployeeId: profile.id,
|
||||||
id: undefined
|
id: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const firstRecord = await this.profileHistoryRepo.find({
|
const firstRecord = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: profile.id },
|
where: { profileEmployeeId: profile.id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(firstRecord);
|
return new HttpSuccess(firstRecord);
|
||||||
}
|
}
|
||||||
|
|
@ -1828,13 +1828,13 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
|
async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
|
||||||
// await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");//ไม่แน่ใจTEMPปิดไว้ก่อน
|
// await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");//ไม่แน่ใจTEMPปิดไว้ก่อน
|
||||||
const profile = await this.profileRepo.findOne({
|
const profile = await this.profileRepo.findOne({
|
||||||
where: { id: id }
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
|
|
||||||
const profileHistory = await this.profileHistoryRepo.find({
|
const profileHistory = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: id },
|
where: { profileEmployeeId: id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (profileHistory.length == 0) {
|
if (profileHistory.length == 0) {
|
||||||
|
|
@ -1843,12 +1843,12 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
...profile,
|
...profile,
|
||||||
birthDateOld: profile?.birthDate,
|
birthDateOld: profile?.birthDate,
|
||||||
profileEmployeeId: id,
|
profileEmployeeId: id,
|
||||||
id: undefined
|
id: undefined,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
const firstRecord = await this.profileHistoryRepo.find({
|
const firstRecord = await this.profileHistoryRepo.find({
|
||||||
where: { profileEmployeeId: id },
|
where: { profileEmployeeId: id },
|
||||||
order: { createdAt: "ASC" }
|
order: { createdAt: "ASC" },
|
||||||
});
|
});
|
||||||
return new HttpSuccess(firstRecord);
|
return new HttpSuccess(firstRecord);
|
||||||
}
|
}
|
||||||
|
|
@ -3606,7 +3606,8 @@ export class ProfileEmployeeTempController extends Controller {
|
||||||
].filter(Boolean);
|
].filter(Boolean);
|
||||||
organizeName = names.join(" ");
|
organizeName = names.join(" ");
|
||||||
}
|
}
|
||||||
await PostRetireToExprofile(
|
PostRetireToExprofile(
|
||||||
|
request,
|
||||||
profile.citizenId ?? "",
|
profile.citizenId ?? "",
|
||||||
profile.prefix ?? "",
|
profile.prefix ?? "",
|
||||||
profile.firstName ?? "",
|
profile.firstName ?? "",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue