error taos

This commit is contained in:
DESKTOP-2S5P7D1\Windows 10 2024-10-18 09:56:01 +07:00
parent 318839c1e9
commit 181f351860
12 changed files with 2553 additions and 3182 deletions

View file

@ -1,172 +1,150 @@
import {
Controller,
Route,
Security,
Tags,
Body,
Request,
SuccessResponse,
Response,
Get,
Put,
Post,
Path,
Delete,
} from "tsoa";
import { setLogDataDiff } from "../interfaces/utils";
import { Controller, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Put, Post, Path, Delete } from "tsoa"
import { setLogDataDiff } from "../interfaces/utils"
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint";
import { AppointDirector } from "../entities/AppointDirector";
import { AppDataSource } from "../database/data-source"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import HttpError from "../interfaces/http-error"
import permission from "../interfaces/permission"
import { RequestWithUser } from "../middlewares/user"
import { Appoint, CreateAppoint, Person, UpdateAppoint } from "../entities/Appoint"
import { AppointDirector } from "../entities/AppointDirector"
@Route("api/v1/probation/appoint")
@Tags("Appoint Director")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class AppointController extends Controller {
private appointRepository = AppDataSource.getRepository(Appoint);
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector);
private appointRepository = AppDataSource.getRepository(Appoint)
private appointDirectorRepository = AppDataSource.getRepository(AppointDirector)
/**
* API
*
* @summary
*
*/
@Get("")
async GetList(@Request() request: RequestWithUser) {
await new permission().PermissionList(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Get("")
async GetList(@Request() request: RequestWithUser) {
await new permission().PermissionList(request, "SYS_PROBATION")
const appoint = await this.appointRepository.find({});
const appoint = await this.appointRepository.find({})
return new HttpSuccess(appoint);
}
return new HttpSuccess(appoint)
}
/**
* API
*
* @summary
*
*/
@Get("list/{id}")
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
const appoint = await this.appointRepository.find({
relations: ["directors"],
where: { profileId: id, status: "DONE" },
});
/**
* API
*
* @summary
*
*/
@Get("list/{id}")
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
const appoint = await this.appointRepository.find({
relations: ["directors"],
where: { profileId: id, status: "DONE" },
})
return new HttpSuccess(appoint);
}
return new HttpSuccess(appoint)
}
/**
* API
*
* @summary
*
*/
@Post("")
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
await new permission().PermissionCreate(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Post("")
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
await new permission().PermissionCreate(request, "SYS_PROBATION")
const data: any = {
topic: requestBody.topic,
profileId: requestBody.profileId,
createdUserId: request.user.sub,
createdFullName: request.user.name,
};
const before = null;
const appoint = await this.appointRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: appoint });
const data: any = {
topic: requestBody.topic,
profileId: requestBody.profileId,
createdUserId: request.user.sub,
createdFullName: request.user.name,
}
const before = null
const appoint = await this.appointRepository.save(data, { data: request })
setLogDataDiff(request, { before, after: appoint })
return new HttpSuccess(appoint.id);
}
return new HttpSuccess(appoint.id)
}
/**
* API
*
* @summary API id
*
*/
@Get("{id}")
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API
*
* @summary API id
*
*/
@Get("{id}")
async GetById(@Request() request: RequestWithUser, @Path() id: string) {
await new permission().PermissionGet(request, "SYS_PROBATION")
const appoint = await this.appointRepository.findOne({
select: ["id", "topic", "status", "profileId"],
where: { id },
relations: ["directors"],
});
const appoint = await this.appointRepository.findOne({
select: ["id", "topic", "status", "profileId"],
where: { id },
relations: ["directors"],
})
return new HttpSuccess(appoint);
}
return new HttpSuccess(appoint)
}
/**
* API
*
* @summary
*
*/
@Put("{id}")
async Update(
@Request() request: RequestWithUser,
@Body() requestBody: UpdateAppoint,
@Path() id: string,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Put("{id}")
async Update(@Request() request: RequestWithUser, @Body() requestBody: UpdateAppoint, @Path() id: string) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
const appoint: any = await this.appointRepository.findOne({ where: { id } });
const appoint: any = await this.appointRepository.findOne({ where: { id } })
if (!appoint) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
}
if (!appoint) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ")
}
const before = appoint;
const before = appoint
appoint.topic = requestBody.topic;
appoint.updateUserId = request.user.sub;
appoint.updateFullName = request.user.name;
appoint.topic = requestBody.topic
appoint.updateUserId = request.user.sub
appoint.updateFullName = request.user.name
await this.appointDirectorRepository.delete({ appointId: id });
const directors = await requestBody.persons.map((x: Person) => ({
...x,
appointId: id,
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
}));
await this.appointDirectorRepository.save(directors);
await this.appointDirectorRepository.delete({ appointId: id })
const directors = await requestBody.persons.map((x: Person) => ({
...x,
appointId: id,
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
}))
await this.appointDirectorRepository.save(directors)
await this.appointRepository.save(appoint, { data: request });
setLogDataDiff(request, { before, after: appoint });
await this.appointRepository.save(appoint, { data: request })
setLogDataDiff(request, { before, after: appoint })
return new HttpSuccess();
}
return new HttpSuccess()
}
/**
* API
*
* @summary
*
*/
@Delete("{id}")
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Delete("{id}")
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_PROBATION")
await this.appointDirectorRepository.delete({ appointId: id });
await this.appointDirectorRepository.delete({ appointId: id })
const result = await this.appointRepository.delete({ id });
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
const result = await this.appointRepository.delete({ id })
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
return new HttpSuccess();
}
return new HttpSuccess()
}
}

File diff suppressed because it is too large Load diff

View file

@ -1,47 +1,32 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { findEndDate } from "../interfaces/utils";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body } from "tsoa"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import { RequestWithUser } from "../middlewares/user"
import { findEndDate } from "../interfaces/utils"
@Route("api/v1/probation/calculate")
@Tags("ฟอร์มมอบหมายงาน")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class CalculateController extends Controller {
/**
* API
*
* @summary
*
*/
@Post("assign-finish")
async AssignFinish(
@Body()
requestBody: {
month: number;
start_date: Date;
},
@Request() request: RequestWithUser,
) {
const { month, start_date } = requestBody;
const finish_date = findEndDate(month, start_date);
/**
* API
*
* @summary
*
*/
@Post("assign-finish")
async AssignFinish(
@Body()
requestBody: {
month: number
start_date: Date
},
@Request() request: RequestWithUser
) {
const { month, start_date } = requestBody
const finish_date = findEndDate(month, start_date)
return new HttpSuccess({ finish_date });
}
return new HttpSuccess({ finish_date })
}
}

View file

