Merge branch 'develop' into dev
This commit is contained in:
commit
e6cf5d312a
19 changed files with 7074 additions and 6019 deletions
33
package-lock.json
generated
33
package-lock.json
generated
|
|
@ -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",
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
39
src/app.ts
39
src/app.ts
|
|
@ -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(
|
||||||
|
`[APP] Application is running on: http://localhost:${APP_PORT}`
|
||||||
|
),
|
||||||
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
|
console.log(`[APP] Swagger on: http://localhost:${APP_PORT}/api-docs`)
|
||||||
),
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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) {
|
||||||
const appoint = await this.appointRepository.find({
|
try {
|
||||||
relations: ["directors"],
|
const appoint = await this.appointRepository.find({
|
||||||
where: { profileId: id, status: "DONE" },
|
relations: ["directors"],
|
||||||
});
|
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,19 +119,27 @@ export class AppointController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post("")
|
@Post("")
|
||||||
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
async Create(@Request() request: RequestWithUser, @Body() requestBody: CreateAppoint) {
|
||||||
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionCreate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const data: any = {
|
const data: any = {
|
||||||
topic: requestBody.topic,
|
topic: requestBody.topic,
|
||||||
profileId: requestBody.profileId,
|
profileId: requestBody.profileId,
|
||||||
createdUserId: request.user.sub,
|
createdUserId: request.user.sub,
|
||||||
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, {
|
||||||
setLogDataDiff(request, { before, after: appoint });
|
data: request,
|
||||||
|
});
|
||||||
|
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,16 +150,22 @@ 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) {
|
||||||
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
try {
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
let _workflow = await new permission().Workflow(request, id, "SYS_PROBATION");
|
||||||
|
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const appoint = await this.appointRepository.findOne({
|
const appoint = await this.appointRepository.findOne({
|
||||||
select: ["id", "topic", "status", "profileId"],
|
select: ["id", "topic", "status", "profileId"],
|
||||||
where: { id },
|
where: { id },
|
||||||
relations: ["directors"],
|
relations: ["directors"],
|
||||||
});
|
});
|
||||||
|
|
||||||
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,36 +180,42 @@ export class AppointController extends Controller {
|
||||||
@Body() requestBody: UpdateAppoint,
|
@Body() requestBody: UpdateAppoint,
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const appoint: any = await this.appointRepository.findOne({
|
const appoint: any = await this.appointRepository.findOne({
|
||||||
where: { id },
|
where: { id },
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!appoint) {
|
if (!appoint) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการแต่งตั้งคณะกรรมการฯ");
|
||||||
|
}
|
||||||
|
|
||||||
|
const before = appoint;
|
||||||
|
|
||||||
|
appoint.topic = requestBody.topic;
|
||||||
|
appoint.updateUserId = request.user.sub;
|
||||||
|
appoint.updateFullName = request.user.name;
|
||||||
|
await this.appointDirectorRepository.delete({ appointId: id });
|
||||||
|
const directors: any = await requestBody.persons.map((x: Person) => ({
|
||||||
|
...x,
|
||||||
|
appointId: id,
|
||||||
|
createdUserId: request.user.sub,
|
||||||
|
createdFullName: request.user.name,
|
||||||
|
updateUserId: request.user.sub,
|
||||||
|
updateFullName: request.user.name,
|
||||||
|
}));
|
||||||
|
await this.appointDirectorRepository.save(directors);
|
||||||
|
|
||||||
|
await this.appointRepository.save(appoint, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: appoint });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const before = appoint;
|
|
||||||
|
|
||||||
appoint.topic = requestBody.topic;
|
|
||||||
appoint.updateUserId = request.user.sub;
|
|
||||||
appoint.updateFullName = request.user.name;
|
|
||||||
await this.appointDirectorRepository.delete({ appointId: id });
|
|
||||||
const directors: any = await requestBody.persons.map((x: Person) => ({
|
|
||||||
...x,
|
|
||||||
appointId: id,
|
|
||||||
createdUserId: request.user.sub,
|
|
||||||
createdFullName: request.user.name,
|
|
||||||
updateUserId: request.user.sub,
|
|
||||||
updateFullName: request.user.name,
|
|
||||||
}));
|
|
||||||
await this.appointDirectorRepository.save(directors);
|
|
||||||
|
|
||||||
await this.appointRepository.save(appoint, { data: request });
|
|
||||||
setLogDataDiff(request, { before, after: appoint });
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -195,14 +226,20 @@ 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) {
|
||||||
await new permission().PermissionDelete(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionDelete(request, "SYS_PROBATION");
|
||||||
|
|
||||||
await this.appointDirectorRepository.delete({ appointId: id });
|
await this.appointDirectorRepository.delete({ appointId: id });
|
||||||
|
|
||||||
const result = await this.appointRepository.delete({ id });
|
const result = await this.appointRepository.delete({ id });
|
||||||
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,27 +250,33 @@ 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) {
|
||||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
const directorId = await new CallAPI()
|
const directorId = await new CallAPI()
|
||||||
.GetData(request, "/org/profile/keycloak")
|
.GetData(request, "/org/profile/keycloak")
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error calling API:", error);
|
console.error("Error calling API:", error);
|
||||||
});
|
});
|
||||||
|
|
||||||
const appoint = await AppDataSource.getRepository(Appoint)
|
const appoint = await AppDataSource.getRepository(Appoint)
|
||||||
.createQueryBuilder("appoint")
|
.createQueryBuilder("appoint")
|
||||||
.leftJoinAndSelect("appoint.directors", "directors")
|
.leftJoinAndSelect("appoint.directors", "directors")
|
||||||
.where(
|
.where(
|
||||||
"appoint.profileId = :profileId and directors.profileId = :directorId and directors.role = 'committee'",
|
"appoint.profileId = :profileId and directors.profileId = :directorId and directors.role = 'committee'",
|
||||||
{
|
{
|
||||||
directorId,
|
directorId,
|
||||||
profileId,
|
profileId,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.orderBy("appoint.createdAt", "DESC")
|
.orderBy("appoint.createdAt", "DESC")
|
||||||
.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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
File diff suppressed because it is too large
Load diff
|
|
@ -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,54 +18,60 @@ 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) {
|
||||||
const director = await this.assignDirector.find({
|
try {
|
||||||
where: { assign_id: id },
|
const director = await this.assignDirector.find({
|
||||||
});
|
where: { assign_id: id },
|
||||||
|
|
||||||
const personalId = await new CallAPI()
|
|
||||||
.GetData(request, "/org/profile/keycloak")
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error calling API:", error);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const role = await director.find((e: any) => e.personal_id === personalId)?.role;
|
const personalId = await new CallAPI()
|
||||||
|
.GetData(request, "/org/profile/keycloak")
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error calling API:", error);
|
||||||
|
});
|
||||||
|
|
||||||
const reportPersonId = await this.assignRepository.findOneBy({
|
const role = await director.find((e: any) => e.personal_id === personalId)?.role;
|
||||||
id,
|
|
||||||
reportPersonId: personalId,
|
|
||||||
});
|
|
||||||
|
|
||||||
const response = {
|
const reportPersonId = await this.assignRepository.findOneBy({
|
||||||
tab1: {
|
id,
|
||||||
isEdit: role === "commander",
|
reportPersonId: personalId,
|
||||||
isView: true,
|
});
|
||||||
},
|
|
||||||
tab2: {
|
|
||||||
isEdit: role === "mentor",
|
|
||||||
isView: true,
|
|
||||||
},
|
|
||||||
tab3: {
|
|
||||||
isEdit: role === "commander",
|
|
||||||
isView: role === "commander" || role === "chairman",
|
|
||||||
},
|
|
||||||
tab4: {
|
|
||||||
isEdit: role === "commander",
|
|
||||||
isView: role === "commander" || role === "chairman",
|
|
||||||
},
|
|
||||||
tab5: {
|
|
||||||
isEdit: Boolean(reportPersonId),
|
|
||||||
isView: true,
|
|
||||||
},
|
|
||||||
tab6: {
|
|
||||||
isEdit: true,
|
|
||||||
isView: true,
|
|
||||||
},
|
|
||||||
tab7: {
|
|
||||||
isEdit: false,
|
|
||||||
isView: true,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
return new HttpSuccess(response);
|
const response = {
|
||||||
|
tab1: {
|
||||||
|
isEdit: role === "commander",
|
||||||
|
isView: true,
|
||||||
|
},
|
||||||
|
tab2: {
|
||||||
|
isEdit: role === "mentor",
|
||||||
|
isView: true,
|
||||||
|
},
|
||||||
|
tab3: {
|
||||||
|
isEdit: role === "commander",
|
||||||
|
isView: role === "commander" || role === "chairman",
|
||||||
|
},
|
||||||
|
tab4: {
|
||||||
|
isEdit: role === "commander",
|
||||||
|
isView: role === "commander" || role === "chairman",
|
||||||
|
},
|
||||||
|
tab5: {
|
||||||
|
isEdit: Boolean(reportPersonId),
|
||||||
|
isView: true,
|
||||||
|
},
|
||||||
|
tab6: {
|
||||||
|
isEdit: true,
|
||||||
|
isView: true,
|
||||||
|
},
|
||||||
|
tab7: {
|
||||||
|
isEdit: false,
|
||||||
|
isView: true,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
return new HttpSuccess(response);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,53 @@
|
||||||
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 คำนวนวันสิ้นสุดตามวันที่เริ่มและระยะเวลาเดือนตามที่ส่งค่ามา
|
||||||
*
|
*
|
||||||
* @summary คำนวนวันสิ้นสุดตามวันที่เริ่มและระยะเวลาเดือนตามที่ส่งค่ามา
|
* @summary คำนวนวันสิ้นสุดตามวันที่เริ่มและระยะเวลาเดือนตามที่ส่งค่ามา
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Post("assign-finish")
|
@Post("assign-finish")
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,356 +1,408 @@
|
||||||
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 รายการความรู้
|
||||||
*
|
*
|
||||||
* @summary options ความรู้
|
* @summary options ความรู้
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("knowledge")
|
@Get("knowledge")
|
||||||
async GetKnowledge(@Query() personal_id: string) {
|
async GetKnowledge(@Query() personal_id: string) {
|
||||||
const person = await this.personalRepository.findOne({
|
try {
|
||||||
where: { personal_id },
|
const person = await this.personalRepository.findOne({
|
||||||
})
|
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({
|
||||||
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({
|
||||||
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 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:
|
||||||
result.knowlage_performance_level == 1
|
result.knowlage_performance_level == 1
|
||||||
? knowledge.level1
|
? knowledge.level1
|
||||||
: result.knowlage_performance_level == 2
|
: result.knowlage_performance_level == 2
|
||||||
? knowledge.level2
|
? knowledge.level2
|
||||||
: result.knowlage_performance_level == 3
|
: result.knowlage_performance_level == 3
|
||||||
? knowledge.level3
|
? knowledge.level3
|
||||||
: result.knowlage_performance_level == 4
|
: result.knowlage_performance_level == 4
|
||||||
? knowledge.level4
|
? knowledge.level4
|
||||||
: knowledge.level5,
|
: knowledge.level5,
|
||||||
level: result.knowlage_performance_level,
|
level: result.knowlage_performance_level,
|
||||||
}))
|
}));
|
||||||
|
return new HttpSuccess(knowledge);
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new HttpSuccess(knowledge)
|
/**
|
||||||
}
|
* API ข้อมูลทักษะ
|
||||||
|
*
|
||||||
|
* @summary options ทักษะ
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("skill")
|
||||||
|
async GetSkill(@Query() personal_id: string) {
|
||||||
|
try {
|
||||||
|
const person = await this.personalRepository.findOne({
|
||||||
|
where: { personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
if (!person) {
|
||||||
* API ข้อมูลทักษะ
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
*
|
}
|
||||||
* @summary options ทักษะ
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("skill")
|
|
||||||
async GetSkill(@Query() personal_id: string) {
|
|
||||||
const person = await this.personalRepository.findOne({
|
|
||||||
where: { personal_id },
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!person) {
|
let result = await this.mapKnowledgeSkillRepository.findOne({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
select: [
|
||||||
}
|
"skill_computer_level",
|
||||||
|
"skill_english_level",
|
||||||
|
"skill_information_level",
|
||||||
|
"skill_resourse_level",
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
positionName: person.positionName,
|
||||||
|
positionLevelName: person.positionLevelName,
|
||||||
|
active: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
let result = await this.mapKnowledgeSkillRepository.findOne({
|
if (!result) {
|
||||||
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"],
|
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
|
||||||
where: {
|
result = await this.mapKnowledgeSkillRepository.findOne({
|
||||||
positionName: person.positionName,
|
select: [
|
||||||
positionLevelName: person.positionLevelName,
|
"skill_computer_level",
|
||||||
active: 1,
|
"skill_english_level",
|
||||||
},
|
"skill_information_level",
|
||||||
})
|
"skill_resourse_level",
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
positionLevelName: person.positionLevelName,
|
||||||
|
active: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
if (!result) {
|
if (!result) {
|
||||||
// ถ้าตำแหน่งไม่ตรงหาจากระดับตำแหน่งแทนเพื่อให้ฟอร์มสามารถกรอกต่อได้
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง");
|
||||||
result = await this.mapKnowledgeSkillRepository.findOne({
|
}
|
||||||
select: ["skill_computer_level", "skill_english_level", "skill_information_level", "skill_resourse_level"],
|
|
||||||
where: {
|
|
||||||
positionLevelName: person.positionLevelName,
|
|
||||||
active: 1,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!result) {
|
const computerData = await this.skillRepository.findOne({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะที่ตรงกับตำแหน่ง")
|
where: { type: TypeSkill.COMPUTER, active: 1 },
|
||||||
}
|
});
|
||||||
|
|
||||||
const computerData = await this.skillRepository.findOne({
|
if (!computerData) {
|
||||||
where: { type: TypeSkill.COMPUTER, active: 1 },
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์");
|
||||||
})
|
}
|
||||||
|
const computer = await {
|
||||||
|
id: computerData.id,
|
||||||
|
title: computerData.title,
|
||||||
|
level_description:
|
||||||
|
result.skill_computer_level == 1
|
||||||
|
? computerData.level1
|
||||||
|
: result.skill_computer_level == 2
|
||||||
|
? computerData.level2
|
||||||
|
: result.skill_computer_level == 3
|
||||||
|
? computerData.level3
|
||||||
|
: result.skill_computer_level == 4
|
||||||
|
? computerData.level4
|
||||||
|
: computerData.level5,
|
||||||
|
level: result.skill_computer_level,
|
||||||
|
};
|
||||||
|
|
||||||
if (!computerData) {
|
const englishData = await this.skillRepository.findOne({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะคอมพิวเตอร์")
|
where: { type: TypeSkill.ENG, active: 1 },
|
||||||
}
|
});
|
||||||
const computer = await {
|
|
||||||
id: computerData.id,
|
|
||||||
title: computerData.title,
|
|
||||||
level_description:
|
|
||||||
result.skill_computer_level == 1
|
|
||||||
? computerData.level1
|
|
||||||
: result.skill_computer_level == 2
|
|
||||||
? computerData.level2
|
|
||||||
: result.skill_computer_level == 3
|
|
||||||
? computerData.level3
|
|
||||||
: result.skill_computer_level == 4
|
|
||||||
? computerData.level4
|
|
||||||
: computerData.level5,
|
|
||||||
level: result.skill_computer_level,
|
|
||||||
}
|
|
||||||
|
|
||||||
const englishData = await this.skillRepository.findOne({
|
if (!englishData) {
|
||||||
where: { type: TypeSkill.ENG, active: 1 },
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ");
|
||||||
})
|
}
|
||||||
|
|
||||||
if (!englishData) {
|
const english = await {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลทักษะภาษาอังกฤษ")
|
id: englishData.id,
|
||||||
}
|
title: englishData.title,
|
||||||
|
level_description:
|
||||||
|
result.skill_english_level == 1
|
||||||
|
? englishData.level1
|
||||||
|
: result.skill_english_level == 2
|
||||||
|
? englishData.level2
|
||||||
|
: result.skill_english_level == 3
|
||||||
|
? englishData.level3
|
||||||
|
: result.skill_english_level == 4
|
||||||
|
? englishData.level4
|
||||||
|
: englishData.level5,
|
||||||
|
level: result.skill_english_level,
|
||||||
|
};
|
||||||
|
|
||||||
const english = await {
|
const informationData = await this.skillRepository.findOne({
|
||||||
id: englishData.id,
|
where: { type: TypeSkill.INFORMATION, active: 1 },
|
||||||
title: englishData.title,
|
});
|
||||||
level_description:
|
|
||||||
result.skill_english_level == 1
|
|
||||||
? englishData.level1
|
|
||||||
: result.skill_english_level == 2
|
|
||||||
? englishData.level2
|
|
||||||
: result.skill_english_level == 3
|
|
||||||
? englishData.level3
|
|
||||||
: result.skill_english_level == 4
|
|
||||||
? englishData.level4
|
|
||||||
: englishData.level5,
|
|
||||||
level: result.skill_english_level,
|
|
||||||
}
|
|
||||||
|
|
||||||
const informationData = await this.skillRepository.findOne({
|
if (!informationData) {
|
||||||
where: { type: TypeSkill.INFORMATION, active: 1 },
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
})
|
}
|
||||||
|
|
||||||
if (!informationData) {
|
const information = await {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
id: informationData.id,
|
||||||
}
|
title: informationData.title,
|
||||||
|
level_description:
|
||||||
|
result.skill_information_level == 1
|
||||||
|
? informationData.level1
|
||||||
|
: result.skill_information_level == 2
|
||||||
|
? informationData.level2
|
||||||
|
: result.skill_information_level == 3
|
||||||
|
? informationData.level3
|
||||||
|
: result.skill_information_level == 4
|
||||||
|
? informationData.level4
|
||||||
|
: informationData.level5,
|
||||||
|
level: result.skill_information_level,
|
||||||
|
};
|
||||||
|
|
||||||
const information = await {
|
const resourseData = await this.skillRepository.findOne({
|
||||||
id: informationData.id,
|
where: { type: TypeSkill.RESOURSE, active: 1 },
|
||||||
title: informationData.title,
|
});
|
||||||
level_description:
|
if (!resourseData) {
|
||||||
result.skill_information_level == 1
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
? informationData.level1
|
}
|
||||||
: result.skill_information_level == 2
|
|
||||||
? informationData.level2
|
|
||||||
: result.skill_information_level == 3
|
|
||||||
? informationData.level3
|
|
||||||
: result.skill_information_level == 4
|
|
||||||
? informationData.level4
|
|
||||||
: informationData.level5,
|
|
||||||
level: result.skill_information_level,
|
|
||||||
}
|
|
||||||
|
|
||||||
const resourseData = await this.skillRepository.findOne({
|
const resourse = await {
|
||||||
where: { type: TypeSkill.RESOURSE, active: 1 },
|
id: resourseData.id,
|
||||||
})
|
title: resourseData.title,
|
||||||
if (!resourseData) {
|
level_description:
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
result.skill_resourse_level == 1
|
||||||
}
|
? resourseData.level1
|
||||||
|
: result.skill_resourse_level == 2
|
||||||
|
? resourseData.level2
|
||||||
|
: result.skill_resourse_level == 3
|
||||||
|
? resourseData.level3
|
||||||
|
: result.skill_resourse_level == 4
|
||||||
|
? resourseData.level4
|
||||||
|
: resourseData.level5,
|
||||||
|
level: result.skill_resourse_level,
|
||||||
|
};
|
||||||
|
|
||||||
const resourse = await {
|
return new HttpSuccess({
|
||||||
id: resourseData.id,
|
computer,
|
||||||
title: resourseData.title,
|
english,
|
||||||
level_description:
|
information,
|
||||||
result.skill_resourse_level == 1
|
resourse,
|
||||||
? resourseData.level1
|
});
|
||||||
: result.skill_resourse_level == 2
|
} catch (error: any) {
|
||||||
? resourseData.level2
|
if (error instanceof HttpError) {
|
||||||
: result.skill_resourse_level == 3
|
throw error;
|
||||||
? resourseData.level3
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
: result.skill_resourse_level == 4
|
}
|
||||||
? resourseData.level4
|
}
|
||||||
: resourseData.level5,
|
|
||||||
level: result.skill_resourse_level,
|
|
||||||
}
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
/**
|
||||||
computer,
|
* API list รายการกฎหมาย
|
||||||
english,
|
*
|
||||||
information,
|
* @summary options กฎหมาย
|
||||||
resourse,
|
*
|
||||||
})
|
*/
|
||||||
}
|
@Get("law")
|
||||||
|
async GetLaw(@Query() personal_id: string) {
|
||||||
|
try {
|
||||||
|
const results = await this.lawRepository.find({
|
||||||
|
select: ["id", "parent_id", "description", "status_select"],
|
||||||
|
where: {
|
||||||
|
active: 1,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
if (!results) {
|
||||||
* API list รายการกฎหมาย
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
*
|
}
|
||||||
* @summary options กฎหมาย
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("law")
|
|
||||||
async GetLaw(@Query() personal_id: string) {
|
|
||||||
const results = await this.lawRepository.find({
|
|
||||||
select: ["id", "parent_id", "description", "status_select"],
|
|
||||||
where: {
|
|
||||||
active: 1,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!results) {
|
const result = await results.map((v) => ({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
...v,
|
||||||
}
|
checked: 0,
|
||||||
|
}));
|
||||||
|
|
||||||
const result = await results.map(v => ({
|
return new HttpSuccess(result);
|
||||||
...v,
|
} catch (error: any) {
|
||||||
checked: 0,
|
if (error instanceof HttpError) {
|
||||||
}))
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return new HttpSuccess(result)
|
/**
|
||||||
}
|
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
||||||
|
*
|
||||||
|
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("new-assign")
|
||||||
|
async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) {
|
||||||
|
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({
|
||||||
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
select: [
|
||||||
*
|
"personal_id",
|
||||||
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง
|
"prefixName",
|
||||||
*
|
"firstName",
|
||||||
*/
|
"lastName",
|
||||||
@Get("new-assign")
|
"posNo",
|
||||||
async NewAssign(@Query() personal_id: string, @Request() request: RequestWithUser) {
|
"positionName",
|
||||||
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION")
|
"positionLevelName",
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
"positionLineName",
|
||||||
|
"isProbation",
|
||||||
|
"orgRootName",
|
||||||
|
"organization",
|
||||||
|
"createdAt",
|
||||||
|
"updatedAt",
|
||||||
|
],
|
||||||
|
where: { personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
const person = await this.personalRepository.findOne({
|
if (!person) {
|
||||||
select: [
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
"personal_id",
|
}
|
||||||
"prefixName",
|
|
||||||
"firstName",
|
|
||||||
"lastName",
|
|
||||||
"posNo",
|
|
||||||
"positionName",
|
|
||||||
"positionLevelName",
|
|
||||||
"positionLineName",
|
|
||||||
"isProbation",
|
|
||||||
"orgRootName",
|
|
||||||
"organization",
|
|
||||||
"createdAt",
|
|
||||||
"updatedAt",
|
|
||||||
],
|
|
||||||
where: { personal_id },
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!person) {
|
const assign = await this.assignRepository.count({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
where: {
|
||||||
}
|
personal_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const assign = await this.assignRepository.count({
|
const responsePerson = {
|
||||||
where: {
|
id: person.personal_id,
|
||||||
personal_id,
|
...person,
|
||||||
},
|
};
|
||||||
})
|
|
||||||
|
|
||||||
const responsePerson = {
|
return new HttpSuccess({
|
||||||
id: person.personal_id,
|
person: responsePerson,
|
||||||
...person,
|
assign_no: assign + 1,
|
||||||
}
|
assign_month: 6,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
||||||
|
*
|
||||||
|
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("new-assign-user")
|
||||||
|
async NewAssignUser(@Query() personal_id: string, @Request() request: RequestWithUser) {
|
||||||
|
try {
|
||||||
|
const person = await this.personalRepository.findOne({
|
||||||
|
select: [
|
||||||
|
"personal_id",
|
||||||
|
"prefixName",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"posNo",
|
||||||
|
"positionName",
|
||||||
|
"positionLevelName",
|
||||||
|
"positionLineName",
|
||||||
|
"isProbation",
|
||||||
|
"orgRootName",
|
||||||
|
"organization",
|
||||||
|
"createdAt",
|
||||||
|
"updatedAt",
|
||||||
|
],
|
||||||
|
where: { personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
return new HttpSuccess({
|
if (!person) {
|
||||||
person: responsePerson,
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
|
||||||
assign_no: assign + 1,
|
}
|
||||||
assign_month: 6,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* API ดึงข้อมูลจำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
|
||||||
*
|
|
||||||
* @summary จำนวนครั้งแบบมอบหมายงานและข้อมูลผู้ทดลอง (USER)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
@Get("new-assign-user")
|
|
||||||
async NewAssignUser(@Query() personal_id: string, @Request() request: RequestWithUser) {
|
|
||||||
const person = await this.personalRepository.findOne({
|
|
||||||
select: [
|
|
||||||
"personal_id",
|
|
||||||
"prefixName",
|
|
||||||
"firstName",
|
|
||||||
"lastName",
|
|
||||||
"posNo",
|
|
||||||
"positionName",
|
|
||||||
"positionLevelName",
|
|
||||||
"positionLineName",
|
|
||||||
"isProbation",
|
|
||||||
"orgRootName",
|
|
||||||
"organization",
|
|
||||||
"createdAt",
|
|
||||||
"updatedAt",
|
|
||||||
],
|
|
||||||
where: { personal_id },
|
|
||||||
})
|
|
||||||
|
|
||||||
if (!person) {
|
const assign = await this.assignRepository.count({
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล")
|
where: {
|
||||||
}
|
personal_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
const assign = await this.assignRepository.count({
|
const responsePerson = {
|
||||||
where: {
|
id: person.personal_id,
|
||||||
personal_id,
|
...person,
|
||||||
},
|
};
|
||||||
})
|
|
||||||
|
|
||||||
const responsePerson = {
|
return new HttpSuccess({
|
||||||
id: person.personal_id,
|
person: responsePerson,
|
||||||
...person,
|
assign_no: assign + 1,
|
||||||
}
|
assign_month: 6,
|
||||||
|
});
|
||||||
return new HttpSuccess({
|
} catch (error: any) {
|
||||||
person: responsePerson,
|
if (error instanceof HttpError) {
|
||||||
assign_no: assign + 1,
|
throw error;
|
||||||
assign_month: 6,
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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,149 +44,132 @@ 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"],
|
||||||
where: {
|
where: {
|
||||||
assign_id,
|
assign_id,
|
||||||
role: "chairman",
|
role: "chairman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!director) {
|
if (!director) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||||
}
|
|
||||||
const director_id = director.personal_id;
|
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
|
||||||
relations: ["profile"],
|
|
||||||
where: { id: assign_id },
|
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const profile = await (assign.profile
|
|
||||||
? {
|
|
||||||
...assign.profile,
|
|
||||||
id: assign.profile.personal_id,
|
|
||||||
name:
|
|
||||||
assign.profile.prefixName +
|
|
||||||
assign.profile.firstName +
|
|
||||||
" " +
|
|
||||||
assign.profile.lastName,
|
|
||||||
Oc: assign.profile.organization,
|
|
||||||
}
|
|
||||||
: null);
|
|
||||||
|
|
||||||
const evaluate_amount = await this.evaluateChairmanRepository.count({
|
|
||||||
where: {
|
|
||||||
assign_id,
|
|
||||||
director_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const evaluate_no = await (evaluate_amount + 1);
|
|
||||||
const start_date =
|
|
||||||
evaluate_amount == 0
|
|
||||||
? assign.date_start
|
|
||||||
: findEndDate(evaluate_amount * 3, assign.date_start);
|
|
||||||
|
|
||||||
const directorData = await this.assignDirectorRepository.find({
|
|
||||||
where: { assign_id },
|
|
||||||
order: { ordering: "ASC" },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!directorData) {
|
|
||||||
throw new HttpError(
|
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentors = [];
|
|
||||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
|
||||||
if (mentorList.length > 0) {
|
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
|
||||||
const e = await mentorList[index];
|
|
||||||
|
|
||||||
mentors.push({
|
|
||||||
personal_id: e.personal_id,
|
|
||||||
dated: e.dated,
|
|
||||||
name: e.fullname,
|
|
||||||
label:
|
|
||||||
e.fullname +
|
|
||||||
" " +
|
|
||||||
(e.position ? `(${e.position}${e.posLevel})` : ""),
|
|
||||||
position: e.position,
|
|
||||||
posType: e.posType,
|
|
||||||
posLevel: e.posLevel,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const director_id = director.personal_id;
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
relations: ["profile"],
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const profile = await (assign.profile
|
||||||
|
? {
|
||||||
|
...assign.profile,
|
||||||
|
id: assign.profile.personal_id,
|
||||||
|
name:
|
||||||
|
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
|
||||||
|
Oc: assign.profile.organization,
|
||||||
|
}
|
||||||
|
: null);
|
||||||
|
|
||||||
|
const evaluate_amount = await this.evaluateChairmanRepository.count({
|
||||||
|
where: {
|
||||||
|
assign_id,
|
||||||
|
director_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
const evaluate_no = await (evaluate_amount + 1);
|
||||||
|
const start_date =
|
||||||
|
evaluate_amount == 0
|
||||||
|
? assign.date_start
|
||||||
|
: findEndDate(evaluate_amount * 3, assign.date_start);
|
||||||
|
|
||||||
|
const directorData = await this.assignDirectorRepository.find({
|
||||||
|
where: { assign_id },
|
||||||
|
order: { ordering: "ASC" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!directorData) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentors = [];
|
||||||
|
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||||
|
if (mentorList.length > 0) {
|
||||||
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
|
const e = await mentorList[index];
|
||||||
|
|
||||||
|
mentors.push({
|
||||||
|
personal_id: e.personal_id,
|
||||||
|
dated: e.dated,
|
||||||
|
name: e.fullname,
|
||||||
|
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||||
|
position: e.position,
|
||||||
|
posType: e.posType,
|
||||||
|
posLevel: e.posLevel,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
||||||
|
|
||||||
|
const commander =
|
||||||
|
commanderData != null
|
||||||
|
? {
|
||||||
|
personal_id: commanderData.personal_id,
|
||||||
|
dated: commanderData.dated,
|
||||||
|
name: commanderData.fullname,
|
||||||
|
label:
|
||||||
|
commanderData.fullname +
|
||||||
|
" " +
|
||||||
|
(commanderData.position
|
||||||
|
? `(${commanderData.position}${commanderData.posLevel})`
|
||||||
|
: ""),
|
||||||
|
position: commanderData.position,
|
||||||
|
posType: commanderData.posType,
|
||||||
|
posLevel: commanderData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||||
|
const chairman =
|
||||||
|
chairmanData != null
|
||||||
|
? {
|
||||||
|
personal_id: chairmanData.personal_id,
|
||||||
|
dated: chairmanData.dated,
|
||||||
|
name: chairmanData.fullname,
|
||||||
|
label:
|
||||||
|
chairmanData.fullname +
|
||||||
|
" " +
|
||||||
|
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||||
|
position: chairmanData.position,
|
||||||
|
posType: chairmanData.posType,
|
||||||
|
posLevel: chairmanData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
person: profile ? profile : null,
|
||||||
|
assign,
|
||||||
|
evaluate_no: evaluate_no,
|
||||||
|
start_date: start_date,
|
||||||
|
end_date: findEndDate(3, start_date),
|
||||||
|
commander,
|
||||||
|
mentors,
|
||||||
|
chairman,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commanderData = await (directorData.find(
|
|
||||||
(x) => x.role == "commander"
|
|
||||||
) ?? null);
|
|
||||||
|
|
||||||
const commander =
|
|
||||||
commanderData != null
|
|
||||||
? {
|
|
||||||
personal_id: commanderData.personal_id,
|
|
||||||
dated: commanderData.dated,
|
|
||||||
name: commanderData.fullname,
|
|
||||||
label:
|
|
||||||
commanderData.fullname +
|
|
||||||
" " +
|
|
||||||
(commanderData.position
|
|
||||||
? `(${commanderData.position}${commanderData.posLevel})`
|
|
||||||
: ""),
|
|
||||||
position: commanderData.position,
|
|
||||||
posType: commanderData.posType,
|
|
||||||
posLevel: commanderData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const chairmanData = await (directorData.find(
|
|
||||||
(x) => x.role == "chairman"
|
|
||||||
) ?? null);
|
|
||||||
const chairman =
|
|
||||||
chairmanData != null
|
|
||||||
? {
|
|
||||||
personal_id: chairmanData.personal_id,
|
|
||||||
dated: chairmanData.dated,
|
|
||||||
name: chairmanData.fullname,
|
|
||||||
label:
|
|
||||||
chairmanData.fullname +
|
|
||||||
" " +
|
|
||||||
(chairmanData.position
|
|
||||||
? `(${chairmanData.position}${chairmanData.posLevel})`
|
|
||||||
: ""),
|
|
||||||
position: chairmanData.position,
|
|
||||||
posType: chairmanData.posType,
|
|
||||||
posLevel: chairmanData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
|
||||||
person: profile ? profile : null,
|
|
||||||
assign,
|
|
||||||
evaluate_no: evaluate_no,
|
|
||||||
start_date: start_date,
|
|
||||||
end_date: findEndDate(3, start_date),
|
|
||||||
commander,
|
|
||||||
mentors,
|
|
||||||
chairman,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -204,159 +182,153 @@ 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,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
try {
|
||||||
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
const director = await this.assignDirectorRepository.findOne({
|
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
||||||
select: ["personal_id"],
|
const director = await this.assignDirectorRepository.findOne({
|
||||||
where: {
|
select: ["personal_id"],
|
||||||
assign_id,
|
|
||||||
role: "chairman",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (!director) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
|
||||||
}
|
|
||||||
const director_id = director.personal_id;
|
|
||||||
let evaluate: any = null;
|
|
||||||
if (evaluate_no) {
|
|
||||||
evaluate = await this.evaluateChairmanRepository.findOne({
|
|
||||||
where: {
|
where: {
|
||||||
director_id,
|
|
||||||
assign_id,
|
assign_id,
|
||||||
no: evaluate_no,
|
role: "chairman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} else {
|
if (!director) {
|
||||||
evaluate = await this.evaluateChairmanRepository.find({
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||||
where: {
|
|
||||||
director_id,
|
|
||||||
assign_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (evaluate)
|
|
||||||
evaluate = await evaluate.map((element: EvaluateChairman) => ({
|
|
||||||
...element,
|
|
||||||
no: Number(element.no),
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!evaluate) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
|
||||||
where: { id: assign_id },
|
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const experimenteeData = await this.personalRepository.find({
|
|
||||||
select: [
|
|
||||||
"personal_id",
|
|
||||||
"prefixName",
|
|
||||||
"firstName",
|
|
||||||
"lastName",
|
|
||||||
"positionName",
|
|
||||||
"positionLevelName",
|
|
||||||
"organization",
|
|
||||||
],
|
|
||||||
where: { personal_id: assign.personal_id },
|
|
||||||
});
|
|
||||||
|
|
||||||
const experimentee = await experimenteeData.map((element) => ({
|
|
||||||
...element,
|
|
||||||
name: element.prefixName + element.firstName + " " + element.lastName,
|
|
||||||
Oc: element.organization,
|
|
||||||
}));
|
|
||||||
|
|
||||||
const directorData = await this.assignDirectorRepository.find({
|
|
||||||
where: { assign_id },
|
|
||||||
order: { ordering: "ASC" },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!directorData) {
|
|
||||||
throw new HttpError(
|
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentors = [];
|
|
||||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
|
||||||
if (mentorList.length > 0) {
|
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
|
||||||
const e = await mentorList[index];
|
|
||||||
|
|
||||||
mentors.push({
|
|
||||||
personal_id: e.personal_id,
|
|
||||||
dated: e.dated,
|
|
||||||
name: e.fullname,
|
|
||||||
label:
|
|
||||||
e.fullname +
|
|
||||||
" " +
|
|
||||||
(e.position ? `(${e.position}${e.posLevel})` : ""),
|
|
||||||
position: e.position,
|
|
||||||
posType: e.posType,
|
|
||||||
posLevel: e.posLevel,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const director_id = director.personal_id;
|
||||||
|
let evaluate: any = null;
|
||||||
|
if (evaluate_no) {
|
||||||
|
evaluate = await this.evaluateChairmanRepository.findOne({
|
||||||
|
where: {
|
||||||
|
director_id,
|
||||||
|
assign_id,
|
||||||
|
no: evaluate_no,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
evaluate = await this.evaluateChairmanRepository.find({
|
||||||
|
where: {
|
||||||
|
director_id,
|
||||||
|
assign_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (evaluate)
|
||||||
|
evaluate = await evaluate.map((element: EvaluateChairman) => ({
|
||||||
|
...element,
|
||||||
|
no: Number(element.no),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!evaluate) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบประเมิน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const experimenteeData = await this.personalRepository.find({
|
||||||
|
select: [
|
||||||
|
"personal_id",
|
||||||
|
"prefixName",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"positionName",
|
||||||
|
"positionLevelName",
|
||||||
|
"organization",
|
||||||
|
],
|
||||||
|
where: { personal_id: assign.personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
|
const experimentee = await experimenteeData.map((element) => ({
|
||||||
|
...element,
|
||||||
|
name: element.prefixName + element.firstName + " " + element.lastName,
|
||||||
|
Oc: element.organization,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const directorData = await this.assignDirectorRepository.find({
|
||||||
|
where: { assign_id },
|
||||||
|
order: { ordering: "ASC" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!directorData) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentors = [];
|
||||||
|
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||||
|
if (mentorList.length > 0) {
|
||||||
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
|
const e = await mentorList[index];
|
||||||
|
|
||||||
|
mentors.push({
|
||||||
|
personal_id: e.personal_id,
|
||||||
|
dated: e.dated,
|
||||||
|
name: e.fullname,
|
||||||
|
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||||
|
position: e.position,
|
||||||
|
posType: e.posType,
|
||||||
|
posLevel: e.posLevel,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
||||||
|
|
||||||
|
const commander =
|
||||||
|
commanderData != null
|
||||||
|
? {
|
||||||
|
personal_id: commanderData.personal_id,
|
||||||
|
dated: commanderData.dated,
|
||||||
|
name: commanderData.fullname,
|
||||||
|
label:
|
||||||
|
commanderData.fullname +
|
||||||
|
" " +
|
||||||
|
(commanderData.position
|
||||||
|
? `(${commanderData.position}${commanderData.posLevel})`
|
||||||
|
: ""),
|
||||||
|
position: commanderData.position,
|
||||||
|
posType: commanderData.posType,
|
||||||
|
posLevel: commanderData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||||
|
const chairman =
|
||||||
|
chairmanData != null
|
||||||
|
? {
|
||||||
|
personal_id: chairmanData.personal_id,
|
||||||
|
dated: chairmanData.dated,
|
||||||
|
name: chairmanData.fullname,
|
||||||
|
label:
|
||||||
|
chairmanData.fullname +
|
||||||
|
" " +
|
||||||
|
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||||
|
position: chairmanData.position,
|
||||||
|
posType: chairmanData.posType,
|
||||||
|
posLevel: chairmanData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
experimentee: experimentee,
|
||||||
|
mentors: mentors,
|
||||||
|
commander: commander,
|
||||||
|
chairman: chairman,
|
||||||
|
assign,
|
||||||
|
evaluate,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const commanderData = await (directorData.find(
|
|
||||||
(x) => x.role == "commander"
|
|
||||||
) ?? null);
|
|
||||||
|
|
||||||
const commander =
|
|
||||||
commanderData != null
|
|
||||||
? {
|
|
||||||
personal_id: commanderData.personal_id,
|
|
||||||
dated: commanderData.dated,
|
|
||||||
name: commanderData.fullname,
|
|
||||||
label:
|
|
||||||
commanderData.fullname +
|
|
||||||
" " +
|
|
||||||
(commanderData.position
|
|
||||||
? `(${commanderData.position}${commanderData.posLevel})`
|
|
||||||
: ""),
|
|
||||||
position: commanderData.position,
|
|
||||||
posType: commanderData.posType,
|
|
||||||
posLevel: commanderData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const chairmanData = await (directorData.find(
|
|
||||||
(x) => x.role == "chairman"
|
|
||||||
) ?? null);
|
|
||||||
const chairman =
|
|
||||||
chairmanData != null
|
|
||||||
? {
|
|
||||||
personal_id: chairmanData.personal_id,
|
|
||||||
dated: chairmanData.dated,
|
|
||||||
name: chairmanData.fullname,
|
|
||||||
label:
|
|
||||||
chairmanData.fullname +
|
|
||||||
" " +
|
|
||||||
(chairmanData.position
|
|
||||||
? `(${chairmanData.position}${chairmanData.posLevel})`
|
|
||||||
: ""),
|
|
||||||
position: chairmanData.position,
|
|
||||||
posType: chairmanData.posType,
|
|
||||||
posLevel: chairmanData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
|
||||||
experimentee: experimentee,
|
|
||||||
mentors: mentors,
|
|
||||||
commander: commander,
|
|
||||||
chairman: chairman,
|
|
||||||
assign,
|
|
||||||
evaluate,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -369,83 +341,87 @@ 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,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
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"],
|
||||||
where: {
|
where: {
|
||||||
|
assign_id,
|
||||||
|
role: "chairman",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!director) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||||
|
}
|
||||||
|
|
||||||
|
const director_id = director.personal_id;
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
relations: ["profile"],
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const postData: any = await {
|
||||||
assign_id,
|
assign_id,
|
||||||
role: "chairman",
|
...requestBody,
|
||||||
},
|
director_id,
|
||||||
});
|
no: requestBody.evaluate_no,
|
||||||
if (!director) {
|
date_start: requestBody.start_date,
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
personal_id: assign.personal_id,
|
||||||
}
|
|
||||||
|
|
||||||
const director_id = director.personal_id;
|
achievement_other_desc: requestBody.achievement_other
|
||||||
|
? requestBody.achievement_other.text
|
||||||
const assign = await this.assignRepository.findOne({
|
: "",
|
||||||
relations: ["profile"],
|
achievement_other_level: requestBody.achievement_other
|
||||||
where: { id: assign_id },
|
? Number(requestBody.achievement_other.level)
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const postData: any = await {
|
|
||||||
assign_id,
|
|
||||||
...requestBody,
|
|
||||||
director_id,
|
|
||||||
no: requestBody.evaluate_no,
|
|
||||||
date_start: requestBody.start_date,
|
|
||||||
personal_id: assign.personal_id,
|
|
||||||
|
|
||||||
achievement_other_desc: requestBody.achievement_other
|
|
||||||
? requestBody.achievement_other.text
|
|
||||||
: "",
|
|
||||||
achievement_other_level: requestBody.achievement_other
|
|
||||||
? Number(requestBody.achievement_other.level)
|
|
||||||
: 0,
|
|
||||||
behavior_other_desc: requestBody.behavior_orther.text,
|
|
||||||
behavior_other_level:
|
|
||||||
requestBody.behavior_orther.text != ""
|
|
||||||
? Number(requestBody.behavior_orther.level)
|
|
||||||
: 0,
|
: 0,
|
||||||
|
behavior_other_desc: requestBody.behavior_orther.text,
|
||||||
|
behavior_other_level:
|
||||||
|
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
|
||||||
|
|
||||||
createdUserId: request.user.sub,
|
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.evaluateChairmanRepository.save(postData, {
|
await this.evaluateChairmanRepository.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}`,
|
||||||
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับคณะกรรมการ) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับคณะกรรมการ) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||||
receiverUserId: director_id,
|
receiverUserId: director_id,
|
||||||
payload: "",
|
payload: "",
|
||||||
isSendMail: true,
|
isSendMail: true,
|
||||||
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();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -459,85 +435,80 @@ 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,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
let evaluate = await this.evaluateChairmanRepository.findOne({
|
let evaluate = await this.evaluateChairmanRepository.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.chairman_dated = requestBody.chairman_dated;
|
||||||
|
evaluate.director1_dated = requestBody.director1_dated;
|
||||||
|
evaluate.director2_dated = requestBody.director2_dated;
|
||||||
|
evaluate.knowledge_level = requestBody.knowledge_level;
|
||||||
|
evaluate.apply_level = requestBody.apply_level;
|
||||||
|
evaluate.success_level = requestBody.success_level;
|
||||||
|
evaluate.achievement_other_desc = requestBody.achievement_other
|
||||||
|
? requestBody.achievement_other.text
|
||||||
|
: "";
|
||||||
|
evaluate.achievement_other_level =
|
||||||
|
requestBody.achievement_other.text != "" ? Number(requestBody.achievement_other.level) : 0;
|
||||||
|
|
||||||
|
evaluate.conduct1_level = requestBody.conduct1_level;
|
||||||
|
evaluate.conduct2_level = requestBody.conduct2_level;
|
||||||
|
evaluate.conduct3_level = requestBody.conduct3_level;
|
||||||
|
evaluate.conduct4_level = requestBody.conduct4_level;
|
||||||
|
evaluate.moral1_level = requestBody.moral1_level;
|
||||||
|
evaluate.moral2_level = requestBody.moral2_level;
|
||||||
|
evaluate.moral3_level = requestBody.moral3_level;
|
||||||
|
evaluate.discipline1_level = requestBody.discipline1_level;
|
||||||
|
evaluate.discipline2_level = requestBody.discipline2_level;
|
||||||
|
evaluate.discipline3_level = requestBody.discipline3_level;
|
||||||
|
evaluate.discipline4_level = requestBody.discipline4_level;
|
||||||
|
evaluate.discipline5_level = requestBody.discipline5_level;
|
||||||
|
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
|
||||||
|
evaluate.behavior_other_level =
|
||||||
|
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0;
|
||||||
|
evaluate.develop_orientation_score = requestBody.develop_orientation_score;
|
||||||
|
evaluate.develop_self_learning_score = requestBody.develop_self_learning_score;
|
||||||
|
evaluate.develop_training_seminar_score = requestBody.develop_training_seminar_score;
|
||||||
|
evaluate.develop_other_training_score = requestBody.develop_other_training_score;
|
||||||
|
evaluate.develop_orientation_percent = requestBody.develop_orientation_percent;
|
||||||
|
evaluate.develop_self_learning_percent = requestBody.develop_self_learning_percent;
|
||||||
|
evaluate.develop_training_seminar_percent = requestBody.develop_training_seminar_percent;
|
||||||
|
evaluate.develop_other_training_percent = requestBody.develop_other_training_percent;
|
||||||
|
evaluate.develop_result = requestBody.develop_result;
|
||||||
|
evaluate.achievement_score = requestBody.achievement_score;
|
||||||
|
evaluate.achievement_score_total = requestBody.achievement_score_total;
|
||||||
|
evaluate.achievement_percent = requestBody.achievement_percent;
|
||||||
|
evaluate.achievement_result = requestBody.achievement_result;
|
||||||
|
evaluate.behavior_score = requestBody.behavior_score;
|
||||||
|
evaluate.behavior_score_total = requestBody.behavior_score_total;
|
||||||
|
evaluate.behavior_percent = requestBody.behavior_percent;
|
||||||
|
evaluate.behavior_result = requestBody.behavior_result;
|
||||||
|
evaluate.sum_score = requestBody.sum_score;
|
||||||
|
evaluate.sum_percent = requestBody.sum_percent;
|
||||||
|
evaluate.evaluate_result = requestBody.evaluate_result;
|
||||||
|
|
||||||
|
evaluate.updateUserId = request.user.sub;
|
||||||
|
evaluate.updateFullName = request.user.name;
|
||||||
|
|
||||||
|
await this.evaluateChairmanRepository.save(evaluate, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: evaluate });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate.chairman_dated = requestBody.chairman_dated;
|
|
||||||
evaluate.director1_dated = requestBody.director1_dated;
|
|
||||||
evaluate.director2_dated = requestBody.director2_dated;
|
|
||||||
evaluate.knowledge_level = requestBody.knowledge_level;
|
|
||||||
evaluate.apply_level = requestBody.apply_level;
|
|
||||||
evaluate.success_level = requestBody.success_level;
|
|
||||||
evaluate.achievement_other_desc = requestBody.achievement_other
|
|
||||||
? requestBody.achievement_other.text
|
|
||||||
: "";
|
|
||||||
evaluate.achievement_other_level =
|
|
||||||
requestBody.achievement_other.text != ""
|
|
||||||
? Number(requestBody.achievement_other.level)
|
|
||||||
: 0;
|
|
||||||
|
|
||||||
evaluate.conduct1_level = requestBody.conduct1_level;
|
|
||||||
evaluate.conduct2_level = requestBody.conduct2_level;
|
|
||||||
evaluate.conduct3_level = requestBody.conduct3_level;
|
|
||||||
evaluate.conduct4_level = requestBody.conduct4_level;
|
|
||||||
evaluate.moral1_level = requestBody.moral1_level;
|
|
||||||
evaluate.moral2_level = requestBody.moral2_level;
|
|
||||||
evaluate.moral3_level = requestBody.moral3_level;
|
|
||||||
evaluate.discipline1_level = requestBody.discipline1_level;
|
|
||||||
evaluate.discipline2_level = requestBody.discipline2_level;
|
|
||||||
evaluate.discipline3_level = requestBody.discipline3_level;
|
|
||||||
evaluate.discipline4_level = requestBody.discipline4_level;
|
|
||||||
evaluate.discipline5_level = requestBody.discipline5_level;
|
|
||||||
evaluate.behavior_other_desc = requestBody.behavior_orther.text;
|
|
||||||
evaluate.behavior_other_level =
|
|
||||||
requestBody.behavior_orther.text != ""
|
|
||||||
? Number(requestBody.behavior_orther.level)
|
|
||||||
: 0;
|
|
||||||
evaluate.develop_orientation_score = requestBody.develop_orientation_score;
|
|
||||||
evaluate.develop_self_learning_score =
|
|
||||||
requestBody.develop_self_learning_score;
|
|
||||||
evaluate.develop_training_seminar_score =
|
|
||||||
requestBody.develop_training_seminar_score;
|
|
||||||
evaluate.develop_other_training_score =
|
|
||||||
requestBody.develop_other_training_score;
|
|
||||||
evaluate.develop_orientation_percent =
|
|
||||||
requestBody.develop_orientation_percent;
|
|
||||||
evaluate.develop_self_learning_percent =
|
|
||||||
requestBody.develop_self_learning_percent;
|
|
||||||
evaluate.develop_training_seminar_percent =
|
|
||||||
requestBody.develop_training_seminar_percent;
|
|
||||||
evaluate.develop_other_training_percent =
|
|
||||||
requestBody.develop_other_training_percent;
|
|
||||||
evaluate.develop_result = requestBody.develop_result;
|
|
||||||
evaluate.achievement_score = requestBody.achievement_score;
|
|
||||||
evaluate.achievement_score_total = requestBody.achievement_score_total;
|
|
||||||
evaluate.achievement_percent = requestBody.achievement_percent;
|
|
||||||
evaluate.achievement_result = requestBody.achievement_result;
|
|
||||||
evaluate.behavior_score = requestBody.behavior_score;
|
|
||||||
evaluate.behavior_score_total = requestBody.behavior_score_total;
|
|
||||||
evaluate.behavior_percent = requestBody.behavior_percent;
|
|
||||||
evaluate.behavior_result = requestBody.behavior_result;
|
|
||||||
evaluate.sum_score = requestBody.sum_score;
|
|
||||||
evaluate.sum_percent = requestBody.sum_percent;
|
|
||||||
evaluate.evaluate_result = requestBody.evaluate_result;
|
|
||||||
|
|
||||||
evaluate.updateUserId = request.user.sub;
|
|
||||||
evaluate.updateFullName = request.user.name;
|
|
||||||
|
|
||||||
await this.evaluateChairmanRepository.save(evaluate, { data: request });
|
|
||||||
setLogDataDiff(request, { before, after: evaluate });
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,349 +1,418 @@
|
||||||
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 ข้อมูลตอนกดสร้างแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
* @summary ข้อมูลตอนกดสร้างแบบประเมินผล (ผู้บังคับบัญชา)
|
* @summary ข้อมูลตอนกดสร้างแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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"],
|
||||||
where: {
|
where: {
|
||||||
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:
|
||||||
Oc: assign.profile.organization,
|
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
|
||||||
}
|
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,
|
||||||
assign,
|
assign,
|
||||||
evaluate_no: evaluate_no,
|
evaluate_no: evaluate_no,
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* API ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
* @summary ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* @summary ข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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({
|
||||||
select: ["personal_id"],
|
select: ["personal_id"],
|
||||||
where: {
|
where: {
|
||||||
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: {
|
||||||
director_id,
|
director_id,
|
||||||
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
|
||||||
// ? {
|
// ? {
|
||||||
// ...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.firstName +
|
||||||
// " " +
|
// " " +
|
||||||
// assign.profile.lastName,
|
// 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 =
|
// const start_date =
|
||||||
// evaluate_amount == 0
|
// evaluate_amount == 0
|
||||||
// ? assign.date_start
|
// ? assign.date_start
|
||||||
// : findEndDate(evaluate_amount * 3, assign.date_start);
|
// : findEndDate(evaluate_amount * 3, assign.date_start);
|
||||||
|
|
||||||
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: [
|
||||||
where: { personal_id: assign.personal_id },
|
"personal_id",
|
||||||
})
|
"prefixName",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"positionName",
|
||||||
|
"positionLevelName",
|
||||||
|
"organization",
|
||||||
|
],
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* API บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
* @summary บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* @summary บันทึกข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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"],
|
||||||
where: {
|
where: {
|
||||||
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 {
|
||||||
assign_id,
|
assign_id,
|
||||||
...requestBody,
|
...requestBody,
|
||||||
director_id,
|
director_id,
|
||||||
no: requestBody.evaluate_no,
|
no: requestBody.evaluate_no,
|
||||||
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
|
||||||
behavior_other_desc: requestBody.behavior_orther.text,
|
: "",
|
||||||
behavior_other_level: requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
|
achievement_other_level: requestBody.achievement_other
|
||||||
|
? Number(requestBody.achievement_other.level)
|
||||||
|
: 0,
|
||||||
|
behavior_other_desc: requestBody.behavior_orther.text,
|
||||||
|
behavior_other_level:
|
||||||
|
requestBody.behavior_orther.text != "" ? Number(requestBody.behavior_orther.level) : 0,
|
||||||
|
|
||||||
createdUserId: request.user.sub,
|
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}`,
|
||||||
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับผู้บังคับบัญชา) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
body: `ถึงกำหนดประเมินผลการทดลองปฏิบัติหน้าที่ราชการ (สำหรับผู้บังคับบัญชา) ครั้งที่ ${nextNo} ${assign.profile.prefixName}${assign.profile.firstName} ${assign.profile.lastName}`,
|
||||||
receiverUserId: director_id,
|
receiverUserId: director_id,
|
||||||
payload: "",
|
payload: "",
|
||||||
isSendMail: true,
|
isSendMail: true,
|
||||||
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* API แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
* @summary แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
* @summary แก้ไขข้อมูลแบบประเมินผล (ผู้บังคับบัญชา)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Put("")
|
@Put("")
|
||||||
async UpdateData(
|
async UpdateData(
|
||||||
// @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
|
|
@ -49,167 +49,175 @@ 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) {
|
||||||
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 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
|
|
||||||
? {
|
|
||||||
...assign.profile,
|
|
||||||
id: assign.profile.personal_id,
|
|
||||||
name:
|
|
||||||
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
|
|
||||||
Oc: assign.profile.organization,
|
|
||||||
}
|
|
||||||
: null);
|
|
||||||
|
|
||||||
const directorData = await this.assignDirectorRepository.find({
|
|
||||||
where: { assign_id },
|
|
||||||
order: { ordering: "ASC" },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!directorData) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentors = [];
|
|
||||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
|
||||||
if (mentorList.length > 0) {
|
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
|
||||||
const e = await mentorList[index];
|
|
||||||
|
|
||||||
mentors.push({
|
|
||||||
personal_id: e.personal_id,
|
|
||||||
dated: e.dated,
|
|
||||||
name: e.fullname,
|
|
||||||
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
|
||||||
position: e.position,
|
|
||||||
posType: e.posType,
|
|
||||||
posLevel: e.posLevel,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
const profile = await (assign.profile
|
||||||
|
|
||||||
const commander =
|
|
||||||
commanderData != null
|
|
||||||
? {
|
? {
|
||||||
personal_id: commanderData.personal_id,
|
...assign.profile,
|
||||||
dated: commanderData.dated,
|
id: assign.profile.personal_id,
|
||||||
name: commanderData.fullname,
|
name:
|
||||||
label:
|
assign.profile.prefixName + assign.profile.firstName + " " + assign.profile.lastName,
|
||||||
commanderData.fullname +
|
Oc: assign.profile.organization,
|
||||||
" " +
|
|
||||||
(commanderData.position
|
|
||||||
? `(${commanderData.position}${commanderData.posLevel})`
|
|
||||||
: ""),
|
|
||||||
position: commanderData.position,
|
|
||||||
posType: commanderData.posType,
|
|
||||||
posLevel: commanderData.posLevel,
|
|
||||||
}
|
}
|
||||||
: null;
|
: null);
|
||||||
|
|
||||||
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
const directorData = await this.assignDirectorRepository.find({
|
||||||
const chairman =
|
where: { assign_id },
|
||||||
chairmanData != null
|
order: { ordering: "ASC" },
|
||||||
? {
|
});
|
||||||
personal_id: chairmanData.personal_id,
|
|
||||||
dated: chairmanData.dated,
|
|
||||||
name: chairmanData.fullname,
|
|
||||||
label:
|
|
||||||
chairmanData.fullname +
|
|
||||||
" " +
|
|
||||||
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
|
||||||
position: chairmanData.position,
|
|
||||||
posType: chairmanData.posType,
|
|
||||||
posLevel: chairmanData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
const resultData = await this.evaluateChairmanRepository.find({
|
if (!directorData) {
|
||||||
select: [
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||||
"develop_orientation_score",
|
}
|
||||||
"develop_self_learning_score",
|
|
||||||
"develop_training_seminar_score",
|
|
||||||
"evaluate_result",
|
|
||||||
"no",
|
|
||||||
],
|
|
||||||
where: {
|
|
||||||
assign_id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!resultData) {
|
let mentors = [];
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล");
|
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||||
}
|
if (mentorList.length > 0) {
|
||||||
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
|
const e = await mentorList[index];
|
||||||
|
|
||||||
const result = await Promise.all(
|
mentors.push({
|
||||||
resultData.map(async (e) => {
|
personal_id: e.personal_id,
|
||||||
const check = await this.evaluateResultRepository.count({ where: { assign_id, no: e.no } });
|
dated: e.dated,
|
||||||
|
name: e.fullname,
|
||||||
const develop_complete =
|
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||||
e.develop_orientation_score > 0 &&
|
position: e.position,
|
||||||
e.develop_self_learning_score > 0 &&
|
posType: e.posType,
|
||||||
e.develop_training_seminar_score
|
posLevel: e.posLevel,
|
||||||
? 1
|
|
||||||
: 2;
|
|
||||||
|
|
||||||
const evaluate_result = e.evaluate_result === 1 ? 1 : 2;
|
|
||||||
|
|
||||||
let startDate = assign.date_start;
|
|
||||||
if (e.no === "2") {
|
|
||||||
const resultNo1 = await this.evaluateResultRepository.findOne({
|
|
||||||
select: ["date_finish"],
|
|
||||||
where: { assign_id, no: "1" },
|
|
||||||
});
|
});
|
||||||
startDate = resultNo1?.date_finish ?? assign.date_start;
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let endDate: any = assign.date_finish;
|
const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
||||||
if (e.no === "1") {
|
|
||||||
endDate = findEndDate(3, assign.date_start) ?? assign.date_finish;
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
const commander =
|
||||||
develop_complete,
|
commanderData != null
|
||||||
evaluate_result,
|
? {
|
||||||
evaluate_no: Number(e.no),
|
personal_id: commanderData.personal_id,
|
||||||
isResult: check > 0 ? true : false,
|
dated: commanderData.dated,
|
||||||
start_date: startDate,
|
name: commanderData.fullname,
|
||||||
end_date: endDate,
|
label:
|
||||||
};
|
commanderData.fullname +
|
||||||
}),
|
" " +
|
||||||
);
|
(commanderData.position
|
||||||
|
? `(${commanderData.position}${commanderData.posLevel})`
|
||||||
|
: ""),
|
||||||
|
position: commanderData.position,
|
||||||
|
posType: commanderData.posType,
|
||||||
|
posLevel: commanderData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
// const develop_complete = await (resultData.develop_orientation_score > 0 &&
|
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||||
// resultData.develop_self_learning_score > 0 &&
|
const chairman =
|
||||||
// resultData.develop_training_seminar_score > 0
|
chairmanData != null
|
||||||
// ? 1
|
? {
|
||||||
// : 2);
|
personal_id: chairmanData.personal_id,
|
||||||
|
dated: chairmanData.dated,
|
||||||
|
name: chairmanData.fullname,
|
||||||
|
label:
|
||||||
|
chairmanData.fullname +
|
||||||
|
" " +
|
||||||
|
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||||
|
position: chairmanData.position,
|
||||||
|
posType: chairmanData.posType,
|
||||||
|
posLevel: chairmanData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
// const evaluate_result = await (resultData.evaluate_result == 1 ? 1 : 2);
|
const resultData = await this.evaluateChairmanRepository.find({
|
||||||
|
select: [
|
||||||
|
"develop_orientation_score",
|
||||||
|
"develop_self_learning_score",
|
||||||
|
"develop_training_seminar_score",
|
||||||
|
"evaluate_result",
|
||||||
|
"no",
|
||||||
|
],
|
||||||
|
where: {
|
||||||
|
assign_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
// const result = await {
|
if (!resultData) {
|
||||||
// develop_complete: develop_complete,
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมินผล");
|
||||||
// evaluate_result: evaluate_result,
|
}
|
||||||
// };
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
const result = await Promise.all(
|
||||||
person: profile,
|
resultData.map(async (e) => {
|
||||||
assign,
|
const check = await this.evaluateResultRepository.count({
|
||||||
result,
|
where: { assign_id, no: e.no },
|
||||||
mentors,
|
});
|
||||||
commander,
|
|
||||||
chairman,
|
const develop_complete =
|
||||||
});
|
e.develop_orientation_score > 0 &&
|
||||||
|
e.develop_self_learning_score > 0 &&
|
||||||
|
e.develop_training_seminar_score
|
||||||
|
? 1
|
||||||
|
: 2;
|
||||||
|
|
||||||
|
const evaluate_result = e.evaluate_result === 1 ? 1 : 2;
|
||||||
|
|
||||||
|
let startDate = assign.date_start;
|
||||||
|
if (e.no === "2") {
|
||||||
|
const resultNo1 = await this.evaluateResultRepository.findOne({
|
||||||
|
select: ["date_finish"],
|
||||||
|
where: { assign_id, no: "1" },
|
||||||
|
});
|
||||||
|
startDate = resultNo1?.date_finish ?? assign.date_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
let endDate: any = assign.date_finish;
|
||||||
|
if (e.no === "1") {
|
||||||
|
endDate = findEndDate(3, assign.date_start) ?? assign.date_finish;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
develop_complete,
|
||||||
|
evaluate_result,
|
||||||
|
evaluate_no: Number(e.no),
|
||||||
|
isResult: check > 0 ? true : false,
|
||||||
|
start_date: startDate,
|
||||||
|
end_date: endDate,
|
||||||
|
};
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// const develop_complete = await (resultData.develop_orientation_score > 0 &&
|
||||||
|
// resultData.develop_self_learning_score > 0 &&
|
||||||
|
// resultData.develop_training_seminar_score > 0
|
||||||
|
// ? 1
|
||||||
|
// : 2);
|
||||||
|
|
||||||
|
// const evaluate_result = await (resultData.evaluate_result == 1 ? 1 : 2);
|
||||||
|
|
||||||
|
// const result = await {
|
||||||
|
// develop_complete: develop_complete,
|
||||||
|
// evaluate_result: evaluate_result,
|
||||||
|
// };
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
person: profile,
|
||||||
|
assign,
|
||||||
|
result,
|
||||||
|
mentors,
|
||||||
|
commander,
|
||||||
|
chairman,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -224,150 +232,167 @@ export class EvaluateResultController extends Controller {
|
||||||
@Query() assign_id: string,
|
@Query() assign_id: string,
|
||||||
@Query() evaluate_no?: string,
|
@Query() evaluate_no?: string,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionGet(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionGet(request, "SYS_PROBATION");
|
||||||
|
|
||||||
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
// ต้องปรับเป็น id ของคนที่ access เข้ามา
|
||||||
const director = await this.assignDirectorRepository.findOne({
|
const director = await this.assignDirectorRepository.findOne({
|
||||||
select: ["personal_id"],
|
select: ["personal_id"],
|
||||||
where: {
|
where: {
|
||||||
assign_id,
|
assign_id,
|
||||||
role: "chairman",
|
role: "chairman",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (!director) {
|
if (!director) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||||
}
|
|
||||||
const director_id = director.personal_id;
|
|
||||||
|
|
||||||
const evaluate = await this.evaluateResultRepository.findOne({
|
|
||||||
where: {
|
|
||||||
director_id,
|
|
||||||
assign_id,
|
|
||||||
no: evaluate_no ?? "1",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!evaluate) {
|
|
||||||
return new HttpSuccess(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
|
||||||
where: { id: assign_id },
|
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const experimenteeData = await this.personalRepository.findOne({
|
|
||||||
select: [
|
|
||||||
"personal_id",
|
|
||||||
"prefixName",
|
|
||||||
"firstName",
|
|
||||||
"lastName",
|
|
||||||
"positionName",
|
|
||||||
"positionLevelName",
|
|
||||||
"organization",
|
|
||||||
"orgRootName",
|
|
||||||
],
|
|
||||||
where: { personal_id: assign.personal_id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!experimenteeData) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
|
||||||
}
|
|
||||||
|
|
||||||
const splitOc = await experimenteeData.organization.split(" ");
|
|
||||||
const splitOcAmount = await splitOc.length;
|
|
||||||
const experimentee = await {
|
|
||||||
...experimenteeData,
|
|
||||||
name:
|
|
||||||
experimenteeData.prefixName + experimenteeData.firstName + " " + experimenteeData.lastName,
|
|
||||||
PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName,
|
|
||||||
Department: splitOcAmount > 2 ? splitOc[splitOcAmount - 3] : "-",
|
|
||||||
OrganizationOrganization: splitOcAmount > 1 ? splitOc[splitOcAmount - 2] : "-",
|
|
||||||
Oc: experimenteeData.orgRootName,
|
|
||||||
};
|
|
||||||
|
|
||||||
const directorData = await this.assignDirectorRepository.find({
|
|
||||||
where: { assign_id },
|
|
||||||
order: { ordering: "ASC" },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!directorData) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
let mentors = [];
|
|
||||||
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
|
||||||
if (mentorList.length > 0) {
|
|
||||||
for (let index = 0; index < mentorList.length; index++) {
|
|
||||||
const e = await mentorList[index];
|
|
||||||
|
|
||||||
mentors.push({
|
|
||||||
personal_id: e.personal_id,
|
|
||||||
dated: e.dated,
|
|
||||||
name: e.fullname,
|
|
||||||
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
|
||||||
position: e.position + e.posLevel,
|
|
||||||
posType: e.posType,
|
|
||||||
posLevel: e.posLevel,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
const director_id = director.personal_id;
|
||||||
|
|
||||||
|
const evaluate = await this.evaluateResultRepository.findOne({
|
||||||
|
where: {
|
||||||
|
director_id,
|
||||||
|
assign_id,
|
||||||
|
no: evaluate_no ?? "1",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!evaluate) {
|
||||||
|
return new HttpSuccess(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const experimenteeData = await this.personalRepository.findOne({
|
||||||
|
select: [
|
||||||
|
"personal_id",
|
||||||
|
"prefixName",
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"positionName",
|
||||||
|
"positionLevelName",
|
||||||
|
"organization",
|
||||||
|
"orgRootName",
|
||||||
|
"orgChild1Name",
|
||||||
|
"orgChild2Name",
|
||||||
|
"orgChild3Name",
|
||||||
|
"orgChild4Name",
|
||||||
|
],
|
||||||
|
where: { personal_id: assign.personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!experimenteeData) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
|
}
|
||||||
|
|
||||||
|
// const splitOc = await experimenteeData.organization.split(" ");
|
||||||
|
// const splitOcAmount = await splitOc.length;
|
||||||
|
const experimentee = await {
|
||||||
|
...experimenteeData,
|
||||||
|
name:
|
||||||
|
experimenteeData.prefixName +
|
||||||
|
experimenteeData.firstName +
|
||||||
|
" " +
|
||||||
|
experimenteeData.lastName,
|
||||||
|
PositionLevel: experimenteeData.positionName + experimenteeData.positionLevelName,
|
||||||
|
OrganizationOrganization: experimenteeData.orgChild2Name
|
||||||
|
? (experimenteeData.orgChild4Name ? experimenteeData.orgChild4Name + " " : "") +
|
||||||
|
(experimenteeData.orgChild3Name ? experimenteeData.orgChild3Name + " " : "") +
|
||||||
|
(experimenteeData.orgChild2Name ? experimenteeData.orgChild2Name + " " : "")
|
||||||
|
: "-",
|
||||||
|
Department: experimenteeData.orgChild1Name ?? "-",
|
||||||
|
Oc: experimenteeData.orgRootName,
|
||||||
|
};
|
||||||
|
|
||||||
|
const directorData = await this.assignDirectorRepository.find({
|
||||||
|
where: { assign_id },
|
||||||
|
order: { ordering: "ASC" },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!directorData) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล ผู้บังคับบัญชาและประธาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
let mentors = [];
|
||||||
|
const mentorList = await directorData.filter((x) => x.role == "mentor");
|
||||||
|
if (mentorList.length > 0) {
|
||||||
|
for (let index = 0; index < mentorList.length; index++) {
|
||||||
|
const e = await mentorList[index];
|
||||||
|
|
||||||
|
mentors.push({
|
||||||
|
personal_id: e.personal_id,
|
||||||
|
dated: e.dated,
|
||||||
|
name: e.fullname,
|
||||||
|
label: e.fullname + " " + (e.position ? `(${e.position}${e.posLevel})` : ""),
|
||||||
|
position: e.position + e.posLevel,
|
||||||
|
posType: e.posType,
|
||||||
|
posLevel: e.posLevel,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
||||||
|
|
||||||
|
// const commander =
|
||||||
|
// commanderData != null
|
||||||
|
// ? {
|
||||||
|
// personal_id: commanderData.personal_id,
|
||||||
|
// dated: commanderData.dated,
|
||||||
|
// name: commanderData.fullname,
|
||||||
|
// label:
|
||||||
|
// commanderData.fullname +
|
||||||
|
// " " +
|
||||||
|
// (commanderData.position
|
||||||
|
// ? `(${commanderData.position}${commanderData.posLevel})`
|
||||||
|
// : ""),
|
||||||
|
// position: commanderData.position + commanderData.posLevel,
|
||||||
|
// posType: commanderData.posType,
|
||||||
|
// posLevel: commanderData.posLevel,
|
||||||
|
// }
|
||||||
|
// : null;
|
||||||
|
|
||||||
|
const commander = {
|
||||||
|
dated: evaluate.authority_dated,
|
||||||
|
name: evaluate.authority_name,
|
||||||
|
|
||||||
|
position: evaluate.authority_pos + evaluate.authority_level,
|
||||||
|
posType: evaluate.authority_type,
|
||||||
|
posLevel: evaluate.authority_level,
|
||||||
|
};
|
||||||
|
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
||||||
|
const chairman =
|
||||||
|
chairmanData != null
|
||||||
|
? {
|
||||||
|
personal_id: chairmanData.personal_id,
|
||||||
|
dated: chairmanData.dated,
|
||||||
|
name: chairmanData.fullname,
|
||||||
|
label:
|
||||||
|
chairmanData.fullname +
|
||||||
|
" " +
|
||||||
|
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
||||||
|
position: chairmanData.position + chairmanData.posLevel,
|
||||||
|
posType: chairmanData.posType,
|
||||||
|
posLevel: chairmanData.posLevel,
|
||||||
|
}
|
||||||
|
: null;
|
||||||
|
|
||||||
|
return new HttpSuccess({
|
||||||
|
commander,
|
||||||
|
chairman,
|
||||||
|
mentors,
|
||||||
|
experimentee,
|
||||||
|
assign,
|
||||||
|
evaluate: evaluate ? evaluate : null,
|
||||||
|
});
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
// const commanderData = await (directorData.find((x) => x.role == "commander") ?? null);
|
|
||||||
|
|
||||||
// const commander =
|
|
||||||
// commanderData != null
|
|
||||||
// ? {
|
|
||||||
// personal_id: commanderData.personal_id,
|
|
||||||
// dated: commanderData.dated,
|
|
||||||
// name: commanderData.fullname,
|
|
||||||
// label:
|
|
||||||
// commanderData.fullname +
|
|
||||||
// " " +
|
|
||||||
// (commanderData.position
|
|
||||||
// ? `(${commanderData.position}${commanderData.posLevel})`
|
|
||||||
// : ""),
|
|
||||||
// position: commanderData.position + commanderData.posLevel,
|
|
||||||
// posType: commanderData.posType,
|
|
||||||
// posLevel: commanderData.posLevel,
|
|
||||||
// }
|
|
||||||
// : null;
|
|
||||||
|
|
||||||
const commander = {
|
|
||||||
dated: evaluate.authority_dated,
|
|
||||||
name: evaluate.authority_name,
|
|
||||||
|
|
||||||
position: evaluate.authority_pos + evaluate.authority_level,
|
|
||||||
posType: evaluate.authority_type,
|
|
||||||
posLevel: evaluate.authority_level,
|
|
||||||
};
|
|
||||||
const chairmanData = await (directorData.find((x) => x.role == "chairman") ?? null);
|
|
||||||
const chairman =
|
|
||||||
chairmanData != null
|
|
||||||
? {
|
|
||||||
personal_id: chairmanData.personal_id,
|
|
||||||
dated: chairmanData.dated,
|
|
||||||
name: chairmanData.fullname,
|
|
||||||
label:
|
|
||||||
chairmanData.fullname +
|
|
||||||
" " +
|
|
||||||
(chairmanData.position ? `(${chairmanData.position}${chairmanData.posLevel})` : ""),
|
|
||||||
position: chairmanData.position + chairmanData.posLevel,
|
|
||||||
posType: chairmanData.posType,
|
|
||||||
posLevel: chairmanData.posLevel,
|
|
||||||
}
|
|
||||||
: null;
|
|
||||||
|
|
||||||
return new HttpSuccess({
|
|
||||||
commander,
|
|
||||||
chairman,
|
|
||||||
mentors,
|
|
||||||
experimentee,
|
|
||||||
assign,
|
|
||||||
evaluate: evaluate ? evaluate : null,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -382,50 +407,56 @@ export class EvaluateResultController extends Controller {
|
||||||
@Body() requestBody: CreateEvaluateResult,
|
@Body() requestBody: CreateEvaluateResult,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
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"],
|
||||||
where: {
|
where: {
|
||||||
|
assign_id,
|
||||||
|
role: "chairman",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (!director) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
||||||
|
}
|
||||||
|
|
||||||
|
const director_id = director.personal_id;
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
relations: ["profile"],
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const postData: any = await {
|
||||||
assign_id,
|
assign_id,
|
||||||
role: "chairman",
|
...requestBody,
|
||||||
},
|
director_id,
|
||||||
});
|
no: requestBody.evaluate_no,
|
||||||
if (!director) {
|
personal_id: assign.personal_id,
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผู้ดูแล");
|
date_start: requestBody.start_date,
|
||||||
|
expand_month: requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
|
||||||
|
|
||||||
|
createdUserId: request.user.sub,
|
||||||
|
createdFullName: request.user.name,
|
||||||
|
updateUserId: request.user.sub,
|
||||||
|
updateFullName: request.user.name,
|
||||||
|
};
|
||||||
|
|
||||||
|
await this.evaluateResultRepository.save(postData, {
|
||||||
|
data: request,
|
||||||
|
});
|
||||||
|
setLogDataDiff(request, { before: null, after: postData });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const director_id = director.personal_id;
|
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
|
||||||
relations: ["profile"],
|
|
||||||
where: { id: assign_id },
|
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const postData: any = await {
|
|
||||||
assign_id,
|
|
||||||
...requestBody,
|
|
||||||
director_id,
|
|
||||||
no: requestBody.evaluate_no,
|
|
||||||
personal_id: assign.personal_id,
|
|
||||||
date_start: requestBody.start_date,
|
|
||||||
expand_month: requestBody.pass_result == 3 ? Number(requestBody.expand_month) : 0,
|
|
||||||
|
|
||||||
createdUserId: request.user.sub,
|
|
||||||
createdFullName: request.user.name,
|
|
||||||
updateUserId: request.user.sub,
|
|
||||||
updateFullName: request.user.name,
|
|
||||||
};
|
|
||||||
|
|
||||||
await this.evaluateResultRepository.save(postData, {
|
|
||||||
data: request,
|
|
||||||
});
|
|
||||||
setLogDataDiff(request, { before: null, after: postData });
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -440,60 +471,66 @@ export class EvaluateResultController extends Controller {
|
||||||
@Query() evaluate_no: number | string,
|
@Query() evaluate_no: number | string,
|
||||||
@Request() request: RequestWithUser,
|
@Request() request: RequestWithUser,
|
||||||
) {
|
) {
|
||||||
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
try {
|
||||||
|
await new permission().PermissionUpdate(request, "SYS_PROBATION");
|
||||||
|
|
||||||
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 result = await this.evaluateResultRepository.findOne({
|
||||||
|
where: { assign_id, no: evaluate_no.toString() },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!result) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการประเมิน");
|
||||||
|
}
|
||||||
|
|
||||||
|
const personal = await this.personalRepository.findOne({
|
||||||
|
where: { personal_id: assign.personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!personal) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
|
}
|
||||||
|
personal.probation_status =
|
||||||
|
result.pass_result == 1
|
||||||
|
? 2 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ
|
||||||
|
: result.pass_result == 2
|
||||||
|
? 3 // ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ
|
||||||
|
: result.pass_result == 4
|
||||||
|
? 1 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ทดลองปฏิบัติหน้าที่ราชการต่อไป
|
||||||
|
: personal.probation_status;
|
||||||
|
|
||||||
|
if (result.pass_result == 3) {
|
||||||
|
personal.probation_status = 7;
|
||||||
|
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
||||||
|
await new CallAPI()
|
||||||
|
.PostData(request, "/placement/noti", {
|
||||||
|
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
||||||
|
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${result.expand_month} เดือน`,
|
||||||
|
receiverUserId: assign.personal_id,
|
||||||
|
payload: "",
|
||||||
|
isSendMail: false,
|
||||||
|
isSendInbox: true,
|
||||||
|
isSendNotification: true,
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error calling API:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.personalRepository.save(personal, { data: request });
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = await this.evaluateResultRepository.findOne({
|
|
||||||
where: { assign_id, no: evaluate_no.toString() },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!result) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลผลการประเมิน");
|
|
||||||
}
|
|
||||||
|
|
||||||
const personal = await this.personalRepository.findOne({
|
|
||||||
where: { personal_id: assign.personal_id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!personal) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
|
||||||
}
|
|
||||||
personal.probation_status =
|
|
||||||
result.pass_result == 1
|
|
||||||
? 2 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ
|
|
||||||
: result.pass_result == 2
|
|
||||||
? 3 // ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ
|
|
||||||
: result.pass_result == 4
|
|
||||||
? 1 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ทดลองปฏิบัติหน้าที่ราชการต่อไป
|
|
||||||
: personal.probation_status;
|
|
||||||
|
|
||||||
if (result.pass_result == 3) {
|
|
||||||
personal.probation_status = 7;
|
|
||||||
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
|
||||||
await new CallAPI()
|
|
||||||
.PostData(request, "/placement/noti", {
|
|
||||||
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
|
||||||
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${result.expand_month} เดือน`,
|
|
||||||
receiverUserId: assign.personal_id,
|
|
||||||
payload: "",
|
|
||||||
isSendMail: false,
|
|
||||||
isSendInbox: true,
|
|
||||||
isSendNotification: true,
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error calling API:", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.personalRepository.save(personal, { data: request });
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -509,80 +546,86 @@ export class EvaluateResultController extends Controller {
|
||||||
@Body() requestBody: CreateEvaluateResult,
|
@Body() requestBody: CreateEvaluateResult,
|
||||||
@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.evaluateResultRepository.findOne({
|
let evaluate = await this.evaluateResultRepository.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.date_start = requestBody.start_date;
|
||||||
|
evaluate.date_finish = requestBody.date_finish;
|
||||||
|
evaluate.develop_complete = requestBody.develop_complete;
|
||||||
|
evaluate.pass_result = requestBody.pass_result;
|
||||||
|
evaluate.expand_month =
|
||||||
|
requestBody.pass_result && requestBody.pass_result == 3
|
||||||
|
? Number(requestBody.expand_month)
|
||||||
|
: 0;
|
||||||
|
evaluate.reson = requestBody.reson;
|
||||||
|
evaluate.chairman_dated = requestBody.chairman_dated;
|
||||||
|
|
||||||
|
// evaluate.director1_dated = requestBody.director1_dated;
|
||||||
|
// evaluate.director2_dated = requestBody.director2_dated;
|
||||||
|
evaluate.updateUserId = request.user.sub;
|
||||||
|
evaluate.updateFullName = request.user.name;
|
||||||
|
|
||||||
|
await this.evaluateResultRepository.save(evaluate, { data: request });
|
||||||
|
setLogDataDiff(request, { before, after: evaluate });
|
||||||
|
|
||||||
|
const assign = await this.assignRepository.findOne({
|
||||||
|
relations: ["profile"],
|
||||||
|
where: { id: assign_id },
|
||||||
|
});
|
||||||
|
if (!assign) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
||||||
|
}
|
||||||
|
const personal = await this.personalRepository.findOne({
|
||||||
|
where: { personal_id: assign.personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!personal) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
|
}
|
||||||
|
personal.probation_status =
|
||||||
|
requestBody.pass_result == 1
|
||||||
|
? 2 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ
|
||||||
|
: requestBody.pass_result == 2
|
||||||
|
? 3 // ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ
|
||||||
|
: requestBody.pass_result == 4
|
||||||
|
? 1 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ทดลองปฏิบัติหน้าที่ราชการต่อไป
|
||||||
|
: personal.probation_status;
|
||||||
|
|
||||||
|
if (requestBody.pass_result == 3) {
|
||||||
|
personal.probation_status = 7;
|
||||||
|
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
||||||
|
await new CallAPI()
|
||||||
|
.PostData(request, "/placement/noti", {
|
||||||
|
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
||||||
|
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
|
||||||
|
receiverUserId: assign.personal_id,
|
||||||
|
payload: "",
|
||||||
|
isSendMail: false,
|
||||||
|
isSendInbox: true,
|
||||||
|
isSendNotification: true,
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error("Error calling API:", error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.personalRepository.save(personal, { data: request });
|
||||||
|
|
||||||
|
return new HttpSuccess();
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
evaluate.date_start = requestBody.start_date;
|
|
||||||
evaluate.date_finish = requestBody.date_finish;
|
|
||||||
evaluate.develop_complete = requestBody.develop_complete;
|
|
||||||
evaluate.pass_result = requestBody.pass_result;
|
|
||||||
evaluate.expand_month =
|
|
||||||
requestBody.pass_result && requestBody.pass_result == 3
|
|
||||||
? Number(requestBody.expand_month)
|
|
||||||
: 0;
|
|
||||||
evaluate.reson = requestBody.reson;
|
|
||||||
evaluate.chairman_dated = requestBody.chairman_dated;
|
|
||||||
|
|
||||||
// evaluate.director1_dated = requestBody.director1_dated;
|
|
||||||
// evaluate.director2_dated = requestBody.director2_dated;
|
|
||||||
evaluate.updateUserId = request.user.sub;
|
|
||||||
evaluate.updateFullName = request.user.name;
|
|
||||||
|
|
||||||
await this.evaluateResultRepository.save(evaluate, { data: request });
|
|
||||||
setLogDataDiff(request, { before, after: evaluate });
|
|
||||||
|
|
||||||
const assign = await this.assignRepository.findOne({
|
|
||||||
relations: ["profile"],
|
|
||||||
where: { id: assign_id },
|
|
||||||
});
|
|
||||||
if (!assign) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลแบบมอบหมายงาน");
|
|
||||||
}
|
|
||||||
const personal = await this.personalRepository.findOne({
|
|
||||||
where: { personal_id: assign.personal_id },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!personal) {
|
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
|
||||||
}
|
|
||||||
personal.probation_status =
|
|
||||||
requestBody.pass_result == 1
|
|
||||||
? 2 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้รับราชการต่อ
|
|
||||||
: requestBody.pass_result == 2
|
|
||||||
? 3 // ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ออกจากราชการ
|
|
||||||
: requestBody.pass_result == 4
|
|
||||||
? 1 // ไม่ต่ำกว่ามาตรฐานที่กำหนด เห็นควรให้ทดลองปฏิบัติหน้าที่ราชการต่อไป
|
|
||||||
: personal.probation_status;
|
|
||||||
|
|
||||||
if (requestBody.pass_result == 3) {
|
|
||||||
personal.probation_status = 7;
|
|
||||||
// #noti ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ กรณีขยายระยะเวลา
|
|
||||||
await new CallAPI()
|
|
||||||
.PostData(request, "/placement/noti", {
|
|
||||||
subject: "ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ",
|
|
||||||
body: `ผลการประเมินการทดลองปฏิบัติหน้าที่ราชการ เห็นควรให้ขยายระยะเวลาทดลองปฏิบัติหน้าที่ราชการต่อไปอีก ${requestBody.expand_month} เดือน`,
|
|
||||||
receiverUserId: assign.personal_id,
|
|
||||||
payload: "",
|
|
||||||
isSendMail: false,
|
|
||||||
isSendInbox: true,
|
|
||||||
isSendNotification: true,
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error("Error calling API:", error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.personalRepository.save(personal, { data: request });
|
|
||||||
|
|
||||||
return new HttpSuccess();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,246 +1,436 @@
|
||||||
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 ข้อมูลบุคคลในระบบทดลองงาน
|
||||||
*
|
*
|
||||||
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
* @summary เพิ่มคนเข้าระบบทดลองงาน
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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 =>
|
||||||
const personal = await this.personalRepository.save(personalData, {
|
field ?? "";
|
||||||
data: request,
|
personalData.orgChild1Name = getFieldValue(requestBody.orgChild1Name);
|
||||||
})
|
personalData.orgChild2Name = getFieldValue(requestBody.orgChild2Name);
|
||||||
setLogDataDiff(request, { before, after: personal })
|
personalData.orgChild3Name = getFieldValue(requestBody.orgChild3Name);
|
||||||
|
personalData.orgChild4Name = getFieldValue(requestBody.orgChild4Name);
|
||||||
|
|
||||||
return new HttpSuccess()
|
const before = null;
|
||||||
}
|
const personal = await this.personalRepository.save(personalData, {
|
||||||
|
data: request,
|
||||||
|
});
|
||||||
|
setLogDataDiff(request, { before, after: personal });
|
||||||
|
|
||||||
/**
|
return new HttpSuccess();
|
||||||
* API รายการบุคคลในระบบทดลองงาน
|
} catch (error: any) {
|
||||||
*
|
if (error instanceof HttpError) {
|
||||||
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
throw error;
|
||||||
*
|
} else
|
||||||
*/
|
throw new HttpError(
|
||||||
@Get("list")
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
async ListPersonal(@Query() status: string = "", @Query() keyword: string = "", @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Request() request: RequestWithUser) {
|
error.message
|
||||||
await new permission().PermissionList(request, "SYS_PROBATION")
|
);
|
||||||
const _data = await new permission().PermissionOrgList(request, "SYS_PROBATION")
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const conditions: any = {}
|
/**
|
||||||
if (status) {
|
* API รายการบุคคลในระบบทดลองงาน
|
||||||
conditions.probation_status = status
|
*
|
||||||
}
|
* @summary รายชื่อคนที่อยู่ในระบบทดลองงาน
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("list")
|
||||||
|
async ListPersonal(
|
||||||
|
@Query() status: string = "",
|
||||||
|
@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");
|
||||||
|
|
||||||
if (_data.root != undefined && _data.root != null && _data.root[0] != null) {
|
let _data = await new permission().PermissionOrgList(
|
||||||
conditions.root = _data.root
|
request,
|
||||||
}
|
"SYS_DEV_PROJECT"
|
||||||
|
);
|
||||||
|
await new CallAPI()
|
||||||
|
.PostData(request, "/org/finddna", _data)
|
||||||
|
.then((x) => {
|
||||||
|
_data = x;
|
||||||
|
})
|
||||||
|
.catch((x) => {});
|
||||||
|
|
||||||
if (_data.child1 != undefined && _data.child1 != null && _data.child1[0] != null) {
|
// const conditions: any = {};
|
||||||
conditions.child1 = _data.child1
|
// if (status) {
|
||||||
}
|
// conditions.probation_status = status;
|
||||||
|
// }
|
||||||
|
|
||||||
if (_data.child2 != undefined && _data.child2 != null && _data.child2[0] != null) {
|
// if (
|
||||||
conditions.child2 = _data.child2
|
// _data.root != undefined &&
|
||||||
}
|
// _data.root != null &&
|
||||||
|
// _data.root[0] != null
|
||||||
|
// ) {
|
||||||
|
// conditions.root = _data.root;
|
||||||
|
// }
|
||||||
|
|
||||||
if (_data.child3 != undefined && _data.child3 != null && _data.child3[0] != null) {
|
// if (
|
||||||
conditions.child3 = _data.child3
|
// _data.child1 != undefined &&
|
||||||
}
|
// _data.child1 != null &&
|
||||||
|
// _data.child1[0] != null
|
||||||
|
// ) {
|
||||||
|
// conditions.child1 = _data.child1;
|
||||||
|
// }
|
||||||
|
|
||||||
if (_data.child4 != undefined && _data.child4 != null && _data.child4[0] != null) {
|
// if (
|
||||||
conditions.child4 = _data.child4
|
// _data.child2 != undefined &&
|
||||||
}
|
// _data.child2 != null &&
|
||||||
|
// _data.child2[0] != null
|
||||||
|
// ) {
|
||||||
|
// conditions.child2 = _data.child2;
|
||||||
|
// }
|
||||||
|
|
||||||
const searchKeyword = await (keyword ? keyword.trim() : null)
|
// if (
|
||||||
|
// _data.child3 != undefined &&
|
||||||
|
// _data.child3 != null &&
|
||||||
|
// _data.child3[0] != null
|
||||||
|
// ) {
|
||||||
|
// conditions.child3 = _data.child3;
|
||||||
|
// }
|
||||||
|
|
||||||
const [lists, total] = await AppDataSource.getRepository(Personal)
|
// if (
|
||||||
.createQueryBuilder("personal")
|
// _data.child4 != undefined &&
|
||||||
.where(conditions)
|
// _data.child4 != null &&
|
||||||
.andWhere(
|
// _data.child4[0] != null
|
||||||
new Brackets(qb => {
|
// ) {
|
||||||
qb.orWhere(searchKeyword ? `CONCAT(prefixName, firstName," ",lastName) like '%${keyword}%'` : "1=1", {
|
// conditions.child4 = _data.child4;
|
||||||
keyword: `%${searchKeyword}%`,
|
// }
|
||||||
})
|
|
||||||
qb.orWhere(searchKeyword ? `positionName like '%${keyword}%'` : "1=1", {
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
})
|
|
||||||
qb.orWhere(searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1", {
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
})
|
|
||||||
qb.orWhere(searchKeyword ? `organization like '%${keyword}%'` : "1=1", {
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
})
|
|
||||||
qb.orWhere(searchKeyword ? `order_number like '%${keyword}%'` : "1=1", {
|
|
||||||
keyword: `%${searchKeyword}%`,
|
|
||||||
})
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.orderBy("updatedAt", "DESC")
|
|
||||||
.skip((page - 1) * pageSize)
|
|
||||||
.take(pageSize)
|
|
||||||
.getManyAndCount()
|
|
||||||
|
|
||||||
if (!lists) {
|
const searchKeyword = await (keyword ? keyword.trim() : null);
|
||||||
throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, "ไม่สามารถแสดงข้อมูลได้")
|
|
||||||
}
|
|
||||||
|
|
||||||
let result: any = []
|
const [lists, total] = await AppDataSource.getRepository(Personal)
|
||||||
|
.createQueryBuilder("personal")
|
||||||
|
.andWhere(
|
||||||
|
_data.root != undefined && _data.root != null
|
||||||
|
? _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}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword ? `positionName like '%${keyword}%'` : "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword ? `positionLevelName like '%${keyword}%'` : "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword ? `organization like '%${keyword}%'` : "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
qb.orWhere(
|
||||||
|
searchKeyword ? `order_number like '%${keyword}%'` : "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.orderBy("updatedAt", "DESC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.getManyAndCount();
|
||||||
|
|
||||||
for (let i = 0; i < lists.length; i++) {
|
if (!lists) {
|
||||||
const probation_no = await this.assignRepository.count({
|
throw new HttpError(
|
||||||
where: { personal_id: lists[i].personal_id },
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
})
|
"ไม่สามารถแสดงข้อมูลได้"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
await result.push({
|
let result: any = [];
|
||||||
personal_id: lists[i].personal_id,
|
|
||||||
ordering: i + 1,
|
|
||||||
name: lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
|
||||||
prefixName: lists[i].prefixName,
|
|
||||||
firstName: lists[i].firstName,
|
|
||||||
lastName: lists[i].lastName,
|
|
||||||
idcard: lists[i].idcard,
|
|
||||||
position_line: lists[i].positionName,
|
|
||||||
position_level: lists[i].positionLevelName,
|
|
||||||
position_type: lists[i].positionTypeName,
|
|
||||||
organization: lists[i].organization,
|
|
||||||
probation_no: probation_no,
|
|
||||||
order_number: lists[i].order_number,
|
|
||||||
probation_status: lists[i].probation_status,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
// await Promise.all(
|
|
||||||
// lists.map(async (item, index) => {
|
|
||||||
// const probation_no = await this.assignRepository.count({
|
|
||||||
// where: {
|
|
||||||
// personal_id: item.personal_id,
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// await result.push({
|
for (let i = 0; i < lists.length; i++) {
|
||||||
// personal_id: item.personal_id,
|
const probation_no = await this.assignRepository.count({
|
||||||
// ordering: index + 1,
|
where: { personal_id: lists[i].personal_id },
|
||||||
// name: item.prefixName + item.firstName + " " + item.lastName,
|
});
|
||||||
// idcard: item.idcard,
|
|
||||||
// // prefixName: item.prefixName,
|
|
||||||
// // firstName: item.firstName,
|
|
||||||
// // lastName: item.lastName,
|
|
||||||
// position_line: item.positionName,
|
|
||||||
// position_level: item.positionLevelName,
|
|
||||||
// position_type: item.positionTypeName,
|
|
||||||
// organization: item.organization,
|
|
||||||
// probation_no: probation_no,
|
|
||||||
// order_number: item.order_number,
|
|
||||||
// probation_status: item.probation_status,
|
|
||||||
// });
|
|
||||||
// }),
|
|
||||||
// );
|
|
||||||
|
|
||||||
return new HttpSuccess({ data: result, total: total })
|
await result.push({
|
||||||
}
|
personal_id: lists[i].personal_id,
|
||||||
|
ordering: i + 1,
|
||||||
|
name:
|
||||||
|
lists[i].prefixName + lists[i].firstName + " " + lists[i].lastName,
|
||||||
|
prefixName: lists[i].prefixName,
|
||||||
|
firstName: lists[i].firstName,
|
||||||
|
lastName: lists[i].lastName,
|
||||||
|
idcard: lists[i].idcard,
|
||||||
|
position_line: lists[i].positionName,
|
||||||
|
position_level: lists[i].positionLevelName,
|
||||||
|
position_type: lists[i].positionTypeName,
|
||||||
|
organization: lists[i].organization,
|
||||||
|
probation_no: probation_no,
|
||||||
|
order_number: lists[i].order_number,
|
||||||
|
probation_status: lists[i].probation_status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// await Promise.all(
|
||||||
|
// lists.map(async (item, index) => {
|
||||||
|
// const probation_no = await this.assignRepository.count({
|
||||||
|
// where: {
|
||||||
|
// personal_id: item.personal_id,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
|
||||||
/**
|
// await result.push({
|
||||||
* API ข้อมูลบุคคลในระบบทดลองงาน
|
// personal_id: item.personal_id,
|
||||||
*
|
// ordering: index + 1,
|
||||||
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
// name: item.prefixName + item.firstName + " " + item.lastName,
|
||||||
*
|
// idcard: item.idcard,
|
||||||
*/
|
// // prefixName: item.prefixName,
|
||||||
@Get("")
|
// // firstName: item.firstName,
|
||||||
async GetPersonal(@Request() request: RequestWithUser, @Query() personal_id: string) {
|
// // lastName: item.lastName,
|
||||||
let _workflow = await new permission().Workflow(request, personal_id, "SYS_PROBATION")
|
// position_line: item.positionName,
|
||||||
if (_workflow == false) await new permission().PermissionGet(request, "SYS_PROBATION")
|
// position_level: item.positionLevelName,
|
||||||
const person = await this.personalRepository.findOne({
|
// position_type: item.positionTypeName,
|
||||||
where: { personal_id: personal_id },
|
// organization: item.organization,
|
||||||
})
|
// probation_no: probation_no,
|
||||||
|
// order_number: item.order_number,
|
||||||
|
// probation_status: item.probation_status,
|
||||||
|
// });
|
||||||
|
// }),
|
||||||
|
// );
|
||||||
|
|
||||||
if (!person) {
|
return new HttpSuccess({ data: result, total: total });
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล")
|
} catch (error: any) {
|
||||||
}
|
if (error instanceof HttpError) {
|
||||||
|
throw error;
|
||||||
|
} else
|
||||||
|
throw new HttpError(
|
||||||
|
HttpStatusCode.INTERNAL_SERVER_ERROR,
|
||||||
|
error.message
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const probation_no = await this.assignRepository.count({
|
/**
|
||||||
where: { personal_id: person.personal_id },
|
* API ข้อมูลบุคคลในระบบทดลองงาน
|
||||||
})
|
*
|
||||||
|
* @summary ข้อมูลคนที่อยูาในระบบทดลองงาน
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
@Get("")
|
||||||
|
async GetPersonal(
|
||||||
|
@Request() request: RequestWithUser,
|
||||||
|
@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({
|
||||||
|
where: { personal_id: personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
const result = await {
|
if (!person) {
|
||||||
personal_id: person.personal_id,
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลบุคคล");
|
||||||
name: person.prefixName + person.firstName + " " + person.lastName,
|
}
|
||||||
position_line: person.positionName,
|
|
||||||
position_level: person.positionLevelName,
|
|
||||||
position_type: person.positionTypeName,
|
|
||||||
organization: person.organization,
|
|
||||||
probation_no: probation_no,
|
|
||||||
order_number: person.order_number,
|
|
||||||
probation_status: person.probation_status,
|
|
||||||
}
|
|
||||||
|
|
||||||
return new HttpSuccess(result)
|
const probation_no = await this.assignRepository.count({
|
||||||
}
|
where: { personal_id: person.personal_id },
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await {
|
||||||
|
personal_id: person.personal_id,
|
||||||
|
name: person.prefixName + person.firstName + " " + person.lastName,
|
||||||
|
position_line: person.positionName,
|
||||||
|
position_level: person.positionLevelName,
|
||||||
|
position_type: person.positionTypeName,
|
||||||
|
organization: person.organization,
|
||||||
|
probation_no: probation_no,
|
||||||
|
order_number: person.order_number,
|
||||||
|
probation_status: person.probation_status,
|
||||||
|
};
|
||||||
|
|
||||||
|
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
|
|
@ -1,132 +1,190 @@
|
||||||
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 แบบสำรวจความคิดเห็น
|
||||||
*
|
*
|
||||||
* @summary แบบสำรวจความคิดเห็น
|
* @summary แบบสำรวจความคิดเห็น
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API บันทึกแบบสำรวจความคิดเห็น
|
* API บันทึกแบบสำรวจความคิดเห็น
|
||||||
*
|
*
|
||||||
* @summary บันทึกแบบสำรวจความคิดเห็น
|
* @summary บันทึกแบบสำรวจความคิดเห็น
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API รายการผลสำรวจความคิดเห็นของ Admin
|
* API รายการผลสำรวจความคิดเห็นของ Admin
|
||||||
*
|
*
|
||||||
* @summary ผลสำรวจความคิดเห็นของ Admin
|
* @summary ผลสำรวจความคิดเห็นของ Admin
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
@Get("/admin")
|
@Get("/admin")
|
||||||
async GetSurveyAdmin(
|
async GetSurveyAdmin(
|
||||||
@Query() year: number = new Date().getFullYear(),
|
@Query() year: number = new Date().getFullYear(),
|
||||||
@Query() keyword: string = "",
|
@Query() keyword: string = "",
|
||||||
@Query("page") page: number = 1,
|
@Query("page") page: number = 1,
|
||||||
@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(
|
||||||
.andWhere(
|
`survey.createdAt BETWEEN '${start.toISOString()}' AND '${end.toISOString()}'`
|
||||||
new Brackets(qb => {
|
)
|
||||||
qb.orWhere(searchKeyword ? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'` : "1=1", {
|
.andWhere(
|
||||||
keyword: `%${searchKeyword}%`,
|
new Brackets((qb) => {
|
||||||
})
|
qb.orWhere(
|
||||||
qb.orWhere(searchKeyword ? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'` : "1=1", {
|
searchKeyword
|
||||||
keyword: `%${searchKeyword}%`,
|
? `CONCAT(personal.prefixName, personal.firstName," ",personal.lastName) like '%${keyword}%'`
|
||||||
})
|
: "1=1",
|
||||||
})
|
{
|
||||||
)
|
keyword: `%${searchKeyword}%`,
|
||||||
.orderBy("survey.createdAt", "DESC")
|
}
|
||||||
.skip((page - 1) * pageSize)
|
);
|
||||||
.take(pageSize)
|
qb.orWhere(
|
||||||
.getManyAndCount()
|
searchKeyword
|
||||||
|
? `CONCAT(personal.positionName, personal.positionLevelName) like '%${keyword}%'`
|
||||||
|
: "1=1",
|
||||||
|
{
|
||||||
|
keyword: `%${searchKeyword}%`,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.orderBy("survey.createdAt", "DESC")
|
||||||
|
.skip((page - 1) * pageSize)
|
||||||
|
.take(pageSize)
|
||||||
|
.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,
|
||||||
assign_id: item.assign_id,
|
assign_id: item.assign_id,
|
||||||
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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"
|
||||||
|
|
|
||||||
|
|
@ -1,230 +1,247 @@
|
||||||
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,
|
||||||
comment:
|
comment:
|
||||||
"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;
|
||||||
|
|
||||||
@OneToMany(() => Assign, (assign: Assign) => assign.personal_id)
|
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child1", default: null })
|
||||||
@JoinColumn({ name: "id" })
|
orgChild1Name: string;
|
||||||
assign: Assign[]
|
|
||||||
|
|
||||||
@OneToOne(() => Appoint, appoint => appoint.personal)
|
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child2", default: null })
|
||||||
@JoinColumn()
|
orgChild2Name: string;
|
||||||
appoint: Appoint
|
|
||||||
|
|
||||||
@OneToOne(() => Survey, { nullable: true })
|
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child3", default: null })
|
||||||
survey: Survey | null
|
orgChild3Name: string;
|
||||||
|
|
||||||
|
@Column({ nullable: true, comment: "ชื่อ หน่วยงาน child4", default: null })
|
||||||
|
orgChild4Name: string;
|
||||||
|
|
||||||
|
@OneToMany(() => Assign, (assign: Assign) => assign.personal_id)
|
||||||
|
@JoinColumn({ name: "id" })
|
||||||
|
assign: Assign[];
|
||||||
|
|
||||||
|
@OneToOne(() => Appoint, (appoint) => appoint.personal)
|
||||||
|
@JoinColumn()
|
||||||
|
appoint: Appoint;
|
||||||
|
|
||||||
|
@OneToOne(() => Survey, { nullable: true })
|
||||||
|
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>;
|
||||||
|
|
|
||||||
|
|
@ -19,10 +19,20 @@ export type LogSequence = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
export function setLogDataDiff(req: RequestWithUser, data: DataDiff) {
|
||||||
req.app.locals.logData.dataDiff = {
|
// Check if data.before and data.after are valid objects
|
||||||
before: JSON.stringify(data.before),
|
if (
|
||||||
after: JSON.stringify(data.after),
|
data.before &&
|
||||||
};
|
typeof data.before === "object" &&
|
||||||
|
data.after &&
|
||||||
|
typeof data.after === "object"
|
||||||
|
) {
|
||||||
|
req.app.locals.logData.dataDiff = {
|
||||||
|
before: JSON.stringify(data.before),
|
||||||
|
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) {
|
||||||
|
|
|
||||||
20
src/migration/1749186876022-personal-add-child-name.ts
Normal file
20
src/migration/1749186876022-personal-add-child-name.ts
Normal 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\``);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue