fixing throw error message
This commit is contained in:
parent
a38adb9598
commit
1a6dc0214e
12 changed files with 622 additions and 1325 deletions
|
|
@ -24,10 +24,7 @@ import { Assign } from "../entities/Assign";
|
|||
import { Personal } from "../entities/Personal";
|
||||
import CallAPI from "../interfaces/call-api";
|
||||
import { EvaluateChairman } from "../entities/EvaluateChairman";
|
||||
import {
|
||||
CreateEvaluateResult,
|
||||
EvaluateResult,
|
||||
} from "../entities/EvaluateResult";
|
||||
import { CreateEvaluateResult, EvaluateResult } from "../entities/EvaluateResult";
|
||||
import permission from "../interfaces/permission";
|
||||
|
||||
@Route("api/v1/probation/evaluate-result")
|
||||
|
|
@ -35,17 +32,14 @@ import permission from "../interfaces/permission";
|
|||
@Security("bearerAuth")
|
||||
@Response(
|
||||
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
|
||||
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
|
||||
)
|
||||
export class EvaluateResultController extends Controller {
|
||||
private assignDirectorRepository =
|
||||
AppDataSource.getRepository(AssignDirector);
|
||||
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
|
||||
private assignRepository = AppDataSource.getRepository(Assign);
|
||||
private evaluateChairmanRepository =
|
||||
AppDataSource.getRepository(EvaluateChairman);
|
||||
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman);
|
||||
private personalRepository = AppDataSource.getRepository(Personal);
|
||||
private evaluateResultRepository =
|
||||
AppDataSource.getRepository(EvaluateResult);
|
||||
private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult);
|
||||
|
||||
/**
|
||||
* API ข้อมูลตอนกดสร้างแบบรายงานการประเมินฯ
|
||||
|
|
@ -54,28 +48,17 @@ export class EvaluateResultController extends Controller {
|
|||
*
|
||||
*/
|
||||
@Get("create")
|
||||
async CreateEvaluate(
|
||||
@Query() assign_id: string,
|
||||
@Request() request: RequestWithUser
|
||||
) {
|
||||
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
|
||||
try {
|
||||
let _workflow = await new permission().Workflow(
|
||||
request,
|
||||
assign_id,
|
||||
"SYS_PROBATION"
|
||||
);
|
||||
if (_workflow == false)
|
||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION");
|
||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
|
||||
const assign = await this.assignRepository.findOne({
|
||||
relations: ["profile"],
|
||||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||
}
|
||||
|
||||
const profile = await (assign.profile
|
||||
|
|
@ -83,10 +66,7 @@ export class EvaluateResultController extends Controller {
|
|||
...assign.profile,
|
||||
id: assign.profile.personal_id,
|
||||
name:
|
||||
assign.profile.prefixName +
|
||||
assign.profile.firstName +
|
||||
" " +
|
||||
assign.profile.lastName,
|
||||
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
|
||||
Oc: assign.profile.organization,
|
||||
}
|
||||
: null);
|
||||
|
|
@ -97,10 +77,7 @@ export class EvaluateResultController extends Controller {
|
|||
});
|
||||
|
||||
if (!directorData) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||
}
|
||||
|
||||
let mentors = [];
|
||||
|
|
@ -113,10 +90,7 @@ export class EvaluateResultController extends Controller {
|
|||
personal_id: e.personal_id,
|
||||
dated: e.dated,
|
||||
name: e.fullname,
|
||||
label:
|
||||
e.fullname +
|
||||
" " +
|
||||
(e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||
position: e.position,
|
||||
posType: e.posType,
|
||||
posLevel: e.posLevel,
|
||||
|
|
@ -124,9 +98,7 @@ export class EvaluateResultController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
const commanderData = await (directorData.find(
|
||||
(x) => x.role == "commander"
|
||||
) ?? null);
|
||||
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
||||
|
||||
const commander =
|
||||
commanderData != null
|
||||
|
|
@ -146,9 +118,7 @@ export class EvaluateResultController extends Controller {
|
|||
}
|
||||
: null;
|
||||
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||
const chairman =
|
||||
chairmanData != null
|
||||
? {
|
||||
|
|
@ -158,9 +128,7 @@ export class EvaluateResultController extends Controller {
|
|||
label:
|
||||
chairmanData.fullname +
|
||||
" " +
|
||||
(chairmanData.position
|
||||
? `(${chairmanData.position}${chairmanData.posLevel})`
|
||||
: ""),
|
||||
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||
position: chairmanData.position,
|
||||
posType: chairmanData.posType,
|
||||
posLevel: chairmanData.posLevel,
|
||||
|
|
@ -181,10 +149,7 @@ export class EvaluateResultController extends Controller {
|
|||
});
|
||||
|
||||
if (!resultData) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลการประเมินผล"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล");
|
||||
}
|
||||
|
||||
const result = await Promise.all(
|
||||
|
|
@ -224,7 +189,7 @@ export class EvaluateResultController extends Controller {
|
|||
start_date: startDate,
|
||||
end_date: endDate,
|
||||
};
|
||||
})
|
||||
}),
|
||||
);
|
||||
|
||||
// const develop_complete = await (resultData.develop_orientation_score > 0 &&
|
||||
|
|
@ -251,7 +216,7 @@ export class EvaluateResultController extends Controller {
|
|||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +230,7 @@ export class EvaluateResultController extends Controller {
|
|||
async GetEvaluate(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query() assign_id: string,
|
||||
@Query() evaluate_no?: string
|
||||
@Query() evaluate_no?: string,
|
||||
) {
|
||||
try {
|
||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||
|
|
@ -299,10 +264,7 @@ export class EvaluateResultController extends Controller {
|
|||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||
}
|
||||
|
||||
const experimenteeData = await this.personalRepository.findOne({
|
||||
|
|
@ -332,11 +294,9 @@ export class EvaluateResultController extends Controller {
|
|||
experimenteeData.firstName +
|
||||
" " +
|
||||
experimenteeData.lastName,
|
||||
PositionLevel:
|
||||
experimenteeData.positionName + experimenteeData.positionLevelName,
|
||||
PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName,
|
||||
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-",
|
||||
OrganizationOrganization:
|
||||
splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-",
|
||||
OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-",
|
||||
Oc: experimenteeData.orgRootName,
|
||||
};
|
||||
|
||||
|
|
@ -346,10 +306,7 @@ export class EvaluateResultController extends Controller {
|
|||
});
|
||||
|
||||
if (!directorData) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||
}
|
||||
|
||||
let mentors = [];
|
||||
|
|
@ -362,10 +319,7 @@ export class EvaluateResultController extends Controller {
|
|||
personal_id: e.personal_id,
|
||||
dated: e.dated,
|
||||
name: e.fullname,
|
||||
label:
|
||||
e.fullname +
|
||||
" " +
|
||||
(e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||
position: e.position + e.posLevel,
|
||||
posType: e.posType,
|
||||
posLevel: e.posLevel,
|
||||
|
|
@ -401,9 +355,7 @@ export class EvaluateResultController extends Controller {
|
|||
posType: evaluate.authority_type,
|
||||
posLevel: evaluate.authority_level,
|
||||
};
|
||||
const chairmanData = await (directorData.find(
|
||||
(x) => x.role == "chairman"
|
||||
) ?? null);
|
||||
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||
const chairman =
|
||||
chairmanData != null
|
||||
? {
|
||||
|
|
@ -413,9 +365,7 @@ export class EvaluateResultController extends Controller {
|
|||
label:
|
||||
chairmanData.fullname +
|
||||
" " +
|
||||
(chairmanData.position
|
||||
? `(${chairmanData.position}${chairmanData.posLevel})`
|
||||
: ""),
|
||||
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||
position: chairmanData.position + chairmanData.posLevel,
|
||||
posType: chairmanData.posType,
|
||||
posLevel: chairmanData.posLevel,
|
||||
|
|
@ -433,7 +383,7 @@ export class EvaluateResultController extends Controller {
|
|||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -447,7 +397,7 @@ export class EvaluateResultController extends Controller {
|
|||
async PostData(
|
||||
@Query() assign_id: string,
|
||||
@Body() requestBody: CreateEvaluateResult,
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
try {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
|
|
@ -470,10 +420,7 @@ export class EvaluateResultController extends Controller {
|
|||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||
}
|
||||
|
||||
const postData: any = await {
|
||||
|
|
@ -483,8 +430,7 @@ export class EvaluateResultController extends Controller {
|
|||
no: requestBody.evaluate_no,
|
||||
personal_id: assign.personal_id,
|
||||
date_start: requestBody.start_date,
|
||||
expand_month:
|
||||
requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
|
||||
expand_month: requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
|
||||
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
|
|
@ -501,7 +447,7 @@ export class EvaluateResultController extends Controller {
|
|||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -515,7 +461,7 @@ export class EvaluateResultController extends Controller {
|
|||
async PatchData(
|
||||
@Query() assign_id: string,
|
||||
@Query() evaluate_no: number | string,
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
try {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
|
|
@ -525,10 +471,7 @@ export class EvaluateResultController extends Controller {
|
|||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||
}
|
||||
|
||||
const result = await this.evaluateResultRepository.findOne({
|
||||
|
|
@ -536,10 +479,7 @@ export class EvaluateResultController extends Controller {
|
|||
});
|
||||
|
||||
if (!result) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลผลการประเมิน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการประเมิน");
|
||||
}
|
||||
|
||||
const personal = await this.personalRepository.findOne({
|
||||
|
|
@ -581,7 +521,7 @@ export class EvaluateResultController extends Controller {
|
|||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -596,7 +536,7 @@ export class EvaluateResultController extends Controller {
|
|||
@Query() assign_id: string,
|
||||
@Query() evaluate_id: string,
|
||||
@Body() requestBody: CreateEvaluateResult,
|
||||
@Request() request: RequestWithUser
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
try {
|
||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||
|
|
@ -635,10 +575,7 @@ export class EvaluateResultController extends Controller {
|
|||
where: { id: assign_id },
|
||||
});
|
||||
if (!assign) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลแบบมอบหมายงาน"
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||
}
|
||||
const personal = await this.personalRepository.findOne({
|
||||
where: { personal_id: assign.personal_id },
|
||||
|
|
@ -680,7 +617,7 @@ export class EvaluateResultController extends Controller {
|
|||
} catch (error: any) {
|
||||
if (error instanceof HttpError) {
|
||||
throw error;
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
|
||||
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue