Merge branch 'develop' into dev

This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2025-09-16 15:00:08 +07:00
commit e6cf5d312a
19 changed files with 7074 additions and 6019 deletions

33
package-lock.json generated
View file

@ -28,7 +28,8 @@
"swagger-ui-express": "^5.0.0", "swagger-ui-express": "^5.0.0",
"tsoa": "^6.0.1", "tsoa": "^6.0.1",
"typeorm": "^0.3.19", "typeorm": "^0.3.19",
"typeorm-cli": "^1.0.7" "typeorm-cli": "^1.0.7",
"ws": "^8.18.1"
}, },
"devDependencies": { "devDependencies": {
"@types/amqplib": "^0.10.5", "@types/amqplib": "^0.10.5",
@ -37,6 +38,7 @@
"@types/node": "^20.11.5", "@types/node": "^20.11.5",
"@types/node-cron": "^3.0.11", "@types/node-cron": "^3.0.11",
"@types/swagger-ui-express": "^4.1.6", "@types/swagger-ui-express": "^4.1.6",
"@types/ws": "^8.5.14",
"nodemon": "^3.0.3", "nodemon": "^3.0.3",
"prettier": "^3.2.2", "prettier": "^3.2.2",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
@ -866,6 +868,15 @@
"@types/serve-static": "*" "@types/serve-static": "*"
} }
}, },
"node_modules/@types/ws": {
"version": "8.5.14",
"resolved": "https://registry.npmjs.org/@types/ws/-/ws-8.5.14.tgz",
"integrity": "sha512-bd/YFLW+URhBzMXurx7lWByOu+xzU9+kb3RboOteXYDfW+tr+JZa99OyNmPINEGB/ahzKrEuc8rcv4gnpJmxTw==",
"dev": true,
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/zen-observable": { "node_modules/@types/zen-observable": {
"version": "0.8.3", "version": "0.8.3",
"resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz", "resolved": "https://registry.npmjs.org/@types/zen-observable/-/zen-observable-0.8.3.tgz",
@ -5769,6 +5780,26 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ=="
}, },
"node_modules/ws": {
"version": "8.18.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-8.18.1.tgz",
"integrity": "sha512-RKW2aJZMXeMxVpnZ6bck+RswznaxmzdULiBr6KY7XkTnW8uvt0iT9H5DkHUChXrc+uurzwa0rVI16n/Xzjdz1w==",
"engines": {
"node": ">=10.0.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": ">=5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/xml2js": { "node_modules/xml2js": {
"version": "0.4.23", "version": "0.4.23",
"resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz", "resolved": "https://registry.npmjs.org/xml2js/-/xml2js-0.4.23.tgz",

View file

@ -22,6 +22,7 @@
"@types/node": "^20.11.5", "@types/node": "^20.11.5",
"@types/node-cron": "^3.0.11", "@types/node-cron": "^3.0.11",
"@types/swagger-ui-express": "^4.1.6", "@types/swagger-ui-express": "^4.1.6",
"@types/ws": "^8.5.14",
"nodemon": "^3.0.3", "nodemon": "^3.0.3",
"prettier": "^3.2.2", "prettier": "^3.2.2",
"ts-node": "^10.9.2", "ts-node": "^10.9.2",
@ -47,6 +48,7 @@
"swagger-ui-express": "^5.0.0", "swagger-ui-express": "^5.0.0",
"tsoa": "^6.0.1", "tsoa": "^6.0.1",
"typeorm": "^0.3.19", "typeorm": "^0.3.19",
"typeorm-cli": "^1.0.7" "typeorm-cli": "^1.0.7",
"ws": "^8.18.1"
} }
} }

View file

@ -18,7 +18,7 @@ async function main() {
app.use( app.use(
cors({ cors({
origin: "*", origin: "*",
}), })
); );
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
@ -36,16 +36,37 @@ async function main() {
const params = new URLSearchParams(req.query as Record<string, string>); const params = new URLSearchParams(req.query as Record<string, string>);
const newUrl = params.toString() ? `${id}?${params.toString()}` : id; const newUrl = params.toString() ? `${id}?${params.toString()}` : id;
const APIAPI_DASHBOARD = `${process.env.API_DASHBOARD}/generate-pdf`; const API_DASHBOARD = `${process.env.VITE_API_REPORT_URL}/html`;
const body = `${process.env.API_DASHBOARD}/d/${newUrl}`; const url = `${process.env.VITE_DASHBOARD_PANEL}/d/${newUrl}&kiosk`;
try { try {
// เรียก API generate-pdf // เรียก API generate-pdf
const apiResponse = await axios.post(APIAPI_DASHBOARD, { url: body }); const apiResponse = await axios.post(
API_DASHBOARD,
{
template: url,
reportName: "dashboard_report",
htmlOption: {
querySelector: ".dashboard-content",
},
},
{
headers: {
"Content-Type": "application/json",
accept: "application/pdf",
},
responseType: "arraybuffer",
}
);
// console.log("Response:", apiResponse.data.pdfUrl); console.log("Response:", apiResponse.data);
res.redirect(apiResponse.data.pdfUrl); const pdfBuffer = Buffer.from(apiResponse.data, "binary");
res.set({
"Content-Type": "application/pdf",
"Content-Disposition": "attachment; filename=dashboard.pdf",
});
res.send(pdfBuffer);
} catch (error) { } catch (error) {
throw new Error("Failed to generate PDF: " + error); throw new Error("Failed to generate PDF: " + error);
} }
@ -61,9 +82,11 @@ async function main() {
APP_PORT, APP_PORT,
APP_HOST, APP_HOST,
() => ( () => (
console.log(`[APP] Application is running on: http://localhost:${APP_PORT}`), console.log(
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`) `[APP] Application is running on: http://localhost:${APP_PORT}`
), ),
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
)
); );
} }

View file

@ -50,6 +50,19 @@ export class AppointController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
try {
const appoint = await this.appointRepository.find({
relations: ["personal", "directors"],
where: { createdUserId: request.user.sub },
// where: { personal: conditions },
});
return new HttpSuccess(appoint);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
// await new permission().PermissionList(request, "SYS_PROBATION") // await new permission().PermissionList(request, "SYS_PROBATION")
// const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION") // const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION")
@ -74,14 +87,6 @@ export class AppointController extends Controller {
// if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) { // if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
// conditions.child4 = _data.child4 // conditions.child4 = _data.child4
// } // }
const appoint = await this.appointRepository.find({
relations: ["personal", "directors"],
where: { createdUserId: request.user.sub },
// where: { personal: conditions },
});
return new HttpSuccess(appoint);
} }
/** /**
@ -92,12 +97,18 @@ export class AppointController extends Controller {
*/ */
@Get("list/{id}") @Get("list/{id}")
async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) { async GetListCommand(@Request() request: RequestWithUser, @Path() id: string) {
try {
const appoint = await this.appointRepository.find({ const appoint = await this.appointRepository.find({
relations: ["directors"], relations: ["directors"],
where: { profileId: id, status: "DONE" }, where: { profileId: id, status: "DONE" },
}); });
return new HttpSuccess(appoint); return new HttpSuccess(appoint);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -108,6 +119,7 @@ export class AppointController extends Controller {
*/ */
@Post("") @Post("")
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) { async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
try {
await new permission().PermissionCreate(request, "SYS_PROBATION"); await new permission().PermissionCreate(request, "SYS_PROBATION");
const data: any = { const data: any = {
@ -117,10 +129,17 @@ export class AppointController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
}; };
const before = null; const before = null;
const appoint = await this.appointRepository.save(data, { data: request }); const appoint = await this.appointRepository.save(data, {
data: request,
});
setLogDataDiff(request, { before, after: appoint }); setLogDataDiff(request, { before, after: appoint });
return new HttpSuccess(appoint.id); return new HttpSuccess(appoint.id);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -131,6 +150,7 @@ export class AppointController extends Controller {
*/ */
@Get("{id}") @Get("{id}")
async GetById(@Request() request: RequestWithUser, @Path() id: string) { async GetById(@Request() request: RequestWithUser, @Path() id: string) {
try {
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION"); let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
@ -141,6 +161,11 @@ export class AppointController extends Controller {
}); });
return new HttpSuccess(appoint); return new HttpSuccess(appoint);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -155,6 +180,7 @@ export class AppointController extends Controller {
@Body() requestBody: UpdateAppoint, @Body() requestBody: UpdateAppoint,
@Path() id: string, @Path() id: string,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const appoint: any = await this.appointRepository.findOne({ const appoint: any = await this.appointRepository.findOne({
@ -185,6 +211,11 @@ export class AppointController extends Controller {
setLogDataDiff(request, { before, after: appoint }); setLogDataDiff(request, { before, after: appoint });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -195,6 +226,7 @@ export class AppointController extends Controller {
*/ */
@Delete("{id}") @Delete("{id}")
public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) { public async deleteRole(@Path() id: string, @Request() request: RequestWithUser) {
try {
await new permission().PermissionDelete(request, "SYS_PROBATION"); await new permission().PermissionDelete(request, "SYS_PROBATION");
await this.appointDirectorRepository.delete({ appointId: id }); await this.appointDirectorRepository.delete({ appointId: id });
@ -203,6 +235,11 @@ export class AppointController extends Controller {
if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); if (!result) throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -213,6 +250,7 @@ export class AppointController extends Controller {
*/ */
@Get("/committee/{profileId}") @Get("/committee/{profileId}")
async GetCheckById(@Request() request: RequestWithUser, @Path() profileId: string) { async GetCheckById(@Request() request: RequestWithUser, @Path() profileId: string) {
try {
await new permission().PermissionGet(request, "SYS_PROBATION"); await new permission().PermissionGet(request, "SYS_PROBATION");
const directorId = await new CallAPI() const directorId = await new CallAPI()
@ -235,5 +273,10 @@ export class AppointController extends Controller {
.getOne(); .getOne();
const check = appoint ? true : false; const check = appoint ? true : false;
return new HttpSuccess(check); return new HttpSuccess(check);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -21,21 +21,12 @@ import { findEndDate, setLogDataDiff } from "../interfaces/utils";
import { Personal } from "../entities/Personal"; import { Personal } from "../entities/Personal";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { Assign, CreateAssign } from "../entities/Assign"; import { Assign, CreateAssign } from "../entities/Assign";
import { import { AssignDirector, CreateAssignDirector } from "../entities/AssignDirector";
AssignDirector,
CreateAssignDirector,
} from "../entities/AssignDirector";
import { AssignJob, CreateAssignJob } from "../entities/AssignJob"; import { AssignJob, CreateAssignJob } from "../entities/AssignJob";
import { import { AssignKnowledge, CreateAssignKnowledge } from "../entities/AssignKnowledge";
AssignKnowledge,
CreateAssignKnowledge,
} from "../entities/AssignKnowledge";
import { AssignLaw, CreateAssignLaw } from "../entities/AssignLaw"; import { AssignLaw, CreateAssignLaw } from "../entities/AssignLaw";
import { AssignSkill, CreateAssignSkill } from "../entities/AssignSkill"; import { AssignSkill, CreateAssignSkill } from "../entities/AssignSkill";
import { import { AssignCompetency, CreateAssignCompetency } from "../entities/AssignCompetency";
AssignCompetency,
CreateAssignCompetency,
} from "../entities/AssignCompetency";
import { import {
AssignCompetencyGroup, AssignCompetencyGroup,
CreateAssignCompetencyGroup, CreateAssignCompetencyGroup,
@ -49,23 +40,18 @@ import CallAPI from "../interfaces/call-api";
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง" "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
) )
export class AssignController extends Controller { export class AssignController extends Controller {
private assignRepository = AppDataSource.getRepository(Assign); private assignRepository = AppDataSource.getRepository(Assign);
private personalRepository = AppDataSource.getRepository(Personal); private personalRepository = AppDataSource.getRepository(Personal);
private assignDirectorRepository = private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
AppDataSource.getRepository(AssignDirector);
private assignJobRepository = AppDataSource.getRepository(AssignJob); private assignJobRepository = AppDataSource.getRepository(AssignJob);
private assignKnowledgeRepository = private assignKnowledgeRepository = AppDataSource.getRepository(AssignKnowledge);
AppDataSource.getRepository(AssignKnowledge);
private assignLawRepository = AppDataSource.getRepository(AssignLaw); private assignLawRepository = AppDataSource.getRepository(AssignLaw);
private assignSkillRepository = AppDataSource.getRepository(AssignSkill); private assignSkillRepository = AppDataSource.getRepository(AssignSkill);
private assignCompetencyRepository = private assignCompetencyRepository = AppDataSource.getRepository(AssignCompetency);
AppDataSource.getRepository(AssignCompetency); private assignCompetencyGroupRepository = AppDataSource.getRepository(AssignCompetencyGroup);
private assignCompetencyGroupRepository = AppDataSource.getRepository(
AssignCompetencyGroup
);
private assignOutputRepository = AppDataSource.getRepository(AssignOutput); private assignOutputRepository = AppDataSource.getRepository(AssignOutput);
private lawsRepository = AppDataSource.getRepository(Law); private lawsRepository = AppDataSource.getRepository(Law);
@ -87,10 +73,8 @@ export class AssignController extends Controller {
* *
*/ */
@Post("") @Post("")
async AddAssign( async AddAssign(@Request() request: RequestWithUser, @Body() requestBody: CreateAssign) {
@Request() request: RequestWithUser, try {
@Body() requestBody: CreateAssign
) {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
where: { where: {
@ -125,8 +109,7 @@ export class AssignController extends Controller {
const assign = await this.assignRepository.save(data, { data: request }); const assign = await this.assignRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: data }); setLogDataDiff(request, { before, after: data });
const jobs = await requestBody.assign_jobs.map( const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
(x: CreateAssignJob, index: number) => ({
...x, ...x,
id: index + 1, id: index + 1,
assign_id: assign.id, assign_id: assign.id,
@ -134,8 +117,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignJobRepository.save(jobs, { data: request }); await this.assignJobRepository.save(jobs, { data: request });
setLogDataDiff(request, { before, after: jobs }); setLogDataDiff(request, { before, after: jobs });
@ -148,13 +130,12 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignKnowledgeRepository.save(knowledges, { data: request }); await this.assignKnowledgeRepository.save(knowledges, { data: request });
setLogDataDiff(request, { before, after: knowledges }); setLogDataDiff(request, { before, after: knowledges });
const laws = await requestBody.assign_law.map( const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
(x: CreateAssignLaw, index: number) => ({
ordering: index + 1, ordering: index + 1,
law_id: x.id, law_id: x.id,
assign_id: assign.id, assign_id: assign.id,
@ -162,13 +143,11 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignLawRepository.save(laws, { data: request }); await this.assignLawRepository.save(laws, { data: request });
setLogDataDiff(request, { before, after: laws }); setLogDataDiff(request, { before, after: laws });
const skills = await requestBody.assign_skill.map( const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
(x: CreateAssignSkill, index: number) => ({
skill_id: index + 1, skill_id: index + 1,
skill_level: x.level, skill_level: x.level,
assign_id: assign.id, assign_id: assign.id,
@ -176,8 +155,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignSkillRepository.save(skills, { data: request }); await this.assignSkillRepository.save(skills, { data: request });
setLogDataDiff(request, { before, after: skills }); setLogDataDiff(request, { before, after: skills });
@ -192,9 +170,11 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignCompetencyRepository.save(competencise, { data: request }); await this.assignCompetencyRepository.save(competencise, {
data: request,
});
setLogDataDiff(request, { before, after: competencise }); setLogDataDiff(request, { before, after: competencise });
const competencyGroups = await requestBody.assign_competency_group.map( const competencyGroups = await requestBody.assign_competency_group.map(
@ -208,7 +188,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignCompetencyGroupRepository.save(competencyGroups, { await this.assignCompetencyGroupRepository.save(competencyGroups, {
data: request, data: request,
@ -224,7 +204,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignOutputRepository.save(outputs, { data: request }); await this.assignOutputRepository.save(outputs, { data: request });
setLogDataDiff(request, { before, after: outputs }); setLogDataDiff(request, { before, after: outputs });
@ -239,12 +219,17 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignDirectorRepository.save(directors, { data: request }); await this.assignDirectorRepository.save(directors, { data: request });
setLogDataDiff(request, { before, after: directors }); setLogDataDiff(request, { before, after: directors });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -257,8 +242,9 @@ export class AssignController extends Controller {
async EditAssign( async EditAssign(
@Query() assign_id: string, @Query() assign_id: string,
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Body() requestBody: CreateAssign @Body() requestBody: CreateAssign,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const assign = await this.assignRepository.findOne({ const assign = await this.assignRepository.findOne({
@ -291,8 +277,7 @@ export class AssignController extends Controller {
}; };
await this.assignJobRepository.delete({ assign_id }); await this.assignJobRepository.delete({ assign_id });
const jobs = await requestBody.assign_jobs.map( const jobs = await requestBody.assign_jobs.map((x: CreateAssignJob, index: number) => ({
(x: CreateAssignJob, index: number) => ({
...x, ...x,
id: index + 1, id: index + 1,
assign_id: assign.id, assign_id: assign.id,
@ -300,8 +285,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignJobRepository.save(jobs); await this.assignJobRepository.save(jobs);
await this.assignKnowledgeRepository.delete({ assign_id }); await this.assignKnowledgeRepository.delete({ assign_id });
@ -314,13 +298,12 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignKnowledgeRepository.save(knowledges); await this.assignKnowledgeRepository.save(knowledges);
await this.assignLawRepository.delete({ assign_id }); await this.assignLawRepository.delete({ assign_id });
const laws = await requestBody.assign_law.map( const laws = await requestBody.assign_law.map((x: CreateAssignLaw, index: number) => ({
(x: CreateAssignLaw, index: number) => ({
ordering: index + 1, ordering: index + 1,
law_id: x.id, law_id: x.id,
assign_id: assign.id, assign_id: assign.id,
@ -328,13 +311,11 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignLawRepository.save(laws); await this.assignLawRepository.save(laws);
await this.assignSkillRepository.delete({ assign_id }); await this.assignSkillRepository.delete({ assign_id });
const skills = await requestBody.assign_skill.map( const skills = await requestBody.assign_skill.map((x: CreateAssignSkill, index: number) => ({
(x: CreateAssignSkill, index: number) => ({
skill_id: index + 1, skill_id: index + 1,
skill_level: x.level, skill_level: x.level,
assign_id: assign.id, assign_id: assign.id,
@ -342,8 +323,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }));
);
await this.assignSkillRepository.save(skills); await this.assignSkillRepository.save(skills);
await this.assignCompetencyRepository.delete({ assign_id }); await this.assignCompetencyRepository.delete({ assign_id });
@ -358,7 +338,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignCompetencyRepository.save(competencise); await this.assignCompetencyRepository.save(competencise);
@ -374,7 +354,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignCompetencyGroupRepository.save(competencyGroups); await this.assignCompetencyGroupRepository.save(competencyGroups);
@ -388,7 +368,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignOutputRepository.save(outputs); await this.assignOutputRepository.save(outputs);
@ -403,7 +383,7 @@ export class AssignController extends Controller {
createdFullName: request.user.name, createdFullName: request.user.name,
updateUserId: request.user.sub, updateUserId: request.user.sub,
updateFullName: request.user.name, updateFullName: request.user.name,
}) }),
); );
await this.assignDirectorRepository.save(directors); await this.assignDirectorRepository.save(directors);
@ -473,6 +453,11 @@ export class AssignController extends Controller {
}); });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -482,17 +467,10 @@ export class AssignController extends Controller {
* *
*/ */
@Get("assign-list") @Get("assign-list")
async ListPersonal( async ListPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
@Request() request: RequestWithUser, try {
@Query() personal_id: string let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION");
) { if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
let _workflow = await new permission().Workflow(
request,
personal_id,
"SYS_PROBATION"
);
if (_workflow == false)
await new permission().PermissionGet(request, "SYS_PROBATION");
const lists = await this.assignRepository.find({ const lists = await this.assignRepository.find({
select: ["id", "round_no", "date_start", "date_finish"], select: ["id", "round_no", "date_start", "date_finish"],
where: { personal_id }, where: { personal_id },
@ -520,14 +498,10 @@ export class AssignController extends Controller {
} }
} }
const commanderData = await (director.find( const commanderData = await (director.find((x) => x.role == "commander") ?? null);
(x) => x.role == "commander"
) ?? null);
const commander = commanderData ? commanderData.fullname : null; const commander = commanderData ? commanderData.fullname : null;
const chairmanData = await (director.find( const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
(x) => x.role == "chairman"
) ?? null);
const chairman = chairmanData ? chairmanData.fullname : null; const chairman = chairmanData ? chairmanData.fullname : null;
await result.push({ await result.push({
@ -536,10 +510,15 @@ export class AssignController extends Controller {
commander: commander, commander: commander,
chairman: chairman, chairman: chairman,
}); });
}) }),
); );
return new HttpSuccess(result); return new HttpSuccess(result);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -549,10 +528,8 @@ export class AssignController extends Controller {
* *
*/ */
@Get("assign-user-list") @Get("assign-user-list")
async ListPersonalUser( async ListPersonalUser(@Request() request: RequestWithUser, @Query() personal_id: string) {
@Request() request: RequestWithUser, try {
@Query() personal_id: string
) {
const lists = await this.assignRepository.find({ const lists = await this.assignRepository.find({
select: ["id", "round_no", "date_start", "date_finish"], select: ["id", "round_no", "date_start", "date_finish"],
where: { personal_id }, where: { personal_id },
@ -580,14 +557,10 @@ export class AssignController extends Controller {
} }
} }
const commanderData = await (director.find( const commanderData = await (director.find((x) => x.role == "commander") ?? null);
(x) => x.role == "commander"
) ?? null);
const commander = commanderData ? commanderData.fullname : null; const commander = commanderData ? commanderData.fullname : null;
const chairmanData = await (director.find( const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
(x) => x.role == "chairman"
) ?? null);
const chairman = chairmanData ? chairmanData.fullname : null; const chairman = chairmanData ? chairmanData.fullname : null;
await result.push({ await result.push({
@ -596,10 +569,15 @@ export class AssignController extends Controller {
commander: commander, commander: commander,
chairman: chairman, chairman: chairman,
}); });
}) }),
); );
return new HttpSuccess(result); return new HttpSuccess(result);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -612,15 +590,11 @@ export class AssignController extends Controller {
async GetAssign( async GetAssign(
@Query() assign_id: string, @Query() assign_id: string,
@Query() isReport: boolean = false, @Query() isReport: boolean = false,
@Request() request: RequestWithUser @Request() request: RequestWithUser,
) { ) {
let _workflow = await new permission().Workflow( try {
request, let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION");
assign_id, if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
"SYS_PROBATION"
);
if (_workflow == false)
await new permission().PermissionGet(request, "SYS_PROBATION");
const assign = await this.assignRepository.findOne({ const assign = await this.assignRepository.findOne({
select: [ select: [
@ -657,6 +631,10 @@ export class AssignController extends Controller {
"positionLineName", "positionLineName",
"orgRootName", "orgRootName",
"organization", "organization",
"orgChild1Name",
"orgChild2Name",
"orgChild3Name",
"orgChild4Name",
], ],
where: { where: {
personal_id: assign.personal_id, personal_id: assign.personal_id,
@ -667,18 +645,20 @@ export class AssignController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
} }
const splitOc = await profileData.organization.split(" "); // const splitOc = await profileData.organization.split(" ");
const splitOcAmount = await splitOc.length; // const splitOcAmount = await splitOc.length;
const profile = { const profile = {
...profileData, ...profileData,
name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`, name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`,
Position: profileData.positionName, Position: profileData.positionName,
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", OrganizationOrganization: profileData.orgChild2Name
OrganizationOrganization: ? (profileData.orgChild4Name ? profileData.orgChild4Name + " " : "") +
splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", (profileData.orgChild3Name ? profileData.orgChild3Name + " " : "") +
(profileData.orgChild2Name ? profileData.orgChild2Name + " " : "")
: "-",
Department: profileData.orgChild1Name ?? "-",
Oc: profileData.orgRootName, Oc: profileData.orgRootName,
PositionAndLevel: PositionAndLevel: profileData.positionName + profileData.positionLevelName,
profileData.positionName + profileData.positionLevelName,
}; };
const jobs = await this.assignJobRepository.find({ const jobs = await this.assignJobRepository.find({
@ -731,7 +711,7 @@ export class AssignController extends Controller {
description: description, description: description,
status_select: x.status_select, status_select: x.status_select,
}; };
}) }),
); );
const skillsData = await this.assignSkillRepository.find({ const skillsData = await this.assignSkillRepository.find({
@ -758,12 +738,7 @@ export class AssignController extends Controller {
})); }));
const competencyData = await this.assignCompetencyRepository.find({ const competencyData = await this.assignCompetencyRepository.find({
select: [ select: ["competency_id", "competency_level", "competency_name", "competency_description"],
"competency_id",
"competency_level",
"competency_name",
"competency_description",
],
where: { assign_id }, where: { assign_id },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -775,8 +750,7 @@ export class AssignController extends Controller {
description: x.competency_description, description: x.competency_description,
})); }));
const competencyGroupData = await this.assignCompetencyGroupRepository.find( const competencyGroupData = await this.assignCompetencyGroupRepository.find({
{
select: [ select: [
"competency_group_id", "competency_group_id",
"competency_group_level", "competency_group_level",
@ -785,8 +759,7 @@ export class AssignController extends Controller {
], ],
where: { assign_id }, where: { assign_id },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
} });
);
const competency_groups = await competencyGroupData.map((x) => ({ const competency_groups = await competencyGroupData.map((x) => ({
id: x.competency_group_id, id: x.competency_group_id,
level: x.competency_group_level, level: x.competency_group_level,
@ -812,17 +785,13 @@ export class AssignController extends Controller {
mentors.push({ mentors.push({
...e, ...e,
name: e.fullname, name: e.fullname,
label: label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
e.fullname +
" " +
(e.position ? `(${e.position}${e.posLevel})` : ""),
Position: e.position + e.posLevel, // report Position: e.position + e.posLevel, // report
}); });
} }
} }
const commanderData = await (director.find((x) => x.role == "commander") ?? const commanderData = await (director.find((x) => x.role == "commander") ?? null);
null);
const commander = await (commanderData const commander = await (commanderData
? { ? {
...commanderData, ...commanderData,
@ -837,8 +806,7 @@ export class AssignController extends Controller {
} }
: null); : null);
const chairmanData = await (director.find((x) => x.role == "chairman") ?? const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
null);
const chairman = await (chairmanData const chairman = await (chairmanData
? { ? {
...chairmanData, ...chairmanData,
@ -846,9 +814,7 @@ export class AssignController extends Controller {
label: label:
chairmanData.fullname + chairmanData.fullname +
" " + " " +
(chairmanData.position (chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
? `(${chairmanData.position}${chairmanData.posLevel})`
: ""),
Position: chairmanData.position + chairmanData.posLevel, // report Position: chairmanData.position + chairmanData.posLevel, // report
} }
: null); : null);
@ -867,6 +833,11 @@ export class AssignController extends Controller {
commander, commander,
chairman, chairman,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -879,8 +850,9 @@ export class AssignController extends Controller {
async GetAssignUser( async GetAssignUser(
@Query() assign_id: string, @Query() assign_id: string,
@Query() isReport: boolean = false, @Query() isReport: boolean = false,
@Request() request: RequestWithUser @Request() request: RequestWithUser,
) { ) {
try {
const assign = await this.assignRepository.findOne({ const assign = await this.assignRepository.findOne({
select: [ select: [
"id", "id",
@ -916,6 +888,10 @@ export class AssignController extends Controller {
"positionLineName", "positionLineName",
"orgRootName", "orgRootName",
"organization", "organization",
"orgChild1Name",
"orgChild2Name",
"orgChild3Name",
"orgChild4Name",
], ],
where: { where: {
personal_id: assign.personal_id, personal_id: assign.personal_id,
@ -926,18 +902,20 @@ export class AssignController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
} }
const splitOc = await profileData.organization.split(" "); // const splitOc = await profileData.organization.split(" ");
const splitOcAmount = await splitOc.length; // const splitOcAmount = await splitOc.length;
const profile = { const profile = {
...profileData, ...profileData,
name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`, name: `${profileData.prefixName}${profileData.firstName} ${profileData.lastName}`,
Position: profileData.positionName, Position: profileData.positionName,
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", OrganizationOrganization: profileData.orgChild2Name
OrganizationOrganization: ? (profileData.orgChild4Name ? profileData.orgChild4Name + " " : "") +
splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", (profileData.orgChild3Name ? profileData.orgChild3Name + " " : "") +
(profileData.orgChild2Name ? profileData.orgChild2Name + " " : "")
: "-",
Department: profileData.orgChild1Name ?? "-",
Oc: profileData.orgRootName, Oc: profileData.orgRootName,
PositionAndLevel: PositionAndLevel: profileData.positionName + profileData.positionLevelName,
profileData.positionName + profileData.positionLevelName,
}; };
const jobs = await this.assignJobRepository.find({ const jobs = await this.assignJobRepository.find({
@ -990,7 +968,7 @@ export class AssignController extends Controller {
description: description, description: description,
status_select: x.status_select, status_select: x.status_select,
}; };
}) }),
); );
const skillsData = await this.assignSkillRepository.find({ const skillsData = await this.assignSkillRepository.find({
@ -1017,12 +995,7 @@ export class AssignController extends Controller {
})); }));
const competencyData = await this.assignCompetencyRepository.find({ const competencyData = await this.assignCompetencyRepository.find({
select: [ select: ["competency_id", "competency_level", "competency_name", "competency_description"],
"competency_id",
"competency_level",
"competency_name",
"competency_description",
],
where: { assign_id }, where: { assign_id },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
}); });
@ -1034,8 +1007,7 @@ export class AssignController extends Controller {
description: x.competency_description, description: x.competency_description,
})); }));
const competencyGroupData = await this.assignCompetencyGroupRepository.find( const competencyGroupData = await this.assignCompetencyGroupRepository.find({
{
select: [ select: [
"competency_group_id", "competency_group_id",
"competency_group_level", "competency_group_level",
@ -1044,8 +1016,7 @@ export class AssignController extends Controller {
], ],
where: { assign_id }, where: { assign_id },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
} });
);
const competency_groups = await competencyGroupData.map((x) => ({ const competency_groups = await competencyGroupData.map((x) => ({
id: x.competency_group_id, id: x.competency_group_id,
level: x.competency_group_level, level: x.competency_group_level,
@ -1071,17 +1042,13 @@ export class AssignController extends Controller {
mentors.push({ mentors.push({
...e, ...e,
name: e.fullname, name: e.fullname,
label: label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
e.fullname +
" " +
(e.position ? `(${e.position}${e.posLevel})` : ""),
Position: e.position + e.posLevel, // report Position: e.position + e.posLevel, // report
}); });
} }
} }
const commanderData = await (director.find((x) => x.role == "commander") ?? const commanderData = await (director.find((x) => x.role == "commander") ?? null);
null);
const commander = await (commanderData const commander = await (commanderData
? { ? {
...commanderData, ...commanderData,
@ -1096,8 +1063,7 @@ export class AssignController extends Controller {
} }
: null); : null);
const chairmanData = await (director.find((x) => x.role == "chairman") ?? const chairmanData = await (director.find((x) => x.role == "chairman") ?? null);
null);
const chairman = await (chairmanData const chairman = await (chairmanData
? { ? {
...chairmanData, ...chairmanData,
@ -1105,9 +1071,7 @@ export class AssignController extends Controller {
label: label:
chairmanData.fullname + chairmanData.fullname +
" " + " " +
(chairmanData.position (chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
? `(${chairmanData.position}${chairmanData.posLevel})`
: ""),
Position: chairmanData.position + chairmanData.posLevel, // report Position: chairmanData.position + chairmanData.posLevel, // report
} }
: null); : null);
@ -1126,5 +1090,10 @@ export class AssignController extends Controller {
commander, commander,
chairman, chairman,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -2,6 +2,8 @@ import { Controller, Route, Security, Tags, Request, Get, Path } from "tsoa";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import HttpError from "../interfaces/http-error";
import HttpStatusCode from "../interfaces/http-status";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import { AssignDirector } from "../entities/AssignDirector"; import { AssignDirector } from "../entities/AssignDirector";
@ -16,6 +18,7 @@ export class AssignPermissionsController extends Controller {
@Get("{id}") @Get("{id}")
async GetAssignPermissions(@Request() request: RequestWithUser, @Path() id: string) { async GetAssignPermissions(@Request() request: RequestWithUser, @Path() id: string) {
try {
const director = await this.assignDirector.find({ const director = await this.assignDirector.find({
where: { assign_id: id }, where: { assign_id: id },
}); });
@ -65,5 +68,10 @@ export class AssignPermissionsController extends Controller {
}; };
return new HttpSuccess(response); return new HttpSuccess(response);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -1,13 +1,28 @@
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body } from "tsoa" import {
import HttpSuccess from "../interfaces/http-success" Controller,
import HttpStatusCode from "../interfaces/http-status" Route,
import { RequestWithUser } from "../middlewares/user" Security,
import { findEndDate } from "../interfaces/utils" Tags,
Request,
SuccessResponse,
Response,
Get,
Post,
Body,
} from "tsoa";
import HttpSuccess from "../interfaces/http-success";
import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { RequestWithUser } from "../middlewares/user";
import { findEndDate } from "../interfaces/utils";
@Route("api/v1/probation/calculate") @Route("api/v1/probation/calculate")
@Tags("ฟอร์มมอบหมายงาน") @Tags("ฟอร์มมอบหมายงาน")
@Security("bearerAuth") @Security("bearerAuth")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
export class CalculateController extends Controller { export class CalculateController extends Controller {
/** /**
* API * API
@ -19,14 +34,20 @@ export class CalculateController extends Controller {
async AssignFinish( async AssignFinish(
@Body() @Body()
requestBody: { requestBody: {
month: number month: number;
start_date: Date start_date: Date;
}, },
@Request() request: RequestWithUser @Request() request: RequestWithUser,
) { ) {
const { month, start_date } = requestBody try {
const finish_date = findEndDate(month, start_date) const { month, start_date } = requestBody;
const finish_date = findEndDate(month, start_date);
return new HttpSuccess({ finish_date }) return new HttpSuccess({ finish_date });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -1,28 +1,41 @@
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Query } from "tsoa" import {
import { AppDataSource } from "../database/data-source" Controller,
import HttpSuccess from "../interfaces/http-success" Route,
import HttpStatusCode from "../interfaces/http-status" Security,
import HttpError from "../interfaces/http-error" Tags,
import { RequestWithUser } from "../middlewares/user" Request,
import { Knowledge, TypeKnowledge } from "../entities/Knowledge" SuccessResponse,
import { Skill, TypeSkill } from "../entities/Skill" Response,
import { MapKnowledgeSkill } from "../entities/MapKnowledgeSkill" Get,
import { Personal } from "../entities/Personal" Query,
import { Law } from "../entities/Law" } from "tsoa";
import { Assign } from "../entities/Assign" import { AppDataSource } from "../database/data-source";
import permission from "../interfaces/permission" 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") @Route("api/v1/probation/data-options")
@Tags("Data Options") @Tags("Data Options")
@Security("bearerAuth") @Security("bearerAuth")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
)
export class DataOptionController extends Controller { export class DataOptionController extends Controller {
private personalRepository = AppDataSource.getRepository(Personal) private personalRepository = AppDataSource.getRepository(Personal);
private knowledgeRepository = AppDataSource.getRepository(Knowledge) private knowledgeRepository = AppDataSource.getRepository(Knowledge);
private mapKnowledgeSkillRepository = AppDataSource.getRepository(MapKnowledgeSkill) private mapKnowledgeSkillRepository = AppDataSource.getRepository(MapKnowledgeSkill);
private skillRepository = AppDataSource.getRepository(Skill) private skillRepository = AppDataSource.getRepository(Skill);
private lawRepository = AppDataSource.getRepository(Law) private lawRepository = AppDataSource.getRepository(Law);
private assignRepository = AppDataSource.getRepository(Assign) private assignRepository = AppDataSource.getRepository(Assign);
/** /**
* API list * API list
@ -32,12 +45,13 @@ export class DataOptionController extends Controller {
*/ */
@Get("knowledge") @Get("knowledge")
async GetKnowledge(@Query() personal_id: string) { async GetKnowledge(@Query() personal_id: string) {
try {
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
where: { personal_id }, where: { personal_id },
}) });
if (!person) { if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
} }
let result = await this.mapKnowledgeSkillRepository.findOne({ let result = await this.mapKnowledgeSkillRepository.findOne({
@ -46,7 +60,7 @@ export class DataOptionController extends Controller {
positionLevelName: person.positionLevelName, positionLevelName: person.positionLevelName,
active: 1, active: 1,
}, },
}) });
if (!result) { if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้ // ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
@ -55,18 +69,18 @@ export class DataOptionController extends Controller {
positionLevelName: person.positionLevelName, positionLevelName: person.positionLevelName,
active: 1, active: 1,
}, },
}) });
} }
if (!result) { if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความรู้ที่ตรงกับตำแหน่ง") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลความรู้ที่ตรงกับตำแหน่ง");
} }
const knowledges = await this.knowledgeRepository.find({ const knowledges = await this.knowledgeRepository.find({
where: { type: TypeKnowledge.PERFORMANCE, active: 1 }, where: { type: TypeKnowledge.PERFORMANCE, active: 1 },
}) });
const knowledge = knowledges.map(knowledge => ({ const knowledge = knowledges.map((knowledge) => ({
id: knowledge.id, id: knowledge.id,
title: knowledge.title, title: knowledge.title,
description: description:
@ -80,9 +94,13 @@ export class DataOptionController extends Controller {
? knowledge.level4 ? knowledge.level4
: knowledge.level5, : knowledge.level5,
level: result.knowlage_performance_level, level: result.knowlage_performance_level,
})) }));
return new HttpSuccess(knowledge);
return new HttpSuccess(knowledge) } catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -93,44 +111,55 @@ export class DataOptionController extends Controller {
*/ */
@Get("skill") @Get("skill")
async GetSkill(@Query() personal_id: string) { async GetSkill(@Query() personal_id: string) {
try {
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
where: { personal_id }, where: { personal_id },
}) });
if (!person) { if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
let result = await this.mapKnowledgeSkillRepository.findOne({ let result = await this.mapKnowledgeSkillRepository.findOne({
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"], select: [
"skill_computer_level",
"skill_english_level",
"skill_information_level",
"skill_resourse_level",
],
where: { where: {
positionName: person.positionName, positionName: person.positionName,
positionLevelName: person.positionLevelName, positionLevelName: person.positionLevelName,
active: 1, active: 1,
}, },
}) });
if (!result) { if (!result) {
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้ // ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
result = await this.mapKnowledgeSkillRepository.findOne({ result = await this.mapKnowledgeSkillRepository.findOne({
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"], select: [
"skill_computer_level",
"skill_english_level",
"skill_information_level",
"skill_resourse_level",
],
where: { where: {
positionLevelName: person.positionLevelName, positionLevelName: person.positionLevelName,
active: 1, active: 1,
}, },
}) });
} }
if (!result) { if (!result) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง");
} }
const computerData = await this.skillRepository.findOne({ const computerData = await this.skillRepository.findOne({
where: { type: TypeSkill.COMPUTER, active: 1 }, where: { type: TypeSkill.COMPUTER, active: 1 },
}) });
if (!computerData) { if (!computerData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์");
} }
const computer = await { const computer = await {
id: computerData.id, id: computerData.id,
@ -146,14 +175,14 @@ export class DataOptionController extends Controller {
? computerData.level4 ? computerData.level4
: computerData.level5, : computerData.level5,
level: result.skill_computer_level, level: result.skill_computer_level,
} };
const englishData = await this.skillRepository.findOne({ const englishData = await this.skillRepository.findOne({
where: { type: TypeSkill.ENG, active: 1 }, where: { type: TypeSkill.ENG, active: 1 },
}) });
if (!englishData) { if (!englishData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ");
} }
const english = await { const english = await {
@ -170,14 +199,14 @@ export class DataOptionController extends Controller {
? englishData.level4 ? englishData.level4
: englishData.level5, : englishData.level5,
level: result.skill_english_level, level: result.skill_english_level,
} };
const informationData = await this.skillRepository.findOne({ const informationData = await this.skillRepository.findOne({
where: { type: TypeSkill.INFORMATION, active: 1 }, where: { type: TypeSkill.INFORMATION, active: 1 },
}) });
if (!informationData) { if (!informationData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const information = await { const information = await {
@ -194,13 +223,13 @@ export class DataOptionController extends Controller {
? informationData.level4 ? informationData.level4
: informationData.level5, : informationData.level5,
level: result.skill_information_level, level: result.skill_information_level,
} };
const resourseData = await this.skillRepository.findOne({ const resourseData = await this.skillRepository.findOne({
where: { type: TypeSkill.RESOURSE, active: 1 }, where: { type: TypeSkill.RESOURSE, active: 1 },
}) });
if (!resourseData) { if (!resourseData) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const resourse = await { const resourse = await {
@ -217,14 +246,19 @@ export class DataOptionController extends Controller {
? resourseData.level4 ? resourseData.level4
: resourseData.level5, : resourseData.level5,
level: result.skill_resourse_level, level: result.skill_resourse_level,
} };
return new HttpSuccess({ return new HttpSuccess({
computer, computer,
english, english,
information, information,
resourse, resourse,
}) });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -235,23 +269,29 @@ export class DataOptionController extends Controller {
*/ */
@Get("law") @Get("law")
async GetLaw(@Query() personal_id: string) { async GetLaw(@Query() personal_id: string) {
try {
const results = await this.lawRepository.find({ const results = await this.lawRepository.find({
select: ["id", "parent_id", "description", "status_select"], select: ["id", "parent_id", "description", "status_select"],
where: { where: {
active: 1, active: 1,
}, },
}) });
if (!results) { if (!results) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const result = await results.map(v => ({ const result = await results.map((v) => ({
...v, ...v,
checked: 0, checked: 0,
})) }));
return new HttpSuccess(result) return new HttpSuccess(result);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -262,8 +302,9 @@ export class DataOptionController extends Controller {
*/ */
@Get("new-assign") @Get("new-assign")
async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) { async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) {
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION") try {
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION") let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
select: [ select: [
@ -282,28 +323,33 @@ export class DataOptionController extends Controller {
"updatedAt", "updatedAt",
], ],
where: { personal_id }, where: { personal_id },
}) });
if (!person) { if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const assign = await this.assignRepository.count({ const assign = await this.assignRepository.count({
where: { where: {
personal_id, personal_id,
}, },
}) });
const responsePerson = { const responsePerson = {
id: person.personal_id, id: person.personal_id,
...person, ...person,
} };
return new HttpSuccess({ return new HttpSuccess({
person: responsePerson, person: responsePerson,
assign_no: assign + 1, assign_no: assign + 1,
assign_month: 6, assign_month: 6,
}) });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
* API (USER) * API (USER)
@ -313,6 +359,7 @@ export class DataOptionController extends Controller {
*/ */
@Get("new-assign-user") @Get("new-assign-user")
async NewAssignUser(@Query() personal_id: string, @Request() request: RequestWithUser) { async NewAssignUser(@Query() personal_id: string, @Request() request: RequestWithUser) {
try {
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
select: [ select: [
"personal_id", "personal_id",
@ -330,27 +377,32 @@ export class DataOptionController extends Controller {
"updatedAt", "updatedAt",
], ],
where: { personal_id }, where: { personal_id },
}) });
if (!person) { if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const assign = await this.assignRepository.count({ const assign = await this.assignRepository.count({
where: { where: {
personal_id, personal_id,
}, },
}) });
const responsePerson = { const responsePerson = {
id: person.personal_id, id: person.personal_id,
...person, ...person,
} };
return new HttpSuccess({ return new HttpSuccess({
person: responsePerson, person: responsePerson,
assign_no: assign + 1, assign_no: assign + 1,
assign_month: 6, assign_month: 6,
}) });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -22,24 +22,19 @@ import HttpError from "../interfaces/http-error";
import { Assign } from "../entities/Assign"; import { Assign } from "../entities/Assign";
import { Personal } from "../entities/Personal"; import { Personal } from "../entities/Personal";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
import { import { CreateEvaluateChairman, EvaluateChairman } from "../entities/EvaluateChairman";
CreateEvaluateChairman,
EvaluateChairman,
} from "../entities/EvaluateChairman";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
@Route("api/v1/probation/evaluate-chairman") @Route("api/v1/probation/evaluate-chairman")
@Tags("แบบประเมินผล (คณะกรรมการ)") @Tags("แบบประเมินผล (คณะกรรมการ)")
@Security("bearerAuth") @Security("bearerAuth")
@Response( @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR, HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง" "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง",
) )
export class EvaluateChairmanController extends Controller { export class EvaluateChairmanController extends Controller {
private assignDirectorRepository = private assignDirectorRepository = AppDataSource.getRepository(AssignDirector);
AppDataSource.getRepository(AssignDirector);
private assignRepository = AppDataSource.getRepository(Assign); private assignRepository = AppDataSource.getRepository(Assign);
private evaluateChairmanRepository = private evaluateChairmanRepository = AppDataSource.getRepository(EvaluateChairman);
AppDataSource.getRepository(EvaluateChairman);
private personalRepository = AppDataSource.getRepository(Personal); private personalRepository = AppDataSource.getRepository(Personal);
/** /**
@ -49,17 +44,10 @@ export class EvaluateChairmanController extends Controller {
* *
*/ */
@Get("create") @Get("create")
async CreateEvaluate( async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
@Query() assign_id: string, try {
@Request() request: RequestWithUser let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION");
) { if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
let _workflow = await new permission().Workflow(
request,
assign_id,
"SYS_PROBATION"
);
if (_workflow == false)
await new permission().PermissionGet(request, "SYS_PROBATION");
const director = await this.assignDirectorRepository.findOne({ const director = await this.assignDirectorRepository.findOne({
select: ["personal_id"], select: ["personal_id"],
@ -86,10 +74,7 @@ export class EvaluateChairmanController extends Controller {
...assign.profile, ...assign.profile,
id: assign.profile.personal_id, id: assign.profile.personal_id,
name: name:
assign.profile.prefixName + assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
assign.profile.firstName +
" " +
assign.profile.lastName,
Oc: assign.profile.organization, Oc: assign.profile.organization,
} }
: null); : null);
@ -112,10 +97,7 @@ export class EvaluateChairmanController extends Controller {
}); });
if (!directorData) { if (!directorData) {
throw new HttpError( throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
);
} }
let mentors = []; let mentors = [];
@ -128,10 +110,7 @@ export class EvaluateChairmanController extends Controller {
personal_id: e.personal_id, personal_id: e.personal_id,
dated: e.dated, dated: e.dated,
name: e.fullname, name: e.fullname,
label: label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
e.fullname +
" " +
(e.position ? `(${e.position}${e.posLevel})` : ""),
position: e.position, position: e.position,
posType: e.posType, posType: e.posType,
posLevel: e.posLevel, posLevel: e.posLevel,
@ -139,9 +118,7 @@ export class EvaluateChairmanController extends Controller {
} }
} }
const commanderData = await (directorData.find( const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
(x) => x.role == "commander"
) ?? null);
const commander = const commander =
commanderData != null commanderData != null
@ -161,9 +138,7 @@ export class EvaluateChairmanController extends Controller {
} }
: null; : null;
const chairmanData = await (directorData.find( const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
(x) => x.role == "chairman"
) ?? null);
const chairman = const chairman =
chairmanData != null chairmanData != null
? { ? {
@ -173,9 +148,7 @@ export class EvaluateChairmanController extends Controller {
label: label:
chairmanData.fullname + chairmanData.fullname +
" " + " " +
(chairmanData.position (chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
? `(${chairmanData.position}${chairmanData.posLevel})`
: ""),
position: chairmanData.position, position: chairmanData.position,
posType: chairmanData.posType, posType: chairmanData.posType,
posLevel: chairmanData.posLevel, posLevel: chairmanData.posLevel,
@ -192,6 +165,11 @@ export class EvaluateChairmanController extends Controller {
mentors, mentors,
chairman, chairman,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -204,8 +182,9 @@ export class EvaluateChairmanController extends Controller {
async GetEvaluate( async GetEvaluate(
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
@Query() assign_id: string, @Query() assign_id: string,
@Query() evaluate_no?: string @Query() evaluate_no?: string,
) { ) {
try {
await new permission().PermissionGet(request, "SYS_PROBATION"); await new permission().PermissionGet(request, "SYS_PROBATION");
// ต้องปรับเป็น id ของคนที่ access เข้ามา // ต้องปรับเป็น id ของคนที่ access เข้ามา
const director = await this.assignDirectorRepository.findOne({ const director = await this.assignDirectorRepository.findOne({
@ -279,10 +258,7 @@ export class EvaluateChairmanController extends Controller {
}); });
if (!directorData) { if (!directorData) {
throw new HttpError( throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
);
} }
let mentors = []; let mentors = [];
@ -295,10 +271,7 @@ export class EvaluateChairmanController extends Controller {
personal_id: e.personal_id, personal_id: e.personal_id,
dated: e.dated, dated: e.dated,
name: e.fullname, name: e.fullname,
label: label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
e.fullname +
" " +
(e.position ? `(${e.position}${e.posLevel})` : ""),
position: e.position, position: e.position,
posType: e.posType, posType: e.posType,
posLevel: e.posLevel, posLevel: e.posLevel,
@ -306,9 +279,7 @@ export class EvaluateChairmanController extends Controller {
} }
} }
const commanderData = await (directorData.find( const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
(x) => x.role == "commander"
) ?? null);
const commander = const commander =
commanderData != null commanderData != null
@ -328,9 +299,7 @@ export class EvaluateChairmanController extends Controller {
} }
: null; : null;
const chairmanData = await (directorData.find( const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
(x) => x.role == "chairman"
) ?? null);
const chairman = const chairman =
chairmanData != null chairmanData != null
? { ? {
@ -340,9 +309,7 @@ export class EvaluateChairmanController extends Controller {
label: label:
chairmanData.fullname + chairmanData.fullname +
" " + " " +
(chairmanData.position (chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
? `(${chairmanData.position}${chairmanData.posLevel})`
: ""),
position: chairmanData.position, position: chairmanData.position,
posType: chairmanData.posType, posType: chairmanData.posType,
posLevel: chairmanData.posLevel, posLevel: chairmanData.posLevel,
@ -357,6 +324,11 @@ export class EvaluateChairmanController extends Controller {
assign, assign,
evaluate, evaluate,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -369,8 +341,9 @@ export class EvaluateChairmanController extends Controller {
async PostData( async PostData(
@Query() assign_id: string, @Query() assign_id: string,
@Body() requestBody: CreateEvaluateChairman, @Body() requestBody: CreateEvaluateChairman,
@Request() request: RequestWithUser @Request() request: RequestWithUser,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const director = await this.assignDirectorRepository.findOne({ const director = await this.assignDirectorRepository.findOne({
@ -410,9 +383,7 @@ export class EvaluateChairmanController extends Controller {
: 0, : 0,
behavior_other_desc: requestBody.behavior_orther.text, behavior_other_desc: requestBody.behavior_orther.text,
behavior_other_level: behavior_other_level:
requestBody.behavior_orther.text != "" requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
? Number(requestBody.behavior_orther.level)
: 0,
createdUserId: request.user.sub, createdUserId: request.user.sub,
createdFullName: request.user.name, createdFullName: request.user.name,
@ -446,6 +417,11 @@ export class EvaluateChairmanController extends Controller {
} }
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -459,8 +435,9 @@ export class EvaluateChairmanController extends Controller {
// @Query() assign_id: string, // @Query() assign_id: string,
@Query() evaluate_id: string, @Query() evaluate_id: string,
@Body() requestBody: CreateEvaluateChairman, @Body() requestBody: CreateEvaluateChairman,
@Request() request: RequestWithUser @Request() request: RequestWithUser,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
let evaluate = await this.evaluateChairmanRepository.findOne({ let evaluate = await this.evaluateChairmanRepository.findOne({
@ -483,9 +460,7 @@ export class EvaluateChairmanController extends Controller {
? requestBody.achievement_other.text ? requestBody.achievement_other.text
: ""; : "";
evaluate.achievement_other_level = evaluate.achievement_other_level =
requestBody.achievement_other.text != "" requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0;
? Number(requestBody.achievement_other.level)
: 0;
evaluate.conduct1_level = requestBody.conduct1_level; evaluate.conduct1_level = requestBody.conduct1_level;
evaluate.conduct2_level = requestBody.conduct2_level; evaluate.conduct2_level = requestBody.conduct2_level;
@ -501,24 +476,15 @@ export class EvaluateChairmanController extends Controller {
evaluate.discipline5_level = requestBody.discipline5_level; evaluate.discipline5_level = requestBody.discipline5_level;
evaluate.behavior_other_desc = requestBody.behavior_orther.text; evaluate.behavior_other_desc = requestBody.behavior_orther.text;
evaluate.behavior_other_level = evaluate.behavior_other_level =
requestBody.behavior_orther.text != "" requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0;
? Number(requestBody.behavior_orther.level)
: 0;
evaluate.develop_orientation_score = requestBody.develop_orientation_score; evaluate.develop_orientation_score = requestBody.develop_orientation_score;
evaluate.develop_self_learning_score = evaluate.develop_self_learning_score = requestBody.develop_self_learning_score;
requestBody.develop_self_learning_score; evaluate.develop_training_seminar_score = requestBody.develop_training_seminar_score;
evaluate.develop_training_seminar_score = evaluate.develop_other_training_score = requestBody.develop_other_training_score;
requestBody.develop_training_seminar_score; evaluate.develop_orientation_percent = requestBody.develop_orientation_percent;
evaluate.develop_other_training_score = evaluate.develop_self_learning_percent = requestBody.develop_self_learning_percent;
requestBody.develop_other_training_score; evaluate.develop_training_seminar_percent = requestBody.develop_training_seminar_percent;
evaluate.develop_orientation_percent = evaluate.develop_other_training_percent = requestBody.develop_other_training_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.develop_result = requestBody.develop_result;
evaluate.achievement_score = requestBody.achievement_score; evaluate.achievement_score = requestBody.achievement_score;
evaluate.achievement_score_total = requestBody.achievement_score_total; evaluate.achievement_score_total = requestBody.achievement_score_total;
@ -539,5 +505,10 @@ export class EvaluateChairmanController extends Controller {
setLogDataDiff(request, { before, after: evaluate }); setLogDataDiff(request, { before, after: evaluate });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

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

File diff suppressed because it is too large Load diff

View file

@ -49,6 +49,7 @@ export class EvaluateResultController extends Controller {
*/ */
@Get("create") @Get("create")
async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) { async CreateEvaluate(@Query() assign_id: string, @Request() request: RequestWithUser) {
try {
let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION"); let _workflow = await new permission().Workflow(request, assign_id, "SYS_PROBATION");
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION"); if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
@ -153,7 +154,9 @@ export class EvaluateResultController extends Controller {
const result = await Promise.all( const result = await Promise.all(
resultData.map(async (e) => { resultData.map(async (e) => {
const check = await this.evaluateResultRepository.count({ where: { assign_id, no: e.no } }); const check = await this.evaluateResultRepository.count({
where: { assign_id, no: e.no },
});
const develop_complete = const develop_complete =
e.develop_orientation_score > 0 && e.develop_orientation_score > 0 &&
@ -210,6 +213,11 @@ export class EvaluateResultController extends Controller {
commander, commander,
chairman, chairman,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -224,6 +232,7 @@ export class EvaluateResultController extends Controller {
@Query() assign_id: string, @Query() assign_id: string,
@Query() evaluate_no?: string, @Query() evaluate_no?: string,
) { ) {
try {
await new permission().PermissionGet(request, "SYS_PROBATION"); await new permission().PermissionGet(request, "SYS_PROBATION");
// ต้องปรับเป็น id ของคนที่ access เข้ามา // ต้องปรับเป็น id ของคนที่ access เข้ามา
@ -268,6 +277,10 @@ export class EvaluateResultController extends Controller {
"positionLevelName", "positionLevelName",
"organization", "organization",
"orgRootName", "orgRootName",
"orgChild1Name",
"orgChild2Name",
"orgChild3Name",
"orgChild4Name",
], ],
where: { personal_id: assign.personal_id }, where: { personal_id: assign.personal_id },
}); });
@ -276,15 +289,22 @@ export class EvaluateResultController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
} }
const splitOc = await experimenteeData.organization.split(" "); // const splitOc = await experimenteeData.organization.split(" ");
const splitOcAmount = await splitOc.length; // const splitOcAmount = await splitOc.length;
const experimentee = await { const experimentee = await {
...experimenteeData, ...experimenteeData,
name: name:
experimenteeData.prefixName + experimenteeData.firstName + " " + experimenteeData.lastName, experimenteeData.prefixName +
experimenteeData.firstName +
" " +
experimenteeData.lastName,
PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName, PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName,
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-", OrganizationOrganization: experimenteeData.orgChild2Name
OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-", ? (experimenteeData.orgChild4Name ? experimenteeData.orgChild4Name + " " : "") +
(experimenteeData.orgChild3Name ? experimenteeData.orgChild3Name + " " : "") +
(experimenteeData.orgChild2Name ? experimenteeData.orgChild2Name + " " : "")
: "-",
Department: experimenteeData.orgChild1Name ?? "-",
Oc: experimenteeData.orgRootName, Oc: experimenteeData.orgRootName,
}; };
@ -368,6 +388,11 @@ export class EvaluateResultController extends Controller {
assign, assign,
evaluate: evaluate ? evaluate : null, evaluate: evaluate ? evaluate : null,
}); });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -382,6 +407,7 @@ export class EvaluateResultController extends Controller {
@Body() requestBody: CreateEvaluateResult, @Body() requestBody: CreateEvaluateResult,
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const director = await this.assignDirectorRepository.findOne({ const director = await this.assignDirectorRepository.findOne({
@ -426,6 +452,11 @@ export class EvaluateResultController extends Controller {
setLogDataDiff(request, { before: null, after: postData }); setLogDataDiff(request, { before: null, after: postData });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -440,6 +471,7 @@ export class EvaluateResultController extends Controller {
@Query() evaluate_no: number | string, @Query() evaluate_no: number | string,
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
const assign = await this.assignRepository.findOne({ const assign = await this.assignRepository.findOne({
@ -494,6 +526,11 @@ export class EvaluateResultController extends Controller {
await this.personalRepository.save(personal, { data: request }); await this.personalRepository.save(personal, { data: request });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -509,6 +546,7 @@ export class EvaluateResultController extends Controller {
@Body() requestBody: CreateEvaluateResult, @Body() requestBody: CreateEvaluateResult,
@Request() request: RequestWithUser, @Request() request: RequestWithUser,
) { ) {
try {
await new permission().PermissionUpdate(request, "SYS_PROBATION"); await new permission().PermissionUpdate(request, "SYS_PROBATION");
let evaluate = await this.evaluateResultRepository.findOne({ let evaluate = await this.evaluateResultRepository.findOne({
@ -584,5 +622,10 @@ export class EvaluateResultController extends Controller {
await this.personalRepository.save(personal, { data: request }); await this.personalRepository.save(personal, { data: request });
return new HttpSuccess(); return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
} }

View file

@ -1,22 +1,38 @@
import { Controller, Post, Route, Security, Tags, Body, Request, SuccessResponse, Response, Get, Query } from "tsoa" import {
import { AppDataSource } from "../database/data-source" Controller,
import HttpSuccess from "../interfaces/http-success" Post,
import HttpStatusCode from "../interfaces/http-status" Route,
import HttpError from "../interfaces/http-error" Security,
import { RequestWithUser } from "../middlewares/user" Tags,
import { setLogDataDiff } from "../interfaces/utils" Body,
import { Personal, PostPersonal } from "../entities/Personal" Request,
import permission from "../interfaces/permission" SuccessResponse,
import { Assign } from "../entities/Assign" Response,
import { Brackets } from "typeorm" 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 { Brackets } from "typeorm";
import CallAPI from "../interfaces/call-api";
@Route("api/v1/probation/personal") @Route("api/v1/probation/personal")
@Tags("Personal") @Tags("Personal")
@Security("bearerAuth") @Security("bearerAuth")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
)
export class PersonalController extends Controller { export class PersonalController extends Controller {
private personalRepository = AppDataSource.getRepository(Personal) private personalRepository = AppDataSource.getRepository(Personal);
private assignRepository = AppDataSource.getRepository(Assign) private assignRepository = AppDataSource.getRepository(Assign);
/** /**
* API * API
@ -25,63 +41,102 @@ export class PersonalController extends Controller {
* *
*/ */
@Post("add") @Post("add")
async AddPersonal(@Body() requestBody: PostPersonal, @Request() request: RequestWithUser) { async AddPersonal(
await new permission().PermissionCreate(request, "SYS_PROBATION") @Body() requestBody: PostPersonal,
@Request() request: RequestWithUser
) {
try {
await new permission().PermissionCreate(request, "SYS_PROBATION");
const checkPersonal: number = await this.personalRepository.count({ const checkPersonal: number = await this.personalRepository.count({
where: { personal_id: requestBody.id }, where: { personal_id: requestBody.id },
}) });
if (checkPersonal > 0) { if (checkPersonal > 0) {
throw new HttpError(HttpStatusCode.BAD_REQUEST, "ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว") throw new HttpError(
HttpStatusCode.BAD_REQUEST,
"ผู้ทดลองปฏิบัติหน้าที่ราชการนี้มีอยู่แล้ว"
);
} }
let organization = await (requestBody.orgChild4Name ? requestBody.orgChild4Name + " " : "") let organization = await (requestBody.orgChild4Name
organization += await (requestBody.orgChild3Name ? requestBody.orgChild3Name + " " : "") ? requestBody.orgChild4Name + "\n"
organization += await (requestBody.orgChild2Name ? requestBody.orgChild2Name + " " : "") : "");
organization += await (requestBody.orgChild1Name ? requestBody.orgChild1Name + " " : "") organization += await (requestBody.orgChild3Name
organization += await (requestBody.orgRootName ? requestBody.orgRootName : "") ? requestBody.orgChild3Name + "\n"
: "");
organization += await (requestBody.orgChild2Name
? requestBody.orgChild2Name + "\n"
: "");
organization += await (requestBody.orgChild1Name
? requestBody.orgChild1Name + "\n"
: "");
organization += await (requestBody.orgRootName
? requestBody.orgRootName
: "");
const personalData = Object.assign(new Personal()) const personalData = Object.assign(new Personal());
personalData.personal_id = requestBody.id personalData.personal_id = requestBody.id;
personalData.order_number = requestBody.order_number ? requestBody.order_number : "" personalData.order_number = requestBody.order_number
personalData.probation_status = 1 ? requestBody.order_number
personalData.createdUserId = request.user.sub : "";
personalData.createdFullName = request.user.name personalData.probation_status = 1;
personalData.updateUserId = request.user.sub personalData.createdUserId = request.user.sub;
personalData.updateFullName = request.user.name personalData.createdFullName = request.user.name;
personalData.updateUserId = request.user.sub;
personalData.updateFullName = request.user.name;
personalData.idcard = requestBody.idcard personalData.idcard = requestBody.idcard;
personalData.prefixName = requestBody.prefix personalData.prefixName = requestBody.prefix;
personalData.firstName = requestBody.firstName personalData.firstName = requestBody.firstName;
personalData.lastName = requestBody.lastName personalData.lastName = requestBody.lastName;
personalData.isProbation = requestBody.isProbation ? 1 : 0 personalData.isProbation = requestBody.isProbation ? 1 : 0;
personalData.positionLevelName = requestBody.posLevelName ? requestBody.posLevelName : "" personalData.positionLevelName = requestBody.posLevelName
personalData.positionName = requestBody.position ? requestBody.position : "" ? requestBody.posLevelName
personalData.positionLineName = requestBody.posLineName : "";
personalData.positionTypeName = requestBody.posTypeName personalData.positionName = requestBody.position
personalData.posNo = requestBody.posNo ? requestBody.posNo : "" ? requestBody.position
personalData.orgRootName = requestBody.orgRootName : "";
personalData.organization = organization personalData.positionLineName = requestBody.posLineName;
personalData.positionTypeName = requestBody.posTypeName;
personalData.posNo = requestBody.posNo ? requestBody.posNo : "";
personalData.orgRootName = requestBody.orgRootName;
personalData.organization = organization;
personalData.root = requestBody.root personalData.root = requestBody.root;
personalData.child1 = requestBody.child1 personalData.child1 = requestBody.child1;
personalData.child2 = requestBody.child2 personalData.child2 = requestBody.child2;
personalData.child3 = requestBody.child3 personalData.child3 = requestBody.child3;
personalData.child4 = requestBody.child4 personalData.child4 = requestBody.child4;
personalData.rootDna = requestBody.rootDna personalData.rootDna = requestBody.rootDna;
personalData.child1Dna = requestBody.child1Dna personalData.child1Dna = requestBody.orgChild1Dna;
personalData.child2Dna = requestBody.child2Dna personalData.child2Dna = requestBody.orgChild2Dna;
personalData.child3Dna = requestBody.child3Dna personalData.child3Dna = requestBody.orgChild3Dna;
personalData.child4Dna = requestBody.child4Dna personalData.child4Dna = requestBody.orgChild4Dna;
const before = null const getFieldValue = (field: string | null | undefined): string =>
field ?? "";
personalData.orgChild1Name = getFieldValue(requestBody.orgChild1Name);
personalData.orgChild2Name = getFieldValue(requestBody.orgChild2Name);
personalData.orgChild3Name = getFieldValue(requestBody.orgChild3Name);
personalData.orgChild4Name = getFieldValue(requestBody.orgChild4Name);
const before = null;
const personal = await this.personalRepository.save(personalData, { const personal = await this.personalRepository.save(personalData, {
data: request, data: request,
}) });
setLogDataDiff(request, { before, after: personal }) setLogDataDiff(request, { before, after: personal });
return new HttpSuccess() return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
}
} }
/** /**
@ -91,79 +146,187 @@ export class PersonalController extends Controller {
* *
*/ */
@Get("list") @Get("list")
async ListPersonal(@Query() status: string = "", @Query() keyword: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) { async ListPersonal(
await new permission().PermissionList(request, "SYS_PROBATION") @Query() status: string = "",
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION") @Query() keyword: string = "",
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Request() request: RequestWithUser
) {
try {
// await new permission().PermissionList(request, "SYS_PROBATION");
// const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION");
const conditions: any = {} let _data = await new permission().PermissionOrgList(
if (status) { request,
conditions.probation_status = status "SYS_DEV_PROJECT"
} );
await new CallAPI()
.PostData(request, "/org/finddna", _data)
.then((x) => {
_data = x;
})
.catch((x) => {});
if (_data.root != undefined && _data.root != null && _data.root[0] != null) { // const conditions: any = {};
conditions.root = _data.root // if (status) {
} // conditions.probation_status = status;
// }
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) { // if (
conditions.child1 = _data.child1 // _data.root != undefined &&
} // _data.root != null &&
// _data.root[0] != null
// ) {
// conditions.root = _data.root;
// }
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) { // if (
conditions.child2 = _data.child2 // _data.child1 != undefined &&
} // _data.child1 != null &&
// _data.child1[0] != null
// ) {
// conditions.child1 = _data.child1;
// }
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) { // if (
conditions.child3 = _data.child3 // _data.child2 != undefined &&
} // _data.child2 != null &&
// _data.child2[0] != null
// ) {
// conditions.child2 = _data.child2;
// }
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) { // if (
conditions.child4 = _data.child4 // _data.child3 != undefined &&
} // _data.child3 != null &&
// _data.child3[0] != null
// ) {
// conditions.child3 = _data.child3;
// }
const searchKeyword = await (keyword ? keyword.trim() : null) // if (
// _data.child4 != undefined &&
// _data.child4 != null &&
// _data.child4[0] != null
// ) {
// conditions.child4 = _data.child4;
// }
const searchKeyword = await (keyword ? keyword.trim() : null);
const [lists, total] = await AppDataSource.getRepository(Personal) const [lists, total] = await AppDataSource.getRepository(Personal)
.createQueryBuilder("personal") .createQueryBuilder("personal")
.where(conditions)
.andWhere( .andWhere(
new Brackets(qb => { _data.root != undefined && _data.root != null
qb.orWhere(searchKeyword ? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'` : "1=1", { ? _data.root[0] != null
? `personal.rootDna IN (:...root)`
: `personal.rootDna is null`
: "1=1",
{
root: _data.root,
}
)
.andWhere(
_data.child1 != undefined && _data.child1 != null
? _data.child1[0] != null
? `personal.child1Dna IN (:...child1)`
: `personal.child1Dna is null`
: "1=1",
{
child1: _data.child1,
}
)
.andWhere(
_data.child2 != undefined && _data.child2 != null
? _data.child2[0] != null
? `personal.child2Dna IN (:...child2)`
: `personal.child2Dna is null`
: "1=1",
{
child2: _data.child2,
}
)
.andWhere(
_data.child3 != undefined && _data.child3 != null
? _data.child3[0] != null
? `personal.child3Dna IN (:...child3)`
: `personal.child3Dna is null`
: "1=1",
{
child3: _data.child3,
}
)
.andWhere(
_data.child4 != undefined && _data.child4 != null
? _data.child4[0] != null
? `personal.child4Dna IN (:...child4)`
: `personal.child4Dna is null`
: "1=1",
{
child4: _data.child4,
}
)
.andWhere(
new Brackets((qb) => {
qb.orWhere(
searchKeyword
? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'`
: "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", { );
qb.orWhere(
searchKeyword ? `positionName like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", { );
qb.orWhere(
searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", { );
qb.orWhere(
searchKeyword ? `organization like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", { );
qb.orWhere(
searchKeyword ? `order_number like '%${keyword}%'` : "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
);
}) })
) )
.orderBy("updatedAt", "DESC") .orderBy("updatedAt", "DESC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount() .getManyAndCount();
if (!lists) { if (!lists) {
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้") throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"ไม่สามารถแสดงข้อมูลได้"
);
} }
let result: any = [] let result: any = [];
for (let i = 0; i < lists.length; i++) { for (let i = 0; i < lists.length; i++) {
const probation_no = await this.assignRepository.count({ const probation_no = await this.assignRepository.count({
where: { personal_id: lists[i].personal_id }, where: { personal_id: lists[i].personal_id },
}) });
await result.push({ await result.push({
personal_id: lists[i].personal_id, personal_id: lists[i].personal_id,
ordering: i + 1, ordering: i + 1,
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName, name:
lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
prefixName: lists[i].prefixName, prefixName: lists[i].prefixName,
firstName: lists[i].firstName, firstName: lists[i].firstName,
lastName: lists[i].lastName, lastName: lists[i].lastName,
@ -175,7 +338,7 @@ export class PersonalController extends Controller {
probation_no: probation_no, probation_no: probation_no,
order_number: lists[i].order_number, order_number: lists[i].order_number,
probation_status: lists[i].probation_status, probation_status: lists[i].probation_status,
}) });
} }
// await Promise.all( // await Promise.all(
// lists.map(async (item, index) => { // lists.map(async (item, index) => {
@ -204,7 +367,16 @@ export class PersonalController extends Controller {
// }), // }),
// ); // );
return new HttpSuccess({ data: result, total: total }) return new HttpSuccess({ data: result, total: total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
}
} }
/** /**
@ -214,20 +386,29 @@ export class PersonalController extends Controller {
* *
*/ */
@Get("") @Get("")
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) { async GetPersonal(
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION") @Request() request: RequestWithUser,
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION") @Query() personal_id: string
) {
try {
let _workflow = await new permission().Workflow(
request,
personal_id,
"SYS_PROBATION"
);
if (_workflow == false)
await new permission().PermissionGet(request, "SYS_PROBATION");
const person = await this.personalRepository.findOne({ const person = await this.personalRepository.findOne({
where: { personal_id: personal_id }, where: { personal_id: personal_id },
}) });
if (!person) { if (!person) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล") throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
} }
const probation_no = await this.assignRepository.count({ const probation_no = await this.assignRepository.count({
where: { personal_id: person.personal_id }, where: { personal_id: person.personal_id },
}) });
const result = await { const result = await {
personal_id: person.personal_id, personal_id: person.personal_id,
@ -239,8 +420,17 @@ export class PersonalController extends Controller {
probation_no: probation_no, probation_no: probation_no,
order_number: person.order_number, order_number: person.order_number,
probation_status: person.probation_status, probation_status: person.probation_status,
} };
return new HttpSuccess(result) return new HttpSuccess(result);
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else
throw new HttpError(
HttpStatusCode.INTERNAL_SERVER_ERROR,
error.message
);
}
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -1,23 +1,38 @@
import { Controller, Route, Security, Tags, Request, SuccessResponse, Response, Get, Post, Body, Query } from "tsoa" import {
import HttpSuccess from "../interfaces/http-success" Controller,
import HttpStatusCode from "../interfaces/http-status" Route,
import HttpError from "../interfaces/http-error" Security,
import { RequestWithUser } from "../middlewares/user" Tags,
import { setLogDataDiff } from "../interfaces/utils" Request,
import { Survey } from "../entities/Survey" SuccessResponse,
import { Assign } from "../entities/Assign" Response,
import { AppDataSource } from "../database/data-source" Get,
import CallAPI from "../interfaces/call-api" Post,
import permission from "../interfaces/permission" Body,
import { Brackets } from "typeorm" Query,
} from "tsoa";
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 { Survey } from "../entities/Survey";
import { Assign } from "../entities/Assign";
import { AppDataSource } from "../database/data-source";
import CallAPI from "../interfaces/call-api";
import permission from "../interfaces/permission";
import { Brackets } from "typeorm";
@Route("api/v1/probation/survey") @Route("api/v1/probation/survey")
@Tags("Survey") @Tags("Survey")
@Security("bearerAuth") @Security("bearerAuth")
@Response(HttpStatusCode.INTERNAL_SERVER_ERROR, "เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง") @Response(
HttpStatusCode.INTERNAL_SERVER_ERROR,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง"
)
export class SurveyController extends Controller { export class SurveyController extends Controller {
private surveyRepository = AppDataSource.getRepository(Survey) private surveyRepository = AppDataSource.getRepository(Survey);
private assignRepository = AppDataSource.getRepository(Assign) private assignRepository = AppDataSource.getRepository(Assign);
/** /**
* API * API
@ -27,26 +42,36 @@ export class SurveyController extends Controller {
*/ */
@Get("") @Get("")
async GetSurvey(@Request() request: RequestWithUser) { async GetSurvey(@Request() request: RequestWithUser) {
const personalId = await new CallAPI().GetData(request, "/org/profile/keycloak").catch(error => { try {
console.error("Error calling API:", error) const personalId = await new CallAPI().GetData(
}) request,
"/org/profile/keycloak"
);
const dataAssign = await this.assignRepository.findOne({ const dataAssign = await this.assignRepository.findOne({
select: ["id"], select: ["id"],
where: { personal_id: personalId }, where: { personal_id: personalId },
order: { date_start: "DESC" }, order: { date_start: "DESC" },
}) });
if (!dataAssign) { if (!dataAssign) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้") throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบผลการประเมินการทดลองปฏิบัติหน้าที่ราชการนี้"
);
} }
const assign_id = dataAssign.id const assign_id = dataAssign.id;
const data = await this.surveyRepository.findOne({ const data = await this.surveyRepository.findOne({
where: { where: {
assign_id, assign_id,
}, },
}) });
return new HttpSuccess({ data: data, assignId: assign_id }) return new HttpSuccess({ data: data, assignId: assign_id });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -56,23 +81,34 @@ export class SurveyController extends Controller {
* *
*/ */
@Post("") @Post("")
async PostSurvey(@Query() assign_id: string, @Body() requestBody: any, @Request() request: RequestWithUser) { async PostSurvey(
const personalId = await new CallAPI().GetData(request, "/org/profile/keycloak").catch(error => { @Query() assign_id: string,
console.error("Error calling API:", error) @Body() requestBody: any,
}) @Request() request: RequestWithUser
) {
try {
const personalId = await new CallAPI().GetData(
request,
"/org/profile/keycloak"
);
const before = null const before = null;
const data = await { const data = await {
...requestBody, ...requestBody,
personal_id: personalId, personal_id: personalId,
assign_id, assign_id,
createdUserId: request.user.sub, createdUserId: request.user.sub,
updateUserId: request.user.sub, updateUserId: request.user.sub,
} };
await this.surveyRepository.save(data, { data: request }) await this.surveyRepository.save(data, { data: request });
setLogDataDiff(request, { before, after: data }) setLogDataDiff(request, { before, after: data });
return new HttpSuccess() return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
} }
/** /**
@ -89,32 +125,44 @@ export class SurveyController extends Controller {
@Query("pageSize") pageSize: number = 10, @Query("pageSize") pageSize: number = 10,
@Request() request: RequestWithUser @Request() request: RequestWithUser
) { ) {
// await new permission().PermissionUpdate(request, "SYS_PROBATION"); try {
const start = new Date("01-01-" + year) const start = new Date("01-01-" + year);
const end = new Date("12-31-" + year) const end = new Date("12-31-" + year);
const searchKeyword = await (keyword ? keyword.trim() : null) const searchKeyword = await (keyword ? keyword.trim() : null);
const [lists, total] = await AppDataSource.getRepository(Survey) const [lists, total] = await AppDataSource.getRepository(Survey)
.createQueryBuilder("survey") .createQueryBuilder("survey")
.leftJoinAndSelect("survey.personal", "personal") .leftJoinAndSelect("survey.personal", "personal")
.where(`survey.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`) .where(
`survey.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`
)
.andWhere( .andWhere(
new Brackets(qb => { new Brackets((qb) => {
qb.orWhere(searchKeyword ? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'` : "1=1", { qb.orWhere(
searchKeyword
? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'`
: "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
qb.orWhere(searchKeyword ? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'` : "1=1", { );
qb.orWhere(
searchKeyword
? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'`
: "1=1",
{
keyword: `%${searchKeyword}%`, keyword: `%${searchKeyword}%`,
}) }
);
}) })
) )
.orderBy("survey.createdAt", "DESC") .orderBy("survey.createdAt", "DESC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)
.getManyAndCount() .getManyAndCount();
const data = lists.map(item => { const data = lists.map((item) => {
return { return {
createdAt: item.createdAt, createdAt: item.createdAt,
personal_id: item.personal_id, personal_id: item.personal_id,
@ -122,11 +170,21 @@ export class SurveyController extends Controller {
answer1: item.answer1, answer1: item.answer1,
answer2: item.answer2, answer2: item.answer2,
answer3: item.answer3, answer3: item.answer3,
fullname: item.personal ? `${item.personal.prefixName}${item.personal.firstName} ${item.personal.lastName}` : "", fullname: item.personal
position: item.personal ? `${item.personal.positionName}${item.personal.positionLevelName}` : "", ? `${item.personal.prefixName}${item.personal.firstName} ${item.personal.lastName}`
} : "",
}) position: item.personal
? `${item.personal.positionName}${item.personal.positionLevelName}`
: "",
};
});
return new HttpSuccess({ data, total: total }) return new HttpSuccess({ data, total: total });
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
}
// await new permission().PermissionUpdate(request, "SYS_PROBATION");
} }
} }

View file

@ -62,6 +62,7 @@ export const AppDataSource = new DataSource({
password: process.env.DB_PASSWORD, password: process.env.DB_PASSWORD,
connectorPackage: "mysql2", connectorPackage: "mysql2",
synchronize: false, synchronize: false,
timezone: "Z", // "Z" = UTC
logging: ["query", "error"], logging: ["query", "error"],
entities: entities:
process.env.NODE_ENV !== "production" process.env.NODE_ENV !== "production"

View file

@ -1,19 +1,19 @@
import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm" import { Entity, Column, PrimaryGeneratedColumn, OneToOne, JoinColumn, OneToMany } from "typeorm";
import { EntityBase } from "./base/Base" import { EntityBase } from "./base/Base";
import { Assign } from "./Assign" import { Assign } from "./Assign";
import { Appoint } from "./Appoint" import { Appoint } from "./Appoint";
import { Survey } from "./Survey" import { Survey } from "./Survey";
@Entity("personal") @Entity("personal")
export class Personal extends EntityBase { export class Personal extends EntityBase {
@PrimaryGeneratedColumn("uuid") @PrimaryGeneratedColumn("uuid")
personal_id: string personal_id: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "เลขที่คำสั่งบรรจุ", comment: "เลขที่คำสั่งบรรจุ",
}) })
order_number!: string order_number!: string;
@Column({ @Column({
nullable: false, nullable: false,
@ -21,210 +21,227 @@ export class Personal extends EntityBase {
"1 อยู่ระหว่างการทดลองปฏิบัติหน้าที่ราชการ, 2 พ้นการทดลองปฏิบัติหน้าที่ราชการ, 3 ไม่พ้นการทดลองปฏิบัติหน้าที่ราชการ, 4 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากเปลี่ยนตำแหน่ง, 5 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากลาออก, 6 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากถึงแก่กรรม, 7 ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการ, 8 ดึงรายชื่อไปออกคำสั่งแล้ว", "1 อยู่ระหว่างการทดลองปฏิบัติหน้าที่ราชการ, 2 พ้นการทดลองปฏิบัติหน้าที่ราชการ, 3 ไม่พ้นการทดลองปฏิบัติหน้าที่ราชการ, 4 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากเปลี่ยนตำแหน่ง, 5 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากลาออก, 6 ยุติการทดลองปฏิบัติหน้าที่ราชการเนื่องจากถึงแก่กรรม, 7 ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการ, 8 ดึงรายชื่อไปออกคำสั่งแล้ว",
default: 1, default: 1,
}) })
probation_status: number probation_status: number;
@Column({ @Column({
nullable: false, nullable: false,
comment: "สถานะการใช้งาน 1 คือใช้งานปกติ, 0 คือไม่ใช้งาน", comment: "สถานะการใช้งาน 1 คือใช้งานปกติ, 0 คือไม่ใช้งาน",
default: 1, default: 1,
}) })
active: number active: number;
@Column({ @Column({
nullable: true, nullable: true,
comment: "คำนำหน้าชื่อ", comment: "คำนำหน้าชื่อ",
}) })
prefixName: string prefixName: string;
@Column({ @Column({
nullable: false, nullable: false,
comment: "ชื่อ", comment: "ชื่อ",
}) })
firstName: string firstName: string;
@Column({ @Column({
nullable: false, nullable: false,
comment: "นามสกุล", comment: "นามสกุล",
}) })
lastName: string lastName: string;
@Column({ @Column({
type: Boolean, type: Boolean,
comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน", comment: "สถานะการทดลองงาน 1 คืออยู่ระหว่างการทดลองงาน, 0 คือไม่อยู่ระหว่างการทดลองงาน",
default: 0, default: 0,
}) })
isProbation: number isProbation: number;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ตำแหน่งในสายงาน", comment: "ตำแหน่งในสายงาน",
}) })
positionName: string positionName: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "เลขที่ตำแหน่ง", comment: "เลขที่ตำแหน่ง",
}) })
posNo: string posNo: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ระดับตำแหน่ง", comment: "ระดับตำแหน่ง",
}) })
positionLevelName: string positionLevelName: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ด้าน/สาขา", comment: "ด้าน/สาขา",
}) })
positionLineName: string positionLineName: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "ประเภทตำแหน่ง", comment: "ประเภทตำแหน่ง",
}) })
positionTypeName: string positionTypeName: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "หน่วยงาน", comment: "หน่วยงาน",
}) })
orgRootName: string orgRootName: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "สังกัด", comment: "สังกัด",
}) })
organization: string organization: string;
@Column({ @Column({
nullable: true, nullable: true,
comment: "เลขบัตรประจำตัวประชาชน", comment: "เลขบัตรประจำตัวประชาชน",
}) })
idcard: string idcard: string;
@Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน root", default: null })
root: string root: string;
@Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null })
child1: string child1: string;
@Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null })
child2: string child2: string;
@Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null })
child3: string child3: string;
@Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null })
child4: string child4: string;
@Column({ nullable: true, comment: "id หน่วยงาน root", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน root", default: null })
rootDna: string rootDna: string;
@Column({ nullable: true, comment: "id หน่วยงาน child1", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child1", default: null })
child1Dna: string child1Dna: string;
@Column({ nullable: true, comment: "id หน่วยงาน child2", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child2", default: null })
child2Dna: string child2Dna: string;
@Column({ nullable: true, comment: "id หน่วยงาน child3", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child3", default: null })
child3Dna: string child3Dna: string;
@Column({ nullable: true, comment: "id หน่วยงาน child4", default: null }) @Column({ nullable: true, comment: "id หน่วยงาน child4", default: null })
child4Dna: string child4Dna: string;
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child1", default: null })
orgChild1Name: string;
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child2", default: null })
orgChild2Name: string;
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child3", default: null })
orgChild3Name: string;
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child4", default: null })
orgChild4Name: string;
@OneToMany(() => Assign, (assign: Assign) => assign.personal_id) @OneToMany(() => Assign, (assign: Assign) => assign.personal_id)
@JoinColumn({ name: "id" }) @JoinColumn({ name: "id" })
assign: Assign[] assign: Assign[];
@OneToOne(() => Appoint, appoint => appoint.personal) @OneToOne(() => Appoint, (appoint) => appoint.personal)
@JoinColumn() @JoinColumn()
appoint: Appoint appoint: Appoint;
@OneToOne(() => Survey, { nullable: true }) @OneToOne(() => Survey, { nullable: true })
survey: Survey | null survey: Survey | null;
} }
export class CreatePersonal { export class CreatePersonal {
@Column() @Column()
personal_id: string personal_id: string;
@Column() @Column()
order_number: string order_number: string;
@Column() @Column()
probation_status: number probation_status: number;
// @Column() // @Column()
// profiles: PersonalProfile; // profiles: PersonalProfile;
@Column() @Column()
createdUserId: string createdUserId: string;
@Column() @Column()
createdFullName: string createdFullName: string;
@Column() @Column()
updateUserId: string updateUserId: string;
@Column() @Column()
updateFullName: string updateFullName: string;
@Column() @Column()
prefixName: string prefixName: string;
@Column() @Column()
firstName: string firstName: string;
@Column() @Column()
lastName: string lastName: string;
@Column() @Column()
isProbation: number isProbation: number;
@Column() @Column()
positionName: string positionName: string;
@Column() @Column()
posNo: string posNo: string;
@Column() @Column()
positionLevelName: string positionLevelName: string;
@Column() @Column()
positionTypeName: string positionTypeName: string;
@Column() @Column()
positionLineName: string positionLineName: string;
@Column() @Column()
orgRootName: string orgRootName: string;
@Column() @Column()
organization: string organization: string;
@Column() @Column()
idcard: string idcard: string;
} }
export class PostPersonal { export class PostPersonal {
id: string id: string;
prefix: string prefix: string;
firstName: string firstName: string;
lastName: string lastName: string;
isProbation: boolean isProbation: boolean;
posTypeName?: string | null posTypeName?: string | null;
posLevelName: string | null posLevelName: string | null;
position: string | null position: string | null;
posLineName?: string | null posLineName?: string | null;
posNo?: string | null posNo?: string | null;
organization?: string organization?: string;
orgRootName: string | null orgRootName: string | null;
orgChild1Name?: string | null orgChild1Name?: string | null;
orgChild2Name?: string | null orgChild2Name?: string | null;
orgChild3Name?: string | null orgChild3Name?: string | null;
orgChild4Name?: string | null orgChild4Name?: string | null;
order_number?: string order_number?: string;
rank?: string | null rank?: string | null;
idcard?: string idcard?: string;
positionField?: string | null positionField?: string | null;
positionArea?: string | null positionArea?: string | null;
posExecutiveName?: string | null posExecutiveName?: string | null;
positionExecutiveField?: string | null positionExecutiveField?: string | null;
root?: string | null root?: string | null;
child1?: string | null child1?: string | null;
child2?: string | null child2?: string | null;
child3?: string | null child3?: string | null;
child4?: string | null child4?: string | null;
rootDna?: string | null rootDna?: string | null;
child1Dna?: string | null child1Dna?: string | null;
child2Dna?: string | null child2Dna?: string | null;
child3Dna?: string | null child3Dna?: string | null;
child4Dna?: string | null child4Dna?: string | null;
orgChild1Dna?: string | null;
orgChild2Dna?: string | null;
orgChild3Dna?: string | null;
orgChild4Dna?: string | null;
} }
export type UpdatePersonal = Partial<CreatePersonal> export type UpdatePersonal = Partial<CreatePersonal>;

View file

@ -19,10 +19,20 @@ export type LogSequence = {
}; };
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) { export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
// Check if data.before and data.after are valid objects
if (
data.before &&
typeof data.before === "object" &&
data.after &&
typeof data.after === "object"
) {
req.app.locals.logData.dataDiff = { req.app.locals.logData.dataDiff = {
before: JSON.stringify(data.before), before: JSON.stringify(data.before),
after: JSON.stringify(data.after), after: JSON.stringify(data.after),
}; };
} else {
console.error("Invalid data provided: both before and after must be valid objects.");
}
} }
export function addLogSequence(req: RequestWithUser, data: LogSequence) { export function addLogSequence(req: RequestWithUser, data: LogSequence) {

View file

@ -0,0 +1,20 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class PersonalAddChildName1749186876022 implements MigrationInterface {
name = 'PersonalAddChildName1749186876022'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild1Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child1'`);
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild2Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child2'`);
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild3Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child3'`);
await queryRunner.query(`ALTER TABLE \`personal\` ADD \`orgChild4Name\` varchar(255) NULL COMMENT 'ชื่อ หน่วยงาน child4'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild4Name\``);
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild3Name\``);
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild2Name\``);
await queryRunner.query(`ALTER TABLE \`personal\` DROP COLUMN \`orgChild1Name\``);
}
}