@ -1,331 +1,307 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { Knowledge, TypeKnowledge } from "../entities/Knowledge";
import { Skill, TypeSkill } from "../entities/Skill";
import { MapKnowledgeSkill } from "../entities/MapKnowledgeSkill";
import { Personal } from "../entities/Personal";
import { Law } from "../entities/Law";
import { Assign } from "../entities/Assign";
import permission from "../interfaces/permission";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Query } from "tsoa"
import { AppDataSource } from "../database/data-source"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import HttpError from "../interfaces/http-error"
import { RequestWithUser } from "../middlewares/user"
import { Knowledge, TypeKnowledge } from "../entities/Knowledge"
import { Skill, TypeSkill } from "../entities/Skill"
import { MapKnowledgeSkill } from "../entities/MapKnowledgeSkill"
import { Personal } from "../entities/Personal"
import { Law } from "../entities/Law"
import { Assign } from "../entities/Assign"
import permission from "../interfaces/permission"
@Route("api/v1/probation/data-options")
@Tags("Data Options")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class DataOptionController extends Controller {
private personalRepository = AppDataSource.getRepository(Personal);
private knowledgeRepository = AppDataSource.getRepository(Knowledge);
private mapKnowledgeSkillRepository = AppDataSource.getRepository(MapKnowledgeSkill);
private skillRepository = AppDataSource.getRepository(Skill);
private lawRepository = AppDataSource.getRepository(Law);
private assignRepository = AppDataSource.getRepository(Assign);
private personalRepository = AppDataSource.getRepository(Personal)
private knowledgeRepository = AppDataSource.getRepository(Knowledge)
private mapKnowledgeSkillRepository = AppDataSource.getRepository(MapKnowledgeSkill)
private skillRepository = AppDataSource.getRepository(Skill)
private lawRepository = AppDataSource.getRepository(Law)
private assignRepository = AppDataSource.getRepository(Assign)
/**
* API list
*
* @summary options
*
*/
@Get("knowledge")
async GetKnowledge(@Query() personal_id: string) {
const person = await this.personalRepository.findOne({
where: { personal_id },
});
/**
* API list
*
* @summary options
*
*/
@Get("knowledge")
async GetKnowledge(@Query() personal_id: string) {
const person = await this.personalRepository.findOne({
where: { personal_id },
})
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
}
let result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionName: person.positionName,
positionLevelName: person.positionLevelName,
active: 1,
},
});
let result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionName: person.positionName,
positionLevelName: person.positionLevelName,
active: 1,
},
})
if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionLevelName: person.positionLevelName,
active: 1,
},
});
}
if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({
where: {
positionLevelName: person.positionLevelName,
active: 1,
},
})
}
if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความรู้ที่ตรงกับตำแหน่ง");
}
if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความรู้ที่ตรงกับตำแหน่ง")
}
const knowledges = await this.knowledgeRepository.find({
where: { type: TypeKnowledge.PERFORMANCE, active: 1 },
});
const knowledges = await this.knowledgeRepository.find({
where: { type: TypeKnowledge.PERFORMANCE, active: 1 },
})
const knowledge = knowledges.map((knowledge) => ({
id: knowledge.id,
title: knowledge.title,
description:
result.knowlage_performance_level == 1
? knowledge.level1
: result.knowlage_performance_level == 2
? knowledge.level2
: result.knowlage_performance_level == 3
? knowledge.level3
: result.knowlage_performance_level == 4
? knowledge.level4
: knowledge.level5,
level: result.knowlage_performance_level,
}));
const knowledge = knowledges.map(knowledge => ({
id: knowledge.id,
title: knowledge.title,
description:
result.knowlage_performance_level == 1
? knowledge.level1
: result.knowlage_performance_level == 2
? knowledge.level2
: result.knowlage_performance_level == 3
? knowledge.level3
: result.knowlage_performance_level == 4
? knowledge.level4
: knowledge.level5,
level: result.knowlage_performance_level,
}))
return new HttpSuccess(knowledge);
}
return new HttpSuccess(knowledge)
}
/**
* API
*
* @summary options
*
*/
@Get("skill")
async GetSkill(@Query() personal_id: string) {
const person = await this.personalRepository.findOne({
where: { personal_id },
});
/**
* API
*
* @summary options
*
*/
@Get("skill")
async GetSkill(@Query() personal_id: string) {
const person = await this.personalRepository.findOne({
where: { personal_id },
})
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
}
let result = await this.mapKnowledgeSkillRepository.findOne({
select: [
"skill_computer_level",
"skill_english_level",
"skill_information_level",
"skill_resourse_level",
],
where: {
positionName: person.positionName,
positionLevelName: person.positionLevelName,
active: 1,
},
});
let result = await this.mapKnowledgeSkillRepository.findOne({
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"],
where: {
positionName: person.positionName,
positionLevelName: person.positionLevelName,
active: 1,
},
})
if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({
select: [
"skill_computer_level",
"skill_english_level",
"skill_information_level",
"skill_resourse_level",
],
where: {
positionLevelName: person.positionLevelName,
active: 1,
},
});
}
if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"],
where: {
positionLevelName: person.positionLevelName,
active: 1,
},
})
}
if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง");
}
if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง")
}
const computerData = await this.skillRepository.findOne({
where: { type: TypeSkill.COMPUTER, active: 1 },
});
const computerData = await this.skillRepository.findOne({
where: { type: TypeSkill.COMPUTER, active: 1 },
})
if (!computerData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์");
}
const computer = await {
id: computerData.id,
title: computerData.title,
level_description:
result.skill_computer_level == 1
? computerData.level1
: result.skill_computer_level == 2
? computerData.level2
: result.skill_computer_level == 3
? computerData.level3
: result.skill_computer_level == 4
? computerData.level4
: computerData.level5,
level: result.skill_computer_level,
};
if (!computerData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์")
}
const computer = await {
id: computerData.id,
title: computerData.title,
level_description:
result.skill_computer_level == 1
? computerData.level1
: result.skill_computer_level == 2
? computerData.level2
: result.skill_computer_level == 3
? computerData.level3
: result.skill_computer_level == 4
? computerData.level4
: computerData.level5,
level: result.skill_computer_level,
}
const englishData = await this.skillRepository.findOne({
where: { type: TypeSkill.ENG, active: 1 },
});
const englishData = await this.skillRepository.findOne({
where: { type: TypeSkill.ENG, active: 1 },
})
if (!englishData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ");
}
if (!englishData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ")
}
const english = await {
id: englishData.id,
title: englishData.title,
level_description:
result.skill_english_level == 1
? englishData.level1
: result.skill_english_level == 2
? englishData.level2
: result.skill_english_level == 3
? englishData.level3
: result.skill_english_level == 4
? englishData.level4
: englishData.level5,
level: result.skill_english_level,
};
const english = await {
id: englishData.id,
title: englishData.title,
level_description:
result.skill_english_level == 1
? englishData.level1
: result.skill_english_level == 2
? englishData.level2
: result.skill_english_level == 3
? englishData.level3
: result.skill_english_level == 4
? englishData.level4
: englishData.level5,
level: result.skill_english_level,
}
const informationData = await this.skillRepository.findOne({
where: { type: TypeSkill.INFORMATION, active: 1 },
});
const informationData = await this.skillRepository.findOne({
where: { type: TypeSkill.INFORMATION, active: 1 },
})
if (!informationData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (!informationData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
}
const information = await {
id: informationData.id,
title: informationData.title,
level_description:
result.skill_information_level == 1
? informationData.level1
: result.skill_information_level == 2
? informationData.level2
: result.skill_information_level == 3
? informationData.level3
: result.skill_information_level == 4
? informationData.level4
: informationData.level5,
level: result.skill_information_level,
};
const information = await {
id: informationData.id,
title: informationData.title,
level_description:
result.skill_information_level == 1
? informationData.level1
: result.skill_information_level == 2
? informationData.level2
: result.skill_information_level == 3
? informationData.level3
: result.skill_information_level == 4
? informationData.level4
: informationData.level5,
level: result.skill_information_level,
}
const resourseData = await this.skillRepository.findOne({
where: { type: TypeSkill.RESOURSE, active: 1 },
});
if (!resourseData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
const resourseData = await this.skillRepository.findOne({
where: { type: TypeSkill.RESOURSE, active: 1 },
})
if (!resourseData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
}
const resourse = await {
id: resourseData.id,
title: resourseData.title,
level_description:
result.skill_resourse_level == 1
? resourseData.level1
: result.skill_resourse_level == 2
? resourseData.level2
: result.skill_resourse_level == 3
? resourseData.level3
: result.skill_resourse_level == 4
? resourseData.level4
: resourseData.level5,
level: result.skill_resourse_level,
};
const resourse = await {
id: resourseData.id,
title: resourseData.title,
level_description:
result.skill_resourse_level == 1
? resourseData.level1
: result.skill_resourse_level == 2
? resourseData.level2
: result.skill_resourse_level == 3
? resourseData.level3
: result.skill_resourse_level == 4
? resourseData.level4
: resourseData.level5,
level: result.skill_resourse_level,
}
return new HttpSuccess({
computer,
english,
information,
resourse,
});
}
return new HttpSuccess({
computer,
english,
information,
resourse,
})
}
/**
* API list
*
* @summary options
*
*/
@Get("law")
async GetLaw(@Query() personal_id: string) {
const results = await this.lawRepository.find({
select: ["id", "parent_id", "description", "status_select"],
where: {
active: 1,
},
});
/**
* API list
*
* @summary options
*
*/
@Get("law")
async GetLaw(@Query() personal_id: string) {
const results = await this.lawRepository.find({
select: ["id", "parent_id", "description", "status_select"],
where: {
active: 1,
},
})
if (!results) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (!results) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
}
const result = await results.map((v) => ({
...v,
checked: 0,
}));
const result = await results.map(v => ({
...v,
checked: 0,
}))
return new HttpSuccess(result);
}
return new HttpSuccess(result)
}
/**
* API
*
* @summary
*
*/
@Get("new-assign")
async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Get("new-assign")
async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION")
const person = await this.personalRepository.findOne({
select: [
"personal_id",
"prefixName",
"firstName",
"lastName",
"posNo",
"positionName",
"positionLevelName",
"positionLineName",
"isProbation",
"orgRootName",
"organization",
"createdAt",
"updatedAt",
],
where: { personal_id },
});
const person = await this.personalRepository.findOne({
select: [
"personal_id",
"prefixName",
"firstName",
"lastName",
"posNo",
"positionName",
"positionLevelName",
"positionLineName",
"isProbation",
"orgRootName",
"organization",
"createdAt",
"updatedAt",
],
where: { personal_id },
})
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
}
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
}
const assign = await this.assignRepository.count({
where: {
personal_id,
},
});
const assign = await this.assignRepository.count({
where: {
personal_id,
},
})
const responsePerson = {
id: person.personal_id,
...person,
};
const responsePerson = {
id: person.personal_id,
...person,
}
return new HttpSuccess({
person: responsePerson,
assign_no: assign + 1,
assign_month: 6,
});
}
return new HttpSuccess({
person: responsePerson,
assign_no: assign + 1,
assign_month: 6,
})
}
}

View file

