ออกคำสั่ง 10

This commit is contained in:
DESKTOP-2S5P7D1\Windows 10 2024-10-30 17:24:06 +07:00
parent 8032533c1b
commit ff3d42b451

View file

@ -1,55 +1,38 @@
import { import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query, Put, Post, Path } from "tsoa"
Controller, import { AppDataSource } from "../database/data-source"
Route, import HttpSuccess from "../interfaces/http-success"
Security, import HttpStatusCode from "../interfaces/http-status"
Tags, import HttpError from "../interfaces/http-error"
Body, import { RequestWithUser } from "../middlewares/user"
Request, import { DataPass, setLogDataDiff } from "../interfaces/utils"
SuccessResponse, import { Personal } from "../entities/Personal"
Response, import { Assign } from "../entities/Assign"
Get, import { EvaluateChairman } from "../entities/EvaluateChairman"
Query, import { EvaluateResult } from "../entities/EvaluateResult"
Put, import { EvaluateAssessor } from "../entities/EvaluateAssessor"
Post, import { AssignDirector } from "../entities/AssignDirector"
Path, import { EvaluateAchievement } from "../entities/EvaluateAchievement"
} from "tsoa"; import { EvaluateCommander } from "../entities/EvaluateCommander"
import { AppDataSource } from "../database/data-source"; import CallAPI from "../interfaces/call-api"
import HttpSuccess from "../interfaces/http-success"; import { Double, In } from "typeorm"
import HttpStatusCode from "../interfaces/http-status"; import Extension from "../interfaces/extension"
import HttpError from "../interfaces/http-error"; import { Appoint } from "../entities/Appoint"
import { RequestWithUser } from "../middlewares/user"; import { AppointDirector } from "../entities/AppointDirector"
import { DataPass, setLogDataDiff } from "../interfaces/utils";
import { Personal } from "../entities/Personal";
import { Assign } from "../entities/Assign";
import { EvaluateChairman } from "../entities/EvaluateChairman";
import { EvaluateResult } from "../entities/EvaluateResult";
import { EvaluateAssessor } from "../entities/EvaluateAssessor";
import { AssignDirector } from "../entities/AssignDirector";
import { EvaluateAchievement } from "../entities/EvaluateAchievement";
import { EvaluateCommander } from "../entities/EvaluateCommander";
import CallAPI from "../interfaces/call-api";
import { Double, In } from "typeorm";
import Extension from "../interfaces/extension";
import { Appoint } from "../entities/Appoint";
import { AppointDirector } from "../entities/AppointDirector";
@Route("api/v1/probation/report") @Route("api/v1/probation/report")
@Tags("Report") @Tags("Report")
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
export class ReportController extends Controller { export class ReportController extends Controller {
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman); private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman)
private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult); private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult)
private personalRepository = AppDataSource.getRepository(Personal); private personalRepository = AppDataSource.getRepository(Personal)
private evaluateAssessorRepository = AppDataSource.getRepository(EvaluateAssessor); private evaluateAssessorRepository = AppDataSource.getRepository(EvaluateAssessor)
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector); private assignDirectorRepository = AppDataSource.getRepository(AssignDirector)
private evaluateAchievementRepository = AppDataSource.getRepository(EvaluateAchievement); private evaluateAchievementRepository = AppDataSource.getRepository(EvaluateAchievement)
private evaluateCommanderRepository = AppDataSource.getRepository(EvaluateCommander); private evaluateCommanderRepository = AppDataSource.getRepository(EvaluateCommander)
private appointRepository = AppDataSource.getRepository(Appoint); private appointRepository = AppDataSource.getRepository(Appoint)
private AppointDirectorRepository = AppDataSource.getRepository(AppointDirector); private AppointDirectorRepository = AppDataSource.getRepository(AppointDirector)
/** /**
* API * API
@ -61,24 +44,24 @@ export class ReportController extends Controller {
async GetReport(@Query() assign_id: string) { async GetReport(@Query() assign_id: string) {
const evaluate = await this.evaluateChairmanRepository.findOne({ const evaluate = await this.evaluateChairmanRepository.findOne({
where: { assign_id }, where: { assign_id },
}); })
const result = await this.evaluateResultRepository.findOne({ const result = await this.evaluateResultRepository.findOne({
where: { assign_id }, where: { assign_id },
}); })
if (!evaluate || !result) { if (!evaluate || !result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการทดลองปฏิบัติราชการ"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการทดลองปฏิบัติราชการ")
} }
const develop_total_score = await (Number(evaluate.develop_orientation_score) + const develop_total_score = await (Number(evaluate.develop_orientation_score) +
Number(evaluate.develop_self_learning_score) + Number(evaluate.develop_self_learning_score) +
Number(evaluate.develop_training_seminar_score) + Number(evaluate.develop_training_seminar_score) +
Number(evaluate.develop_other_training_score)); Number(evaluate.develop_other_training_score))
const develop_total_percent = await (Number(evaluate.develop_orientation_percent) + const develop_total_percent = await (Number(evaluate.develop_orientation_percent) +
Number(evaluate.develop_orientation_percent) + Number(evaluate.develop_orientation_percent) +
Number(evaluate.develop_self_learning_percent) + Number(evaluate.develop_self_learning_percent) +
Number(evaluate.develop_training_seminar_percent)); Number(evaluate.develop_training_seminar_percent))
const data = await { const data = await {
develop_orientation_score: evaluate.develop_orientation_score, develop_orientation_score: evaluate.develop_orientation_score,
@ -105,9 +88,9 @@ export class ReportController extends Controller {
reason: result.reson, reason: result.reson,
pass_result: result.pass_result, pass_result: result.pass_result,
evaluate_date: result.chairman_dated, evaluate_date: result.chairman_dated,
}; }
return new HttpSuccess(data); return new HttpSuccess(data)
} }
/** /**
@ -120,15 +103,15 @@ export class ReportController extends Controller {
async GetPass() { async GetPass() {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 2 }, where: { probation_status: 2 },
}); })
let data: DataPass[] = []; let data: DataPass[] = []
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
const assign = await AppDataSource.getRepository(Assign).findOne({ const assign = await AppDataSource.getRepository(Assign).findOne({
select: ["date_start", "date_finish"], select: ["date_start", "date_finish"],
where: { personal_id: list.personal_id }, where: { personal_id: list.personal_id },
}); })
if (assign) if (assign)
data.push({ data.push({
@ -137,11 +120,11 @@ export class ReportController extends Controller {
name: `${list.prefixName}${list.firstName} ${list.lastName}`, name: `${list.prefixName}${list.firstName} ${list.lastName}`,
}, },
assign, assign,
}); })
}), })
); )
return new HttpSuccess(data); return new HttpSuccess(data)
} }
/** /**
@ -154,15 +137,15 @@ export class ReportController extends Controller {
async GetDataNotPass() { async GetDataNotPass() {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 3 }, where: { probation_status: 3 },
}); })
let data: DataPass[] = []; let data: DataPass[] = []
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
const assign = await AppDataSource.getRepository(Assign).findOne({ const assign = await AppDataSource.getRepository(Assign).findOne({
select: ["date_start", "date_finish"], select: ["date_start", "date_finish"],
where: { personal_id: list.personal_id }, where: { personal_id: list.personal_id },
}); })
if (assign) if (assign)
data.push({ data.push({
@ -171,11 +154,11 @@ export class ReportController extends Controller {
name: `${list.prefixName}${list.firstName} ${list.lastName}`, name: `${list.prefixName}${list.firstName} ${list.lastName}`,
}, },
assign, assign,
}); })
}), })
); )
return new HttpSuccess(data); return new HttpSuccess(data)
} }
/** /**
@ -189,9 +172,9 @@ export class ReportController extends Controller {
const data = await this.personalRepository.find({ const data = await this.personalRepository.find({
select: ["personal_id"], select: ["personal_id"],
where: { probation_status: 7 }, where: { probation_status: 7 },
}); })
return new HttpSuccess(data); return new HttpSuccess(data)
} }
/** /**
@ -201,32 +184,25 @@ export class ReportController extends Controller {
* *
*/ */
@Put("status") @Put("status")
async UpdateStatus( async UpdateStatus(@Query() personal_id: string, @Body() requestBody: { command_no: string }, @Request() request: RequestWithUser) {
@Query() personal_id: string,
@Body() requestBody: { command_no: string },
@Request() request: RequestWithUser,
) {
const personal = await this.personalRepository.findOne({ const personal = await this.personalRepository.findOne({
where: { personal_id }, where: { personal_id },
}); })
const before = personal; const before = personal
if (!personal) { if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
} }
personal.order_number = requestBody.command_no; personal.order_number = requestBody.command_no
personal.probation_status = 8; personal.probation_status = 8
personal.updateFullName = request.user.name; personal.updateFullName = request.user.name
personal.updateUserId = request.user.sub; personal.updateUserId = request.user.sub
this.personalRepository.save(personal, { data: request }); this.personalRepository.save(personal, { data: request })
setLogDataDiff(request, { before, after: personal }); setLogDataDiff(request, { before, after: personal })
const resultText = const resultText = (await personal.probation_status) === 2 ? "ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ" : "ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ"
(await personal.probation_status) === 2
? "ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ"
: "ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ";
await new CallAPI() await new CallAPI()
.PostData(request, "/placement/noti", { .PostData(request, "/placement/noti", {
@ -238,11 +214,11 @@ export class ReportController extends Controller {
isSendInbox: true, isSendInbox: true,
isSendNotification: true, isSendNotification: true,
}) })
.catch((error) => { .catch(error => {
console.error("Error calling API:", error); console.error("Error calling API:", error)
}); })
return new HttpSuccess(); return new HttpSuccess()
} }
/** /**
@ -252,28 +228,24 @@ export class ReportController extends Controller {
* *
*/ */
@Put("change-status") @Put("change-status")
async ChangeStatus( async ChangeStatus(@Query() personal_id: string, @Body() reqBody: { status: number }, @Request() request: RequestWithUser) {
@Query() personal_id: string,
@Body() reqBody: { status: number },
@Request() request: RequestWithUser,
) {
const personal = await this.personalRepository.findOne({ const personal = await this.personalRepository.findOne({
where: { personal_id }, where: { personal_id },
}); })
const before = personal; const before = personal
if (!personal) { if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
} }
personal.probation_status = await reqBody.status; personal.probation_status = await reqBody.status
personal.updateFullName = request.user.name; personal.updateFullName = request.user.name
personal.updateUserId = request.user.sub; personal.updateUserId = request.user.sub
await this.personalRepository.save(personal, { data: request }); await this.personalRepository.save(personal, { data: request })
setLogDataDiff(request, { before, after: personal }); setLogDataDiff(request, { before, after: personal })
return new HttpSuccess(); return new HttpSuccess()
} }
/** /**
@ -286,46 +258,46 @@ export class ReportController extends Controller {
async GetDataFormRecord(@Query() id: string) { async GetDataFormRecord(@Query() id: string) {
const evaluate = await this.evaluateAssessorRepository.findOne({ const evaluate = await this.evaluateAssessorRepository.findOne({
where: { id }, where: { id },
}); })
if (!evaluate) { if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const directorData = await this.assignDirectorRepository.findOne({ const directorData = await this.assignDirectorRepository.findOne({
select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"], select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"],
where: { personal_id: evaluate.director_id }, where: { personal_id: evaluate.director_id },
}); })
if (!directorData) { if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const director = await { const director = await {
...directorData, ...directorData,
name: directorData.fullname, name: directorData.fullname,
position: directorData.position, position: directorData.position,
}; }
const achievements = await this.evaluateAchievementRepository.find({ const achievements = await this.evaluateAchievementRepository.find({
select: ["evaluate_expect_level", "evaluate_output_level"], select: ["evaluate_expect_level", "evaluate_output_level"],
where: { evaluate_id: evaluate.id }, where: { evaluate_id: evaluate.id },
}); })
if (!achievements) { if (!achievements) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
let achievement: any = []; let achievement: any = []
await Promise.all( await Promise.all(
achievements.map(async (element) => { achievements.map(async element => {
const evaluate_expect_level = await { const evaluate_expect_level = await {
col1: element.evaluate_expect_level == 1 ? "/" : "", col1: element.evaluate_expect_level == 1 ? "/" : "",
col2: element.evaluate_expect_level == 2 ? "/" : "", col2: element.evaluate_expect_level == 2 ? "/" : "",
col3: element.evaluate_expect_level == 3 ? "/" : "", col3: element.evaluate_expect_level == 3 ? "/" : "",
col4: element.evaluate_expect_level == 4 ? "/" : "", col4: element.evaluate_expect_level == 4 ? "/" : "",
col5: element.evaluate_expect_level == 5 ? "/" : "", col5: element.evaluate_expect_level == 5 ? "/" : "",
}; }
const evaluate_output_level = await { const evaluate_output_level = await {
col1: element.evaluate_output_level == 1 ? "/" : "", col1: element.evaluate_output_level == 1 ? "/" : "",
@ -333,15 +305,15 @@ export class ReportController extends Controller {
col3: element.evaluate_output_level == 3 ? "/" : "", col3: element.evaluate_output_level == 3 ? "/" : "",
col4: element.evaluate_output_level == 4 ? "/" : "", col4: element.evaluate_output_level == 4 ? "/" : "",
col5: element.evaluate_output_level == 5 ? "/" : "", col5: element.evaluate_output_level == 5 ? "/" : "",
}; }
achievement.push({ achievement.push({
...element, ...element,
evaluate_expect_level, evaluate_expect_level,
evaluate_output_level, evaluate_output_level,
}); })
}), })
); )
const evaluateData = await { const evaluateData = await {
id: evaluate.id, id: evaluate.id,
@ -515,25 +487,25 @@ export class ReportController extends Controller {
updatedAt: evaluate.updatedAt, updatedAt: evaluate.updatedAt,
achievements: achievement, achievements: achievement,
role: director.role, role: director.role,
}; }
const assign = await AppDataSource.getRepository(Assign).findOne({ const assign = await AppDataSource.getRepository(Assign).findOne({
select: ["id", "personal_id", "round_no", "date_start", "date_finish"], select: ["id", "personal_id", "round_no", "date_start", "date_finish"],
where: { id: evaluate.assign_id }, where: { id: evaluate.assign_id },
}); })
if (!assign) { if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimenteeData = await this.personalRepository.findOne({ const experimenteeData = await this.personalRepository.findOne({
where: { where: {
personal_id: assign.personal_id, personal_id: assign.personal_id,
}, },
}); })
if (!experimenteeData) { if (!experimenteeData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimentee = await { const experimentee = await {
@ -545,15 +517,15 @@ export class ReportController extends Controller {
Department: "-", Department: "-",
OrganizationOrganization: experimenteeData.orgRootName, OrganizationOrganization: experimenteeData.orgRootName,
Oc: experimenteeData.organization, Oc: experimenteeData.organization,
}; }
const data = await { const data = await {
experimentee: experimentee ? experimentee : null, experimentee: experimentee ? experimentee : null,
director: director ? director : null, director: director ? director : null,
assign, assign,
evaluate: evaluateData, evaluate: evaluateData,
}; }
return new HttpSuccess(data); return new HttpSuccess(data)
} }
/** /**
@ -566,10 +538,10 @@ export class ReportController extends Controller {
async GetDataEvaluateCommander(@Query() id: string, @Request() request: RequestWithUser) { async GetDataEvaluateCommander(@Query() id: string, @Request() request: RequestWithUser) {
const evaluate = await this.evaluateCommanderRepository.findOne({ const evaluate = await this.evaluateCommanderRepository.findOne({
where: { id }, where: { id },
}); })
if (!evaluate) { if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const evaluateData = await { const evaluateData = await {
@ -746,25 +718,25 @@ export class ReportController extends Controller {
other_training: evaluate.other_training, other_training: evaluate.other_training,
createdAt: evaluate.createdAt, createdAt: evaluate.createdAt,
updatedAt: evaluate.updatedAt, updatedAt: evaluate.updatedAt,
}; }
const assign = await AppDataSource.getRepository(Assign).findOne({ const assign = await AppDataSource.getRepository(Assign).findOne({
select: ["id", "personal_id", "round_no", "date_start", "date_finish"], select: ["id", "personal_id", "round_no", "date_start", "date_finish"],
where: { id: evaluate.assign_id }, where: { id: evaluate.assign_id },
}); })
if (!assign) { if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimenteeData = await this.personalRepository.findOne({ const experimenteeData = await this.personalRepository.findOne({
where: { where: {
personal_id: assign.personal_id, personal_id: assign.personal_id,
}, },
}); })
if (!experimenteeData) { if (!experimenteeData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimentee = await { const experimentee = await {
@ -776,38 +748,29 @@ export class ReportController extends Controller {
Department: "-", Department: "-",
OrganizationOrganization: experimenteeData.orgRootName, OrganizationOrganization: experimenteeData.orgRootName,
Oc: experimenteeData.organization, Oc: experimenteeData.organization,
}; }
const commanderData = await this.assignDirectorRepository.findOne({ const commanderData = await this.assignDirectorRepository.findOne({
select: [ select: ["personal_id", "fullname", "position", "position", "posType", "posLevel", "role", "dated"],
"personal_id",
"fullname",
"position",
"position",
"posType",
"posLevel",
"role",
"dated",
],
where: { personal_id: evaluate.director_id }, where: { personal_id: evaluate.director_id },
}); })
if (!commanderData) { if (!commanderData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const commander = await { const commander = await {
...commanderData, ...commanderData,
name: commanderData.fullname, name: commanderData.fullname,
Position: commanderData.position, Position: commanderData.position,
}; }
return new HttpSuccess({ return new HttpSuccess({
experimentee: experimentee ? experimentee : null, experimentee: experimentee ? experimentee : null,
commander: commander ? commander : null, commander: commander ? commander : null,
assign, assign,
evaluate: evaluateData, evaluate: evaluateData,
}); })
} }
/** /**
@ -820,20 +783,20 @@ export class ReportController extends Controller {
async GetDataEvaluateChairman(@Query() id: string, @Request() request: RequestWithUser) { async GetDataEvaluateChairman(@Query() id: string, @Request() request: RequestWithUser) {
const evaluate = await this.evaluateChairmanRepository.findOne({ const evaluate = await this.evaluateChairmanRepository.findOne({
where: { id }, where: { id },
}); })
if (!evaluate) { if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const develop_total_score = await (Number(evaluate.develop_orientation_score) + const develop_total_score = await (Number(evaluate.develop_orientation_score) +
Number(evaluate.develop_self_learning_score) + Number(evaluate.develop_self_learning_score) +
Number(evaluate.develop_training_seminar_score) + Number(evaluate.develop_training_seminar_score) +
Number(evaluate.develop_other_training_score)); Number(evaluate.develop_other_training_score))
const develop_total_percent = await (Number(evaluate.develop_orientation_percent) + const develop_total_percent = await (Number(evaluate.develop_orientation_percent) +
Number(evaluate.develop_orientation_percent) + Number(evaluate.develop_orientation_percent) +
Number(evaluate.develop_self_learning_percent) + Number(evaluate.develop_self_learning_percent) +
Number(evaluate.develop_training_seminar_percent)); Number(evaluate.develop_training_seminar_percent))
const evaluateData = await { const evaluateData = await {
id: evaluate.id, id: evaluate.id,
@ -1010,25 +973,25 @@ export class ReportController extends Controller {
evaluate_result: evaluate.evaluate_result, evaluate_result: evaluate.evaluate_result,
createdAt: evaluate.createdAt, createdAt: evaluate.createdAt,
updatedAt: evaluate.updatedAt, updatedAt: evaluate.updatedAt,
}; }
const assign = await AppDataSource.getRepository(Assign).findOne({ const assign = await AppDataSource.getRepository(Assign).findOne({
select: ["id", "personal_id", "round_no", "date_start", "date_finish"], select: ["id", "personal_id", "round_no", "date_start", "date_finish"],
where: { id: evaluate.assign_id }, where: { id: evaluate.assign_id },
}); })
if (!assign) { if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimenteeData = await this.personalRepository.findOne({ const experimenteeData = await this.personalRepository.findOne({
where: { where: {
personal_id: assign.personal_id, personal_id: assign.personal_id,
}, },
}); })
if (!experimenteeData) { if (!experimenteeData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const experimentee = await { const experimentee = await {
@ -1040,35 +1003,35 @@ export class ReportController extends Controller {
Department: "-", Department: "-",
OrganizationOrganization: experimenteeData.orgRootName, OrganizationOrganization: experimenteeData.orgRootName,
Oc: experimenteeData.organization, Oc: experimenteeData.organization,
}; }
const directorData = await this.assignDirectorRepository.find({ const directorData = await this.assignDirectorRepository.find({
select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"], select: ["personal_id", "fullname", "position", "posType", "posLevel", "role", "dated"],
where: { assign_id: assign.id }, where: { assign_id: assign.id },
}); })
if (!directorData) { if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
} }
const director = await Promise.all( const director = await Promise.all(
directorData.map(async (element) => { directorData.map(async element => {
return { return {
...element, ...element,
name: element.fullname, name: element.fullname,
Position: element.position, Position: element.position,
}; }
}), })
); )
const mentorData = await (director.find((x) => x.role == "mentor") ?? null); const mentorData = await (director.find(x => x.role == "mentor") ?? null)
const mentor = mentorData != null ? mentorData : null; const mentor = mentorData != null ? mentorData : null
const commanderData = await (director.find((x) => x.role == "commander") ?? null); const commanderData = await (director.find(x => x.role == "commander") ?? null)
const commander = commanderData != null ? commanderData : null; const commander = commanderData != null ? commanderData : null
const chairmanData = await (director.find((x) => x.role == "chairman") ?? null); const chairmanData = await (director.find(x => x.role == "chairman") ?? null)
const chairman = chairmanData != null ? chairmanData : null; const chairman = chairmanData != null ? chairmanData : null
return new HttpSuccess({ return new HttpSuccess({
experimentee: experimentee ? experimentee : null, experimentee: experimentee ? experimentee : null,
@ -1077,7 +1040,7 @@ export class ReportController extends Controller {
director2: mentor ? mentor : null, director2: mentor ? mentor : null,
assign, assign,
evaluate: evaluateData, evaluate: evaluateData,
}); })
} }
@Post("command11/officer/report/excecute") @Post("command11/officer/report/excecute")
@ -1086,21 +1049,21 @@ export class ReportController extends Controller {
@Body() @Body()
body: { body: {
refIds: { refIds: {
refId: string; refId: string
commandAffectDate: Date | null; commandAffectDate: Date | null
commandNo: string | null; commandNo: string | null
commandId: string | null; commandId: string | null
commandYear: number; commandYear: number
templateDoc: string | null; templateDoc: string | null
amount: Double | null; amount: Double | null
positionSalaryAmount: Double | null; positionSalaryAmount: Double | null
mouthSalaryAmount: Double | null; mouthSalaryAmount: Double | null
}[]; }[]
}, }
) { ) {
await new CallAPI() await new CallAPI()
.PostData(request, "/org/command/excexute/salary-probation", { .PostData(request, "/org/command/excexute/salary-probation", {
data: body.refIds.map((v) => ({ data: body.refIds.map(v => ({
profileId: v.refId, profileId: v.refId,
commandId: v.commandId, commandId: v.commandId,
date: v.commandAffectDate, date: v.commandAffectDate,
@ -1111,59 +1074,59 @@ export class ReportController extends Controller {
mouthSalaryAmount: v.mouthSalaryAmount, mouthSalaryAmount: v.mouthSalaryAmount,
})), })),
}) })
.then(async (res) => { .then(async res => {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 8, personal_id: In(body.refIds.map((x) => x.refId)) }, where: { probation_status: 8, personal_id: In(body.refIds.map(x => x.refId)) },
});
await Promise.all(
lists.map(async (list) => {
list.probation_status = 9;
await this.personalRepository.save(list);
}),
);
}) })
.catch(() => {}); await Promise.all(
return new HttpSuccess(); lists.map(async list => {
list.probation_status = 9
await this.personalRepository.save(list)
})
)
})
.catch(() => {})
return new HttpSuccess()
} }
@Post("command11/officer/report") @Post("command11/officer/report")
public async command11( public async command11(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 2, personal_id: In(body.refIds) }, where: { probation_status: 2, personal_id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.probation_status = 8; list.probation_status = 8
await this.personalRepository.save(list); await this.personalRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command11/officer/report/delete") @Post("command11/officer/report/delete")
public async command11Delete( public async command11Delete(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 8, personal_id: In(body.refIds) }, where: { probation_status: 8, personal_id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.probation_status = 2; list.probation_status = 2
await this.personalRepository.save(list); await this.personalRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command12/officer/report/excecute") @Post("command12/officer/report/excecute")
@ -1172,21 +1135,21 @@ export class ReportController extends Controller {
@Body() @Body()
body: { body: {
refIds: { refIds: {
refId: string; refId: string
commandAffectDate: Date | null; commandAffectDate: Date | null
commandNo: string | null; commandNo: string | null
commandId: string | null; commandId: string | null
commandYear: number; commandYear: number
templateDoc: string | null; templateDoc: string | null
amount: Double | null; amount: Double | null
positionSalaryAmount: Double | null; positionSalaryAmount: Double | null
mouthSalaryAmount: Double | null; mouthSalaryAmount: Double | null
}[]; }[]
}, }
) { ) {
await new CallAPI() await new CallAPI()
.PostData(request, "/org/command/excexute/salary-probation-leave", { .PostData(request, "/org/command/excexute/salary-probation-leave", {
data: body.refIds.map((v) => ({ data: body.refIds.map(v => ({
profileId: v.refId, profileId: v.refId,
commandId: v.commandId, commandId: v.commandId,
date: v.commandAffectDate, date: v.commandAffectDate,
@ -1198,57 +1161,57 @@ export class ReportController extends Controller {
isGovernment: false, isGovernment: false,
})), })),
}) })
.then(async (res) => { .then(async res => {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 8, personal_id: In(body.refIds.map((x) => x.refId)) }, where: { probation_status: 8, personal_id: In(body.refIds.map(x => x.refId)) },
});
await Promise.all(
lists.map(async (list) => {
list.probation_status = 9;
await this.personalRepository.save(list);
}),
);
}) })
.catch(() => {}); await Promise.all(
return new HttpSuccess(); lists.map(async list => {
list.probation_status = 9
await this.personalRepository.save(list)
})
)
})
.catch(() => {})
return new HttpSuccess()
} }
@Post("command12/officer/report") @Post("command12/officer/report")
public async command12( public async command12(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 3, personal_id: In(body.refIds) }, where: { probation_status: 3, personal_id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.probation_status = 8; list.probation_status = 8
await this.personalRepository.save(list); await this.personalRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command12/officer/report/delete") @Post("command12/officer/report/delete")
public async command12Delete( public async command12Delete(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.personalRepository.find({ const lists = await this.personalRepository.find({
where: { probation_status: 8, personal_id: In(body.refIds) }, where: { probation_status: 8, personal_id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.probation_status = 3; list.probation_status = 3
await this.personalRepository.save(list); await this.personalRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command10/officer/report/excecute") @Post("command10/officer/report/excecute")
@ -1257,66 +1220,66 @@ export class ReportController extends Controller {
@Body() @Body()
body: { body: {
refIds: { refIds: {
refId: string; refId: string
commandAffectDate: Date | null; commandAffectDate: Date | null
commandNo: string | null; commandNo: string | null
commandId?: string | null; commandId?: string | null
commandYear: number; commandYear: number
templateDoc: string | null; templateDoc: string | null
amount: Double | null; amount: Double | null
positionSalaryAmount: Double | null; positionSalaryAmount: Double | null
mouthSalaryAmount: Double | null; mouthSalaryAmount: Double | null
}[]; }[]
}, }
) { ) {
const lists = await this.appointRepository.find({ const lists = await this.appointRepository.find({
where: { id: In(body.refIds.map((x) => x.refId)) }, where: { id: In(body.refIds.map(x => x.refId)) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.status = "DONE"; list.status = "DONE"
await this.appointRepository.save(list); await this.appointRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command10/officer/report") @Post("command10/officer/report")
public async command10( public async command10(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.appointRepository.find({ const lists = await this.appointRepository.find({
where: { id: In(body.refIds) }, where: { id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.status = "PENDING"; list.status = "REPORT"
await this.appointRepository.save(list); await this.appointRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Post("command10/officer/report/delete") @Post("command10/officer/report/delete")
public async command10Delete( public async command10Delete(
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() @Body()
body: { body: {
refIds: string[]; refIds: string[]
}, }
) { ) {
const lists = await this.appointRepository.find({ const lists = await this.appointRepository.find({
where: { id: In(body.refIds) }, where: { id: In(body.refIds) },
}); })
await Promise.all( await Promise.all(
lists.map(async (list) => { lists.map(async list => {
list.status = "REPORT"; list.status = "PENDING"
await this.appointRepository.save(list); await this.appointRepository.save(list)
}), })
); )
return new HttpSuccess(); return new HttpSuccess()
} }
@Get("command10/appoints/{refId}") @Get("command10/appoints/{refId}")
@ -1324,9 +1287,9 @@ export class ReportController extends Controller {
const lists = await this.AppointDirectorRepository.find({ const lists = await this.AppointDirectorRepository.find({
where: { appointId: refId }, where: { appointId: refId },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); })
const directors = await Promise.all( const directors = await Promise.all(
lists.map(async (director) => { lists.map(async director => {
return { return {
profileId: director.profileId, profileId: director.profileId,
name: director.name, name: director.name,
@ -1334,9 +1297,9 @@ export class ReportController extends Controller {
positionType: director.positionType, positionType: director.positionType,
positionLevel: director.positionLevel, positionLevel: director.positionLevel,
role: director.role === "chairman" ? "ประธาน" : "กรรมการ", role: director.role === "chairman" ? "ประธาน" : "กรรมการ",
}; }
}), })
); )
return new HttpSuccess(directors); return new HttpSuccess(directors)
} }
} }