@ -1,496 +1,428 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
Query,
Put,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
import { AppDataSource } from "../database/data-source";
import { AssignDirector } from "../entities/AssignDirector";
import HttpError from "../interfaces/http-error";
import { Assign } from "../entities/Assign";
import { Personal } from "../entities/Personal";
import CallAPI from "../interfaces/call-api";
import { CreateEvaluateChairman, EvaluateChairman } from "../entities/EvaluateChairman";
import permission from "../interfaces/permission";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query, Put } from "tsoa"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import { RequestWithUser } from "../middlewares/user"
import { findEndDate, setLogDataDiff } from "../interfaces/utils"
import { AppDataSource } from "../database/data-source"
import { AssignDirector } from "../entities/AssignDirector"
import HttpError from "../interfaces/http-error"
import { Assign } from "../entities/Assign"
import { Personal } from "../entities/Personal"
import CallAPI from "../interfaces/call-api"
import { CreateEvaluateChairman, EvaluateChairman } from "../entities/EvaluateChairman"
import permission from "../interfaces/permission"
@Route("api/v1/probation/evaluate-chairman")
@Tags("แบบประเมินผล (คณะกรรมการ)")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class EvaluateChairmanController extends Controller {
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
private assignRepository = AppDataSource.getRepository(Assign);
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman);
private personalRepository = AppDataSource.getRepository(Personal);
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector)
private assignRepository = AppDataSource.getRepository(Assign)
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman)
private personalRepository = AppDataSource.getRepository(Personal)
/**
* API ()
*
* @summary ()
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION")
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director_id = director.personal_id;
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name:
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null);
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name: assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null)
const evaluate_amount = await this.evaluateChairmanRepository.count({
where: {
assign_id,
director_id,
},
});
const evaluate_no = await (evaluate_amount + 1);
const start_date =
evaluate_amount == 0
? assign.date_start
: findEndDate(evaluate_amount * 3, assign.date_start);
const evaluate_amount = await this.evaluateChairmanRepository.count({
where: {
assign_id,
director_id,
},
})
const evaluate_no = await (evaluate_amount + 1)
const start_date = evaluate_amount == 0 ? assign.date_start : findEndDate(evaluate_amount * 3, assign.date_start)
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
});
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
})
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
}
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน")
}
let mentors = [];
const mentorList = await directorData.filter((x) => x.role == "mentor");
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index];
let mentors = []
const mentorList = await directorData.filter(x => x.role == "mentor")
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index]
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label:
e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
});
}
}
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label: e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
})
}
}
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
const commanderData = await (directorData.find(x => x.role == "commander") ?? null)
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label:
commanderData.fullname +
" " +
(commanderData.position
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
: ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null;
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label: commanderData.fullname + " " + (commanderData.position ? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})` : ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label:
chairmanData.fullname +
" " +
(chairmanData.position
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
: ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null;
const chairmanData = await (directorData.find(x => x.role == "chairman") ?? null)
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label: chairmanData.fullname + " " + (chairmanData.position ? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})` : ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null
return new HttpSuccess({
person: profile ? profile : null,
assign,
evaluate_no: evaluate_no,
start_date: start_date,
end_date: findEndDate(3, start_date),
commander,
mentors,
chairman,
});
}
return new HttpSuccess({
person: profile ? profile : null,
assign,
evaluate_no: evaluate_no,
start_date: start_date,
end_date: findEndDate(3, start_date),
commander,
mentors,
chairman,
})
}
/**
* API ()
*
* @summary ()
*
*/
@Get("")
async GetEvaluate(
@Request() request: RequestWithUser,
@Query() assign_id: string,
@Query() evaluate_no?: string,
) {
await new permission().PermissionGet(request, "SYS_PROBATION");
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director_id = director.personal_id;
let evaluate: any = null;
if (evaluate_no) {
evaluate = await this.evaluateChairmanRepository.findOne({
where: {
director_id,
assign_id,
no: evaluate_no,
},
});
} else {
evaluate = await this.evaluateChairmanRepository.find({
where: {
director_id,
assign_id,
},
});
/**
* API ()
*
* @summary ()
*
*/
@Get("")
async GetEvaluate(@Request() request: RequestWithUser, @Query() assign_id: string, @Query() evaluate_no?: string) {
await new permission().PermissionGet(request, "SYS_PROBATION")
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id
let evaluate: any = null
if (evaluate_no) {
evaluate = await this.evaluateChairmanRepository.findOne({
where: {
director_id,
assign_id,
no: evaluate_no,
},
})
} else {
evaluate = await this.evaluateChairmanRepository.find({
where: {
director_id,
assign_id,
},
})
if (evaluate)
evaluate = await evaluate.map((element: EvaluateChairman) => ({
...element,
no: Number(element.no),
}));
}
if (evaluate)
evaluate = await evaluate.map((element: EvaluateChairman) => ({
...element,
no: Number(element.no),
}))
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน")
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const experimenteeData = await this.personalRepository.find({
select: [
"personal_id",
"prefixName",
"firstName",
"lastName",
"positionName",
"positionLevelName",
"organization",
],
where: { personal_id: assign.personal_id },
});
const experimenteeData = await this.personalRepository.find({
select: ["personal_id", "prefixName", "firstName", "lastName", "positionName", "positionLevelName", "organization"],
where: { personal_id: assign.personal_id },
})
const experimentee = await experimenteeData.map((element) => ({
...element,
name: element.prefixName + element.firstName + " " + element.lastName,
Oc: element.organization,
}));
const experimentee = await experimenteeData.map(element => ({
...element,
name: element.prefixName + element.firstName + " " + element.lastName,
Oc: element.organization,
}))
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
});
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
})
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
}
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน")
}
let mentors = [];
const mentorList = await directorData.filter((x) => x.role == "mentor");
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index];
let mentors = []
const mentorList = await directorData.filter(x => x.role == "mentor")
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index]
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label:
e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
});
}
}
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label: e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
})
}
}
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
const commanderData = await (directorData.find(x => x.role == "commander") ?? null)
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label:
commanderData.fullname +
" " +
(commanderData.position
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
: ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null;
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label: commanderData.fullname + " " + (commanderData.position ? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})` : ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label:
chairmanData.fullname +
" " +
(chairmanData.position
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
: ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null;
const chairmanData = await (directorData.find(x => x.role == "chairman") ?? null)
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label: chairmanData.fullname + " " + (chairmanData.position ? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})` : ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null
return new HttpSuccess({
experimentee: experimentee,
mentors: mentors,
commander: commander,
chairman: chairman,
assign,
evaluate,
});
}
return new HttpSuccess({
experimentee: experimentee,
mentors: mentors,
commander: commander,
chairman: chairman,
assign,
evaluate,
})
}
/**
* API ()
*
* @summary ()
*
*/
@Post("")
async PostData(
@Query() assign_id: string,
@Body() requestBody: CreateEvaluateChairman,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Post("")
async PostData(@Query() assign_id: string, @Body() requestBody: CreateEvaluateChairman, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id;
const director_id = director.personal_id
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: requestBody.evaluate_no,
date_start: requestBody.start_date,
personal_id: assign.personal_id,
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: requestBody.evaluate_no,
date_start: requestBody.start_date,
personal_id: assign.personal_id,
achievement_other_desc: requestBody.achievement_other
? requestBody.achievement_other.text
: "",
achievement_other_level: requestBody.achievement_other
? Number(requestBody.achievement_other.level)
: 0,
behavior_other_desc: requestBody.behavior_orther.text,
behavior_other_level:
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
achievement_other_desc: requestBody.achievement_other ? requestBody.achievement_other.text : "",
achievement_other_level: requestBody.achievement_other ? Number(requestBody.achievement_other.level) : 0,
behavior_other_desc: requestBody.behavior_orther.text,
behavior_other_level: requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
};
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
}
await this.evaluateChairmanRepository.save(postData, {
data: request,
});
setLogDataDiff(request, { before: null, after: postData });
await this.evaluateChairmanRepository.save(postData, {
data: request,
})
setLogDataDiff(request, { before: null, after: postData })
if (Number(requestBody.evaluate_no) < 2) {
// #noted cronjob
// แจ้งประธานเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
var dateSend = await findEndDate(3, requestBody.start_date);
const nextNo = await (Number(requestBody.evaluate_no) + 1);
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับคณะกรรมการ) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
receiverUserId: director_id,
payload: "",
isSendMail: true,
isSendInbox: true,
receiveDate: dateSend,
})
.catch((error) => {
console.error("Error calling API:", error);
});
}
if (Number(requestBody.evaluate_no) < 2) {
// #noted cronjob
// แจ้งประธานเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
var dateSend = await findEndDate(3, requestBody.start_date)
const nextNo = await (Number(requestBody.evaluate_no) + 1)
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับคณะกรรมการ) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
receiverUserId: director_id,
payload: "",
isSendMail: true,
isSendInbox: true,
receiveDate: dateSend,
})
.catch(error => {
console.error("Error calling API:", error)
})
}
return new HttpSuccess();
}
return new HttpSuccess()
}
/**
* API ()
*
* @summary ()
*
*/
@Put("")
async UpdateData(
// @Query() assign_id: string,
@Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateChairman,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Put("")
async UpdateData(
// @Query() assign_id: string,
@Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateChairman,
@Request() request: RequestWithUser
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
let evaluate = await this.evaluateChairmanRepository.findOne({
where: { id: evaluate_id },
});
let evaluate = await this.evaluateChairmanRepository.findOne({
where: { id: evaluate_id },
})
const before = evaluate;
const before = evaluate
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน")
}
evaluate.chairman_dated = requestBody.chairman_dated;
evaluate.director1_dated = requestBody.director1_dated;
evaluate.director2_dated = requestBody.director2_dated;
evaluate.knowledge_level = requestBody.knowledge_level;
evaluate.apply_level = requestBody.apply_level;
evaluate.success_level = requestBody.success_level;
evaluate.achievement_other_desc = requestBody.achievement_other
? requestBody.achievement_other.text
: "";
evaluate.achievement_other_level =
requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0;
evaluate.chairman_dated = requestBody.chairman_dated
evaluate.director1_dated = requestBody.director1_dated
evaluate.director2_dated = requestBody.director2_dated
evaluate.knowledge_level = requestBody.knowledge_level
evaluate.apply_level = requestBody.apply_level
evaluate.success_level = requestBody.success_level
evaluate.achievement_other_desc = requestBody.achievement_other ? requestBody.achievement_other.text : ""
evaluate.achievement_other_level = requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0
evaluate.conduct1_level = requestBody.conduct1_level;
evaluate.conduct2_level = requestBody.conduct2_level;
evaluate.conduct3_level = requestBody.conduct3_level;
evaluate.conduct4_level = requestBody.conduct4_level;
evaluate.moral1_level = requestBody.moral1_level;
evaluate.moral2_level = requestBody.moral2_level;
evaluate.moral3_level = requestBody.moral3_level;
evaluate.discipline1_level = requestBody.discipline1_level;
evaluate.discipline2_level = requestBody.discipline2_level;
evaluate.discipline3_level = requestBody.discipline3_level;
evaluate.discipline4_level = requestBody.discipline4_level;
evaluate.discipline5_level = requestBody.discipline5_level;
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
evaluate.behavior_other_level =
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0;
evaluate.develop_orientation_score = requestBody.develop_orientation_score;
evaluate.develop_self_learning_score = requestBody.develop_self_learning_score;
evaluate.develop_training_seminar_score = requestBody.develop_training_seminar_score;
evaluate.develop_other_training_score = requestBody.develop_other_training_score;
evaluate.develop_orientation_percent = requestBody.develop_orientation_percent;
evaluate.develop_self_learning_percent = requestBody.develop_self_learning_percent;
evaluate.develop_training_seminar_percent = requestBody.develop_training_seminar_percent;
evaluate.develop_other_training_percent = requestBody.develop_other_training_percent;
evaluate.develop_result = requestBody.develop_result;
evaluate.achievement_score = requestBody.achievement_score;
evaluate.achievement_score_total = requestBody.achievement_score_total;
evaluate.achievement_percent = requestBody.achievement_percent;
evaluate.achievement_result = requestBody.achievement_result;
evaluate.behavior_score = requestBody.behavior_score;
evaluate.behavior_score_total = requestBody.behavior_score_total;
evaluate.behavior_percent = requestBody.behavior_percent;
evaluate.behavior_result = requestBody.behavior_result;
evaluate.sum_score = requestBody.sum_score;
evaluate.sum_percent = requestBody.sum_percent;
evaluate.evaluate_result = requestBody.evaluate_result;
evaluate.conduct1_level = requestBody.conduct1_level
evaluate.conduct2_level = requestBody.conduct2_level
evaluate.conduct3_level = requestBody.conduct3_level
evaluate.conduct4_level = requestBody.conduct4_level
evaluate.moral1_level = requestBody.moral1_level
evaluate.moral2_level = requestBody.moral2_level
evaluate.moral3_level = requestBody.moral3_level
evaluate.discipline1_level = requestBody.discipline1_level
evaluate.discipline2_level = requestBody.discipline2_level
evaluate.discipline3_level = requestBody.discipline3_level
evaluate.discipline4_level = requestBody.discipline4_level
evaluate.discipline5_level = requestBody.discipline5_level
evaluate.behavior_other_desc = requestBody.behavior_orther.text
evaluate.behavior_other_level = requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0
evaluate.develop_orientation_score = requestBody.develop_orientation_score
evaluate.develop_self_learning_score = requestBody.develop_self_learning_score
evaluate.develop_training_seminar_score = requestBody.develop_training_seminar_score
evaluate.develop_other_training_score = requestBody.develop_other_training_score
evaluate.develop_orientation_percent = requestBody.develop_orientation_percent
evaluate.develop_self_learning_percent = requestBody.develop_self_learning_percent
evaluate.develop_training_seminar_percent = requestBody.develop_training_seminar_percent
evaluate.develop_other_training_percent = requestBody.develop_other_training_percent
evaluate.develop_result = requestBody.develop_result
evaluate.achievement_score = requestBody.achievement_score
evaluate.achievement_score_total = requestBody.achievement_score_total
evaluate.achievement_percent = requestBody.achievement_percent
evaluate.achievement_result = requestBody.achievement_result
evaluate.behavior_score = requestBody.behavior_score
evaluate.behavior_score_total = requestBody.behavior_score_total
evaluate.behavior_percent = requestBody.behavior_percent
evaluate.behavior_result = requestBody.behavior_result
evaluate.sum_score = requestBody.sum_score
evaluate.sum_percent = requestBody.sum_percent
evaluate.evaluate_result = requestBody.evaluate_result
evaluate.updateUserId = request.user.sub;
evaluate.updateFullName = request.user.name;
evaluate.updateUserId = request.user.sub
evaluate.updateFullName = request.user.name
await this.evaluateChairmanRepository.save(evaluate, { data: request });
setLogDataDiff(request, { before, after: evaluate });
await this.evaluateChairmanRepository.save(evaluate, { data: request })
setLogDataDiff(request, { before, after: evaluate })
return new HttpSuccess();
}
return new HttpSuccess()
}
}

View file

@ -1,394 +1,348 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
Query,
Put,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { findEndDate, setLogDataDiff } from "../interfaces/utils";
import { AppDataSource } from "../database/data-source";
import { AssignDirector } from "../entities/AssignDirector";
import HttpError from "../interfaces/http-error";
import { Assign } from "../entities/Assign";
import { CreateEvaluateCommander, EvaluateCommander } from "../entities/EvaluateCommander";
import { Personal } from "../entities/Personal";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query, Put } from "tsoa"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import { RequestWithUser } from "../middlewares/user"
import { findEndDate, setLogDataDiff } from "../interfaces/utils"
import { AppDataSource } from "../database/data-source"
import { AssignDirector } from "../entities/AssignDirector"
import HttpError from "../interfaces/http-error"
import { Assign } from "../entities/Assign"
import { CreateEvaluateCommander, EvaluateCommander } from "../entities/EvaluateCommander"
import { Personal } from "../entities/Personal"
import CallAPI from "../interfaces/call-api"
import permission from "../interfaces/permission"
@Route("api/v1/probation/evaluate")
@Tags("แบบประเมินผล (ผู้บังคับบัญชา)")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class EvaluateController extends Controller {
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
private assignRepository = AppDataSource.getRepository(Assign);
private evaluateCommanderRepository = AppDataSource.getRepository(EvaluateCommander);
private personalRepository = AppDataSource.getRepository(Personal);
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector)
private assignRepository = AppDataSource.getRepository(Assign)
private evaluateCommanderRepository = AppDataSource.getRepository(EvaluateCommander)
private personalRepository = AppDataSource.getRepository(Personal)
/**
* API ()
*
* @summary ()
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION")
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director_id = director.personal_id;
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name:
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null);
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name: assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null)
const evaluate_amount = await this.evaluateCommanderRepository.count({
where: {
assign_id,
director_id,
},
});
const evaluate_no = await (evaluate_amount + 1);
const start_date =
evaluate_amount == 0
? assign.date_start
: findEndDate(evaluate_amount * 3, assign.date_start);
const evaluate_amount = await this.evaluateCommanderRepository.count({
where: {
assign_id,
director_id,
},
})
const evaluate_no = await (evaluate_amount + 1)
const start_date = evaluate_amount == 0 ? assign.date_start : findEndDate(evaluate_amount * 3, assign.date_start)
const commanderData = await this.assignDirectorRepository.findOne({
select: ["personal_id", "dated", "fullname", "position", "posType", "posLevel"],
where: { personal_id: director_id },
});
if (!commanderData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้บังคับบัญชา");
}
const commander = await {
...commanderData,
name: commanderData.fullname,
label: `${commanderData.fullname} (${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`,
};
const commanderData = await this.assignDirectorRepository.findOne({
select: ["personal_id", "dated", "fullname", "position", "posType", "posLevel"],
where: { personal_id: director_id },
})
if (!commanderData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้บังคับบัญชา")
}
const commander = await {
...commanderData,
name: commanderData.fullname,
label: `${commanderData.fullname} (${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`,
}
return new HttpSuccess({
person: profile,
assign,
evaluate_no: evaluate_no,
start_date: start_date,
end_date: findEndDate(3, start_date),
director: commander,
});
}
return new HttpSuccess({
person: profile,
assign,
evaluate_no: evaluate_no,
start_date: start_date,
end_date: findEndDate(3, start_date),
director: commander,
})
}
/**
* API ()
*
* @summary ()
*
*/
@Get("")
async GetEvaluate(
@Request() request: RequestWithUser,
@Query() assign_id: string,
@Query() evaluate_no?: string,
) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Get("")
async GetEvaluate(@Request() request: RequestWithUser, @Query() assign_id: string, @Query() evaluate_no?: string) {
await new permission().PermissionGet(request, "SYS_PROBATION")
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director_id = director.personal_id;
let evaluate: any = null;
if (evaluate_no) {
evaluate = await this.evaluateCommanderRepository.findOne({
where: {
director_id,
assign_id,
no: evaluate_no,
},
});
} else {
evaluate = await this.evaluateCommanderRepository.find({
where: {
director_id,
assign_id,
},
});
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id
let evaluate: any = null
if (evaluate_no) {
evaluate = await this.evaluateCommanderRepository.findOne({
where: {
director_id,
assign_id,
no: evaluate_no,
},
})
} else {
evaluate = await this.evaluateCommanderRepository.find({
where: {
director_id,
assign_id,
},
})
if (evaluate)
evaluate = await evaluate.map((element: EvaluateCommander) => ({
...element,
no: Number(element.no),
}));
}
if (evaluate)
evaluate = await evaluate.map((element: EvaluateCommander) => ({
...element,
no: Number(element.no),
}))
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน")
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
// const profile = await (assign.profile
// ? {
// ...assign.profile,
// id: assign.profile.personal_id,
// name:
// assign.profile.prefixName +
// assign.profile.firstName +
// " " +
// assign.profile.lastName,
// Oc: assign.profile.organization,
// }
// : null);
// const profile = await (assign.profile
// ? {
// ...assign.profile,
// id: assign.profile.personal_id,
// name:
// assign.profile.prefixName +
// assign.profile.firstName +
// " " +
// assign.profile.lastName,
// Oc: assign.profile.organization,
// }
// : null);
// const evaluate_amount = await this.evaluateCommanderRepository.count({
// where: {
// assign_id,
// director_id,
// },
// });
// const evaluate_no = await (evaluate_amount + 1);
// const start_date =
// evaluate_amount == 0
// ? assign.date_start
// : findEndDate(evaluate_amount * 3, assign.date_start);
// const evaluate_amount = await this.evaluateCommanderRepository.count({
// where: {
// assign_id,
// director_id,
// },
// });
// const evaluate_no = await (evaluate_amount + 1);
// const start_date =
// evaluate_amount == 0
// ? assign.date_start
// : findEndDate(evaluate_amount * 3, assign.date_start);
const directorData = await this.assignDirectorRepository.find({
select: ["personal_id", "dated", "fullname", "position", "posType", "posLevel"],
where: { personal_id: director_id },
});
const directorData = await this.assignDirectorRepository.find({
select: ["personal_id", "dated", "fullname", "position", "posType", "posLevel"],
where: { personal_id: director_id },
})
const directors = await directorData.map((element) => ({
...element,
name: element.fullname,
label: `${element.fullname} (${element.position}, ${element.posType}: ${element.posLevel})`,
}));
const directors = await directorData.map(element => ({
...element,
name: element.fullname,
label: `${element.fullname} (${element.position}, ${element.posType}: ${element.posLevel})`,
}))
const experimenteeData = await this.personalRepository.find({
select: [
"personal_id",
"prefixName",
"firstName",
"lastName",
"positionName",
"positionLevelName",
"organization",
],
where: { personal_id: assign.personal_id },
});
const experimenteeData = await this.personalRepository.find({
select: ["personal_id", "prefixName", "firstName", "lastName", "positionName", "positionLevelName", "organization"],
where: { personal_id: assign.personal_id },
})
const experimentee = await experimenteeData.map((element) => ({
...element,
name: element.prefixName + element.firstName + " " + element.lastName,
Oc: element.organization,
}));
const experimentee = await experimenteeData.map(element => ({
...element,
name: element.prefixName + element.firstName + " " + element.lastName,
Oc: element.organization,
}))
return new HttpSuccess({
experimentee: experimentee,
director: directors ? directors : null,
assign,
evaluate,
});
}
return new HttpSuccess({
experimentee: experimentee,
director: directors ? directors : null,
assign,
evaluate,
})
}
/**
* API ()
*
* @summary ()
*
*/
@Post("")
async PostData(
@Query() assign_id: string,
@Body() requestBody: CreateEvaluateCommander,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Post("")
async PostData(@Query() assign_id: string, @Body() requestBody: CreateEvaluateCommander, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "commander",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id;
const director_id = director.personal_id
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: requestBody.evaluate_no,
date_start: requestBody.start_date,
personal_id: assign.personal_id,
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: requestBody.evaluate_no,
date_start: requestBody.start_date,
personal_id: assign.personal_id,
achievement_other_desc: requestBody.achievement_other
? requestBody.achievement_other.text
: "",
achievement_other_level: requestBody.achievement_other
? Number(requestBody.achievement_other.level)
: 0,
behavior_other_desc: requestBody.behavior_orther.text,
behavior_other_level:
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
achievement_other_desc: requestBody.achievement_other ? requestBody.achievement_other.text : "",
achievement_other_level: requestBody.achievement_other ? Number(requestBody.achievement_other.level) : 0,
behavior_other_desc: requestBody.behavior_orther.text,
behavior_other_level: requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
};
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
}
await this.evaluateCommanderRepository.save(postData, {
data: request,
});
setLogDataDiff(request, { before: null, after: postData });
await this.evaluateCommanderRepository.save(postData, {
data: request,
})
setLogDataDiff(request, { before: null, after: postData })
if (Number(requestBody.evaluate_no) < 2) {
// #noted cronjob
// แจ้งผู้บังคับบัญชาเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
var dateSend = await findEndDate(3, requestBody.start_date);
const nextNo = await (Number(requestBody.evaluate_no) + 1);
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับผู้บังคับบัญชา) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
receiverUserId: director_id,
payload: "",
isSendMail: true,
isSendInbox: true,
receiveDate: dateSend,
})
.catch((error) => {
console.error("Error calling API:", error);
});
}
if (Number(requestBody.evaluate_no) < 2) {
// #noted cronjob
// แจ้งผู้บังคับบัญชาเข้ามาบันทึกผลทุก 3 เดือน 2 ครั้ง
var dateSend = await findEndDate(3, requestBody.start_date)
const nextNo = await (Number(requestBody.evaluate_no) + 1)
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับผู้บังคับบัญชา) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
receiverUserId: director_id,
payload: "",
isSendMail: true,
isSendInbox: true,
receiveDate: dateSend,
})
.catch(error => {
console.error("Error calling API:", error)
})
}
return new HttpSuccess();
}
return new HttpSuccess()
}
/**
* API ()
*
* @summary ()
*
*/
@Put("")
async UpdateData(
// @Query() assign_id: string,
@Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateCommander,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API ()
*
* @summary ()
*
*/
@Put("")
async UpdateData(
// @Query() assign_id: string,
@Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateCommander,
@Request() request: RequestWithUser
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
let evaluate = await this.evaluateCommanderRepository.findOne({
where: { id: evaluate_id },
});
let evaluate = await this.evaluateCommanderRepository.findOne({
where: { id: evaluate_id },
})
const before = evaluate;
const before = evaluate
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน")
}
evaluate.commander_dated = requestBody.commander_dated;
evaluate.knowledge_level = requestBody.knowledge_level;
evaluate.skill_level = requestBody.skill_level;
evaluate.competency_level = requestBody.competency_level;
evaluate.learn_level = requestBody.learn_level;
evaluate.apply_level = requestBody.apply_level;
evaluate.success_level = requestBody.success_level;
evaluate.achievement_other_desc = requestBody.achievement_other
? requestBody.achievement_other.text
: "";
evaluate.achievement_other_level =
requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0;
evaluate.commander_dated = requestBody.commander_dated
evaluate.knowledge_level = requestBody.knowledge_level
evaluate.skill_level = requestBody.skill_level
evaluate.competency_level = requestBody.competency_level
evaluate.learn_level = requestBody.learn_level
evaluate.apply_level = requestBody.apply_level
evaluate.success_level = requestBody.success_level
evaluate.achievement_other_desc = requestBody.achievement_other ? requestBody.achievement_other.text : ""
evaluate.achievement_other_level = requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0
evaluate.conduct1_level = requestBody.conduct1_level;
evaluate.conduct2_level = requestBody.conduct2_level;
evaluate.conduct3_level = requestBody.conduct3_level;
evaluate.conduct4_level = requestBody.conduct4_level;
evaluate.moral1_level = requestBody.moral1_level;
evaluate.moral2_level = requestBody.moral2_level;
evaluate.moral3_level = requestBody.moral3_level;
evaluate.discipline1_level = requestBody.discipline1_level;
evaluate.discipline2_level = requestBody.discipline2_level;
evaluate.discipline3_level = requestBody.discipline3_level;
evaluate.discipline4_level = requestBody.discipline4_level;
evaluate.discipline5_level = requestBody.discipline5_level;
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
evaluate.behavior_other_level =
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0;
evaluate.behavior_strength_desc = requestBody.behavior_strength_desc;
evaluate.behavior_improve_desc = requestBody.behavior_improve_desc;
evaluate.orientation = requestBody.orientation;
evaluate.self_learning = requestBody.self_learning;
evaluate.training_seminar = requestBody.training_seminar;
evaluate.other_training = requestBody.other_training;
evaluate.updateUserId = request.user.sub;
evaluate.updateFullName = request.user.name;
evaluate.conduct1_level = requestBody.conduct1_level
evaluate.conduct2_level = requestBody.conduct2_level
evaluate.conduct3_level = requestBody.conduct3_level
evaluate.conduct4_level = requestBody.conduct4_level
evaluate.moral1_level = requestBody.moral1_level
evaluate.moral2_level = requestBody.moral2_level
evaluate.moral3_level = requestBody.moral3_level
evaluate.discipline1_level = requestBody.discipline1_level
evaluate.discipline2_level = requestBody.discipline2_level
evaluate.discipline3_level = requestBody.discipline3_level
evaluate.discipline4_level = requestBody.discipline4_level
evaluate.discipline5_level = requestBody.discipline5_level
evaluate.behavior_other_desc = requestBody.behavior_orther.text
evaluate.behavior_other_level = requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0
evaluate.behavior_strength_desc = requestBody.behavior_strength_desc
evaluate.behavior_improve_desc = requestBody.behavior_improve_desc
evaluate.orientation = requestBody.orientation
evaluate.self_learning = requestBody.self_learning
evaluate.training_seminar = requestBody.training_seminar
evaluate.other_training = requestBody.other_training
evaluate.updateUserId = request.user.sub
evaluate.updateFullName = request.user.name
await this.evaluateCommanderRepository.save(evaluate, { data: request });
setLogDataDiff(request, { before, after: evaluate });
await this.evaluateCommanderRepository.save(evaluate, { data: request })
setLogDataDiff(request, { before, after: evaluate })
return new HttpSuccess();
}
return new HttpSuccess()
}
}

View file

@ -33,7 +33,6 @@ import permission from "../interfaces/permission";
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class EvaluateRecordController extends Controller {
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
private assignRepository = AppDataSource.getRepository(Assign);

View file

@ -1,502 +1,418 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
Query,
Put,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { AppDataSource } from "../database/data-source";
import { AssignDirector } from "../entities/AssignDirector";
import HttpError from "../interfaces/http-error";
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 permission from "../interfaces/permission";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query, Put } from "tsoa"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import { RequestWithUser } from "../middlewares/user"
import { setLogDataDiff } from "../interfaces/utils"
import { AppDataSource } from "../database/data-source"
import { AssignDirector } from "../entities/AssignDirector"
import HttpError from "../interfaces/http-error"
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 permission from "../interfaces/permission"
@Route("api/v1/probation/evaluate-result")
@Tags("แบบรายงานการประเมินฯ")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class EvaluateResultController extends Controller {
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
private assignRepository = AppDataSource.getRepository(Assign);
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman);
private personalRepository = AppDataSource.getRepository(Personal);
private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult);
private assignDirectorRepository = AppDataSource.getRepository(AssignDirector)
private assignRepository = AppDataSource.getRepository(Assign)
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman)
private personalRepository = AppDataSource.getRepository(Personal)
private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult)
/**
* API
*
* @summary
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
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, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name:
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null);
const profile = await (assign.profile
? {
...assign.profile,
id: assign.profile.personal_id,
name: assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
Oc: assign.profile.organization,
}
: null)
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
});
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
})
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
}
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน")
}
let mentors = [];
const mentorList = await directorData.filter((x) => x.role == "mentor");
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index];
let mentors = []
const mentorList = await directorData.filter(x => x.role == "mentor")
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index]
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label:
e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
});
}
}
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label: e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
})
}
}
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
const commanderData = await (directorData.find(x => x.role == "commander") ?? null)
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label:
commanderData.fullname +
" " +
(commanderData.position
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
: ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null;
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label: commanderData.fullname + " " + (commanderData.position ? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})` : ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label:
chairmanData.fullname +
" " +
(chairmanData.position
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
: ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null;
const chairmanData = await (directorData.find(x => x.role == "chairman") ?? null)
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label: chairmanData.fullname + " " + (chairmanData.position ? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})` : ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null
const resultData = await this.evaluateChairmanRepository.findOne({
select: [
"develop_orientation_score",
"develop_self_learning_score",
"develop_training_seminar_score",
"evaluate_result",
],
where: {
assign_id,
},
});
const resultData = await this.evaluateChairmanRepository.findOne({
select: ["develop_orientation_score", "develop_self_learning_score", "develop_training_seminar_score", "evaluate_result"],
where: {
assign_id,
},
})
if (!resultData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล");
}
if (!resultData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล")
}
const develop_complete = await (resultData.develop_orientation_score > 0 &&
resultData.develop_self_learning_score > 0 &&
resultData.develop_training_seminar_score > 0
? 1
: 2);
const develop_complete = await (resultData.develop_orientation_score > 0 && resultData.develop_self_learning_score > 0 && resultData.develop_training_seminar_score > 0 ? 1 : 2)
const evaluate_result = await (resultData.evaluate_result == 1 ? 1 : 2);
const evaluate_result = await (resultData.evaluate_result == 1 ? 1 : 2)
const result = await {
develop_complete: develop_complete,
evaluate_result: evaluate_result,
};
const result = await {
develop_complete: develop_complete,
evaluate_result: evaluate_result,
}
return new HttpSuccess({
person: profile,
assign,
result,
mentors,
commander,
chairman,
});
}
return new HttpSuccess({
person: profile,
assign,
result,
mentors,
commander,
chairman,
})
}
/**
* API
*
* @summary
*
*/
@Get("")
async GetEvaluate(
@Request() request: RequestWithUser,
@Query() assign_id: string,
@Query() evaluate_no?: string,
) {
await new permission().PermissionGet(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Get("")
async GetEvaluate(@Request() request: RequestWithUser, @Query() assign_id: string, @Query() evaluate_no?: string) {
await new permission().PermissionGet(request, "SYS_PROBATION")
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director_id = director.personal_id;
// ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id
const evaluate = await this.evaluateResultRepository.findOne({
where: {
director_id,
assign_id,
},
});
const evaluate = await this.evaluateResultRepository.findOne({
where: {
director_id,
assign_id,
},
})
if (!evaluate) {
return new HttpSuccess(null);
}
if (!evaluate) {
return new HttpSuccess(null)
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const experimenteeData = await this.personalRepository.findOne({
select: [
"personal_id",
"prefixName",
"firstName",
"lastName",
"positionName",
"positionLevelName",
"organization",
],
where: { personal_id: assign.personal_id },
});
const experimenteeData = await this.personalRepository.findOne({
select: ["personal_id", "prefixName", "firstName", "lastName", "positionName", "positionLevelName", "organization"],
where: { personal_id: assign.personal_id },
})
if (!experimenteeData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
const experimentee = await {
...experimenteeData,
name:
experimenteeData.prefixName + experimenteeData.firstName + " " + experimenteeData.lastName,
Oc: experimenteeData.organization,
};
if (!experimenteeData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
}
const experimentee = await {
...experimenteeData,
name: experimenteeData.prefixName + experimenteeData.firstName + " " + experimenteeData.lastName,
Oc: experimenteeData.organization,
}
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
});
const directorData = await this.assignDirectorRepository.find({
where: { assign_id },
order: { ordering: "ASC" },
})
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
}
if (!directorData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน")
}
let mentors = [];
const mentorList = await directorData.filter((x) => x.role == "mentor");
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index];
let mentors = []
const mentorList = await directorData.filter(x => x.role == "mentor")
if (mentorList.length > 0) {
for (let index = 0; index < mentorList.length; index++) {
const e = await mentorList[index]
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label:
e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
});
}
}
mentors.push({
personal_id: e.personal_id,
dated: e.dated,
name: e.fullname,
label: e.fullname + " " + (e.position ? `(${e.position}, ${e.posType}: ${e.posLevel})` : ""),
position: e.position,
posType: e.posType,
posLevel: e.posLevel,
})
}
}
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
const commanderData = await (directorData.find(x => x.role == "commander") ?? null)
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label:
commanderData.fullname +
" " +
(commanderData.position
? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})`
: ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null;
const commander =
commanderData != null
? {
personal_id: commanderData.personal_id,
dated: commanderData.dated,
name: commanderData.fullname,
label: commanderData.fullname + " " + (commanderData.position ? `(${commanderData.position}, ${commanderData.posType}: ${commanderData.posLevel})` : ""),
position: commanderData.position,
posType: commanderData.posType,
posLevel: commanderData.posLevel,
}
: null
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label:
chairmanData.fullname +
" " +
(chairmanData.position
? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})`
: ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null;
const chairmanData = await (directorData.find(x => x.role == "chairman") ?? null)
const chairman =
chairmanData != null
? {
personal_id: chairmanData.personal_id,
dated: chairmanData.dated,
name: chairmanData.fullname,
label: chairmanData.fullname + " " + (chairmanData.position ? `(${chairmanData.position}, ${chairmanData.posType}: ${chairmanData.posLevel})` : ""),
position: chairmanData.position,
posType: chairmanData.posType,
posLevel: chairmanData.posLevel,
}
: null
return new HttpSuccess({
commander,
chairman,
mentors,
experimentee,
assign,
evaluate: evaluate,
});
}
return new HttpSuccess({
commander,
chairman,
mentors,
experimentee,
assign,
evaluate: evaluate,
})
}
/**
* API
*
* @summary
*
*/
@Post("")
async PostData(
@Query() assign_id: string,
@Body() requestBody: CreateEvaluateResult,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Post("")
async PostData(@Query() assign_id: string, @Body() requestBody: CreateEvaluateResult, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
});
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
}
const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"],
where: {
assign_id,
role: "chairman",
},
})
if (!director) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล")
}
const director_id = director.personal_id;
const director_id = director.personal_id
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: 1,
personal_id: assign.personal_id,
date_start: requestBody.start_date,
expand_month: requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
const postData: any = await {
assign_id,
...requestBody,
director_id,
no: 1,
personal_id: assign.personal_id,
date_start: requestBody.start_date,
expand_month: requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
};
createdUserId: request.user.sub,
createdFullName: request.user.name,
updateUserId: request.user.sub,
updateFullName: request.user.name,
}
await this.evaluateResultRepository.save(postData, {
data: request,
});
setLogDataDiff(request, { before: null, after: postData });
await this.evaluateResultRepository.save(postData, {
data: request,
})
setLogDataDiff(request, { before: null, after: postData })
const personal = await this.personalRepository.findOne({
where: { personal_id: assign.personal_id },
});
const personal = await this.personalRepository.findOne({
where: { personal_id: assign.personal_id },
})
if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
personal.probation_status =
requestBody.pass_result == 1
? 2
: requestBody.pass_result == 2
? 3
: personal.probation_status;
if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
}
personal.probation_status = requestBody.pass_result == 1 ? 2 : requestBody.pass_result == 2 ? 3 : personal.probation_status
if (requestBody.pass_result == 3) {
personal.probation_status = 7;
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
receiverUserId: assign.personal_id,
payload: "",
isSendMail: false,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
}
if (requestBody.pass_result == 3) {
personal.probation_status = 7
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
receiverUserId: assign.personal_id,
payload: "",
isSendMail: false,
isSendInbox: true,
isSendNotification: true,
})
.catch(error => {
console.error("Error calling API:", error)
})
}
await this.personalRepository.save(personal, { data: request });
await this.personalRepository.save(personal, { data: request })
return new HttpSuccess();
}
return new HttpSuccess()
}
/**
* API
*
* @summary
*
*/
@Put("")
async UpdateData(
@Query() assign_id: string,
@Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateResult,
@Request() request: RequestWithUser,
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Put("")
async UpdateData(@Query() assign_id: string, @Query() evaluate_id: string, @Body() requestBody: CreateEvaluateResult, @Request() request: RequestWithUser) {
await new permission().PermissionUpdate(request, "SYS_PROBATION")
let evaluate = await this.evaluateResultRepository.findOne({
where: { id: evaluate_id },
});
let evaluate = await this.evaluateResultRepository.findOne({
where: { id: evaluate_id },
})
const before = evaluate;
const before = evaluate
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
}
if (!evaluate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน")
}
evaluate.date_start = requestBody.start_date;
evaluate.date_finish = requestBody.date_finish;
evaluate.develop_complete = requestBody.develop_complete;
evaluate.pass_result = requestBody.pass_result;
evaluate.expand_month =
requestBody.pass_result && requestBody.pass_result == 3
? Number(requestBody.expand_month)
: 0;
evaluate.reson = requestBody.reson;
evaluate.chairman_dated = requestBody.chairman_dated;
evaluate.date_start = requestBody.start_date
evaluate.date_finish = requestBody.date_finish
evaluate.develop_complete = requestBody.develop_complete
evaluate.pass_result = requestBody.pass_result
evaluate.expand_month = requestBody.pass_result && requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0
evaluate.reson = requestBody.reson
evaluate.chairman_dated = requestBody.chairman_dated
evaluate.director1_dated = requestBody.director1_dated;
evaluate.director2_dated = requestBody.director2_dated;
evaluate.updateUserId = request.user.sub;
evaluate.updateFullName = request.user.name;
evaluate.director1_dated = requestBody.director1_dated
evaluate.director2_dated = requestBody.director2_dated
evaluate.updateUserId = request.user.sub
evaluate.updateFullName = request.user.name
await this.evaluateResultRepository.save(evaluate, { data: request });
setLogDataDiff(request, { before, after: evaluate });
await this.evaluateResultRepository.save(evaluate, { data: request })
setLogDataDiff(request, { before, after: evaluate })
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
});
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
}
const personal = await this.personalRepository.findOne({
where: { personal_id: assign.personal_id },
});
const assign = await this.assignRepository.findOne({
relations: ["profile"],
where: { id: assign_id },
})
if (!assign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน")
}
const personal = await this.personalRepository.findOne({
where: { personal_id: assign.personal_id },
})
if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
personal.probation_status =
requestBody.pass_result == 1
? 2
: requestBody.pass_result == 2
? 3
: personal.probation_status;
if (!personal) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
}
personal.probation_status = requestBody.pass_result == 1 ? 2 : requestBody.pass_result == 2 ? 3 : personal.probation_status
if (requestBody.pass_result == 3) {
personal.probation_status = 7;
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
receiverUserId: assign.personal_id,
payload: "",
isSendMail: false,
isSendInbox: true,
isSendNotification: true,
})
.catch((error) => {
console.error("Error calling API:", error);
});
}
if (requestBody.pass_result == 3) {
personal.probation_status = 7
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
await new CallAPI()
.PostData(request, "/placement/noti", {
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
receiverUserId: assign.personal_id,
payload: "",
isSendMail: false,
isSendInbox: true,
isSendNotification: true,
})
.catch(error => {
console.error("Error calling API:", error)
})
}
await this.personalRepository.save(personal, { data: request });
await this.personalRepository.save(personal, { data: request })
return new HttpSuccess();
}
return new HttpSuccess()
}
}

View file

@ -1,215 +1,166 @@
import {
Controller,
Post,
Route,
Security,
Tags,
Body,
Request,
SuccessResponse,
Response,
Get,
Query,
} from "tsoa";
import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { Personal, PostPersonal } from "../entities/Personal";
import permission from "../interfaces/permission";
import { Assign } from "../entities/Assign";
import { Controller, Post, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query } from "tsoa"
import { AppDataSource } from "../database/data-source"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import HttpError from "../interfaces/http-error"
import { RequestWithUser } from "../middlewares/user"
import { setLogDataDiff } from "../interfaces/utils"
import { Personal, PostPersonal } from "../entities/Personal"
import permission from "../interfaces/permission"
import { Assign } from "../entities/Assign"
@Route("api/v1/probation/personal")
@Tags("Personal")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class PersonalController extends Controller {
private personalRepository = AppDataSource.getRepository(Personal);
private assignRepository = AppDataSource.getRepository(Assign);
private personalRepository = AppDataSource.getRepository(Personal)
private assignRepository = AppDataSource.getRepository(Assign)
/**
* API
*
* @summary
*
*/
@Post("add")
async AddPersonal(
@Body() requestBody: PostPersonal,
@Request() request: RequestWithUser
) {
await new permission().PermissionCreate(request, "SYS_PROBATION");
/**
* API
*
* @summary
*
*/
@Post("add")
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) {
await new permission().PermissionCreate(request, "SYS_PROBATION")
const checkPersonal: number = await this.personalRepository.count({
where: { personal_id: requestBody.id },
});
if (checkPersonal > 0) {
throw new HttpError(
HttpStatusCode.BAD_REQUEST,
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
);
}
const checkPersonal: number = await this.personalRepository.count({
where: { personal_id: requestBody.id },
})
if (checkPersonal > 0) {
throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว")
}
let organization = await (requestBody.orgChild4Name
? requestBody.orgChild4Name + "/"
: "");
organization += await (requestBody.orgChild3Name
? requestBody.orgChild3Name + "/"
: "");
organization += await (requestBody.orgChild2Name
? requestBody.orgChild2Name + "/"
: "");
organization += await (requestBody.orgChild1Name
? requestBody.orgChild1Name + "/"
: "");
organization += await (requestBody.orgRootName
? requestBody.orgRootName
: "");
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + "/" : "")
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + "/" : "")
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + "/" : "")
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + "/" : "")
organization += await (requestBody.orgRootName ? requestBody.orgRootName : "")
const personalData = Object.assign(new Personal());
personalData.personal_id = requestBody.id;
personalData.order_number = requestBody.order_number
? requestBody.order_number
: "";
personalData.probation_status = 1;
personalData.createdUserId = request.user.sub;
personalData.createdFullName = request.user.name;
personalData.updateUserId = request.user.sub;
personalData.updateFullName = request.user.name;
const personalData = Object.assign(new Personal())
personalData.personal_id = requestBody.id
personalData.order_number = requestBody.order_number ? requestBody.order_number : ""
personalData.probation_status = 1
personalData.createdUserId = request.user.sub
personalData.createdFullName = request.user.name
personalData.updateUserId = request.user.sub
personalData.updateFullName = request.user.name
personalData.idcard = requestBody.idcard;
personalData.prefixName = requestBody.prefix;
personalData.firstName = requestBody.firstName;
personalData.lastName = requestBody.lastName;
personalData.isProbation = requestBody.isProbation ? 1 : 0;
personalData.positionLevelName = requestBody.posLevelName
? requestBody.posLevelName
: "";
personalData.positionName = requestBody.position
? requestBody.position
: "";
personalData.positionLineName = requestBody.posLineName;
personalData.positionTypeName = requestBody.posTypeName;
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
personalData.orgRootName = requestBody.orgRootName;
personalData.organization = organization;
personalData.idcard = requestBody.idcard
personalData.prefixName = requestBody.prefix
personalData.firstName = requestBody.firstName
personalData.lastName = requestBody.lastName
personalData.isProbation = requestBody.isProbation ? 1 : 0
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : ""
personalData.positionName = requestBody.position ? requestBody.position : ""
personalData.positionLineName = requestBody.posLineName
personalData.positionTypeName = requestBody.posTypeName
personalData.posNo = requestBody.posNo ? requestBody.posNo : ""
personalData.orgRootName = requestBody.orgRootName
personalData.organization = organization
const before = null;
const personal = await this.personalRepository.save(personalData, {
data: request,
});
setLogDataDiff(request, { before, after: personal });
const before = null
const personal = await this.personalRepository.save(personalData, {
data: request,
})
setLogDataDiff(request, { before, after: personal })
return new HttpSuccess();
}
return new HttpSuccess()
}
/**
* API
*
* @summary
*
*/
@Get("list")
async ListPersonal(
@Query() status: string = "",
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Request() request: RequestWithUser
) {
await new permission().PermissionList(request, "SYS_PROBATION");
const conditions: any = {};
if (status) {
conditions.probation_status = status;
}
/**
* API
*
* @summary
*
*/
@Get("list")
async ListPersonal(@Query() status: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) {
await new permission().PermissionList(request, "SYS_PROBATION")
const conditions: any = {}
if (status) {
conditions.probation_status = status
}
const [lists, total] = await this.personalRepository.findAndCount({
order: { createdAt: "DESC" },
where: conditions,
skip: (page - 1) * pageSize,
take: pageSize,
});
const [lists, total] = await this.personalRepository.findAndCount({
order: { createdAt: "DESC" },
where: conditions,
skip: (page - 1) * pageSize,
take: pageSize,
})
if (!lists) {
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถแสดงข้อมูลได้"
);
}
if (!lists) {
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้")
}
let result: any = [];
let result: any = []
await Promise.all(
lists.map(async (item, index) => {
const probation_no = await this.assignRepository.count({
where: {
personal_id: item.personal_id,
},
});
await Promise.all(
lists.map(async (item, index) => {
const probation_no = await this.assignRepository.count({
where: {
personal_id: item.personal_id,
},
})
await result.push({
personal_id: item.personal_id,
ordering: index + 1,
name: item.prefixName + item.firstName + " " + item.lastName,
idcard: item.idcard,
prefixName: item.prefixName,
firstName: item.firstName,
lastName: item.lastName,
position_line: item.positionName,
position_level: item.positionLevelName,
position_type: item.positionTypeName,
organization: item.organization,
probation_no: probation_no,
order_number: item.order_number,
probation_status: item.probation_status,
});
})
);
await result.push({
personal_id: item.personal_id,
ordering: index + 1,
name: item.prefixName + item.firstName + " " + item.lastName,
idcard: item.idcard,
prefixName: item.prefixName,
firstName: item.firstName,
lastName: item.lastName,
position_line: item.positionName,
position_level: item.positionLevelName,
position_type: item.positionTypeName,
organization: item.organization,
probation_no: probation_no,
order_number: item.order_number,
probation_status: item.probation_status,
})
})
)
return new HttpSuccess({ data: result, total: total });
}
return new HttpSuccess({ data: result, total: total })
}
/**
* API
*
* @summary
*
*/
@Get("")
async GetPersonal(
@Request() request: RequestWithUser,
@Query() personal_id: string
) {
await new permission().PermissionGet(request, "SYS_PROBATION");
const person = await this.personalRepository.findOne({
where: { personal_id: personal_id },
});
/**
* API
*
* @summary
*
*/
@Get("")
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
await new permission().PermissionGet(request, "SYS_PROBATION")
const person = await this.personalRepository.findOne({
where: { personal_id: personal_id },
})
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
}
if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
}
const probation_no = await this.assignRepository.count({
where: { personal_id: person.personal_id },
});
const probation_no = await this.assignRepository.count({
where: { personal_id: person.personal_id },
})
const result = await {
personal_id: person.personal_id,
name: person.prefixName + person.firstName + " " + person.lastName,
position_line: person.positionName,
position_level: person.positionLevelName,
position_type: person.positionTypeName,
organization: person.organization,
probation_no: probation_no,
order_number: person.order_number,
probation_status: person.probation_status,
};
const result = await {
personal_id: person.personal_id,
name: person.prefixName + person.firstName + " " + person.lastName,
position_line: person.positionName,
position_level: person.positionLevelName,
position_type: person.positionTypeName,
organization: person.organization,
probation_no: probation_no,
order_number: person.order_number,
probation_status: person.probation_status,
}
return new HttpSuccess(result);
}
return new HttpSuccess(result)
}
}

View file

@ -22,7 +22,6 @@ import { Appoint } from "../entities/Appoint"
@Tags("Report")
@Security("bearerAuth")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class ReportController extends Controller {
private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman)
private evaluateResultRepository = AppDataSource.getRepository(EvaluateResult)

View file

@ -1,67 +1,47 @@
import {
Controller,
Route,
Security,
Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
Query,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { Survey } from "../entities/Survey";
import { AppDataSource } from "../database/data-source";
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query } from "tsoa"
import HttpSuccess from "../interfaces/http-success"
import HttpStatusCode from "../interfaces/http-status"
import { RequestWithUser } from "../middlewares/user"
import { setLogDataDiff } from "../interfaces/utils"
import { Survey } from "../entities/Survey"
import { AppDataSource } from "../database/data-source"
@Route("api/v1/probation/survey")
@Tags("Survey")
@Security("bearerAuth")
@Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง")
export class SurveyController extends Controller {
private surveyRepository = AppDataSource.getRepository(Survey);
private surveyRepository = AppDataSource.getRepository(Survey)
/**
* API
*
* @summary
*
*/
@Get("")
async GetSurvey(@Query() assign_id: string) {
const data = await this.surveyRepository.findOne({
where: {
assign_id,
},
});
return new HttpSuccess(data);
}
/**
* API
*
* @summary
*
*/
@Get("")
async GetSurvey(@Query() assign_id: string) {
const data = await this.surveyRepository.findOne({
where: {
assign_id,
},
})
return new HttpSuccess(data)
}
/**
* API
*
* @summary
*
*/
@Post("")
async PostSurvey(
@Query() assign_id: string,
@Body() requestBody: any,
@Request() request: RequestWithUser,
) {
const before = null;
const data = await { ...requestBody, personal_id: request.user.sub, assign_id };
await this.surveyRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: data });
/**
* API
*
* @summary
*
*/
@Post("")
async PostSurvey(@Query() assign_id: string, @Body() requestBody: any, @Request() request: RequestWithUser) {
const before = null
const data = await { ...requestBody, personal_id: request.user.sub, assign_id }
await this.surveyRepository.save(data, { data: request })
setLogDataDiff(request, { before, after: data })
return new HttpSuccess();
}
return new HttpSuccess()
}
}