filter by dna

This commit is contained in:
Moss 2025-06-12 19:30:57 +07:00
parent 2178caa0c1
commit 309f295391

View file

@ -79,29 +79,41 @@ export class EvaluationController {
@Get("performance/user")
async listPerformance(@Request() request: RequestWithUser) {
const list = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.where("evaluation.userId = :userId", { userId: request.user.sub })
.andWhere("evaluation.step = :step", { step: "DONE" })
.andWhere("evaluation.evaluationResult IN (:...evaluationResult)", {
evaluationResult: ["PASS", "NOTPASS"],
})
.select([
"evaluation.id",
"evaluation.type",
"evaluation.subject",
"evaluation.evaluationResult",
"evaluation.lastUpdatedAt",
])
.orderBy("evaluation.lastUpdatedAt", "ASC")
.getMany();
.createQueryBuilder("evaluation")
.where("evaluation.userId = :userId", { userId: request.user.sub })
.andWhere("evaluation.step = :step", { step: "DONE" })
.andWhere("evaluation.evaluationResult IN (:...evaluationResult)", {
evaluationResult: ["PASS", "NOTPASS"],
})
.select([
"evaluation.id",
"evaluation.type",
"evaluation.subject",
"evaluation.evaluationResult",
"evaluation.lastUpdatedAt",
])
.orderBy("evaluation.lastUpdatedAt", "ASC")
.getMany();
const performance = list.map((item) => ({
id: item.id,
year: item.lastUpdatedAt?Extension.ToThaiYear(item.lastUpdatedAt.getFullYear()):null,
type: item.type == "EXPERT" ? "ชำนาญการ" : item.type == "EXPERTISE" ? "เชียวชาญ" : item.type == "SPECIAL_EXPERT" ? "ชำนาญการพิเศษ": null,
subject: item.subject?item.subject[0]:null,
evaluationResult: item.evaluationResult == "PASS" ? "ผ่าน" : item.evaluationResult == "NOTPASS" ? "ไม่ผ่าน" : null,
}));
const performance = list.map((item) => ({
id: item.id,
year: item.lastUpdatedAt ? Extension.ToThaiYear(item.lastUpdatedAt.getFullYear()) : null,
type:
item.type == "EXPERT"
? "ชำนาญการ"
: item.type == "EXPERTISE"
? "เชียวชาญ"
: item.type == "SPECIAL_EXPERT"
? "ชำนาญการพิเศษ"
: null,
subject: item.subject ? item.subject[0] : null,
evaluationResult:
item.evaluationResult == "PASS"
? "ผ่าน"
: item.evaluationResult == "NOTPASS"
? "ไม่ผ่าน"
: null,
}));
return new HttpSuccess(performance);
}
@ -134,6 +146,12 @@ export class EvaluationController {
try {
// await new permission().PermissionList(request, "SYS_EVA_REQ");
let _data = await new permission().PermissionOrgList(request, "SYS_EVA_REQ");
await new CallAPI()
.PostData(request, "/org/finddna", _data)
.then((x) => {
_data = x;
})
.catch((x) => {});
const [evaluation, total] = await AppDataSource.getRepository(Evaluation)
.createQueryBuilder("evaluation")
.andWhere(
@ -349,18 +367,21 @@ export class EvaluationController {
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
/**
* API get template
*
* @summary get template (ADMIN)
*
* @param {string} id id
*/
@Get("get-announce-template/{id}")
async getAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser) {
@Get("get-announce-template/{id}")
async getAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser) {
try {
const evaluation = await this.evaluationRepository.findOne({ where: { id } , select: ["id","detailAnnounceStep5Body","detailAnnounceStep5Footer"]});
const evaluation = await this.evaluationRepository.findOne({
where: { id },
select: ["id", "detailAnnounceStep5Body", "detailAnnounceStep5Footer"],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการประเมิน");
}
@ -370,7 +391,7 @@ export class EvaluationController {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
}
/**
* step
@ -510,24 +531,31 @@ export class EvaluationController {
if (!evaluation) {
return `not found data`;
}
let _code = requestBody.type == "EXPERT" ? "ST05-1" : requestBody.type == "EXPERTISE" ? "ST05-1" : requestBody.type == "SPECIAL_EXPERT" ? "ST05-2" : "ST05-1";
let _code =
requestBody.type == "EXPERT"
? "ST05-1"
: requestBody.type == "EXPERTISE"
? "ST05-1"
: requestBody.type == "SPECIAL_EXPERT"
? "ST05-2"
: "ST05-1";
const announceTemplate5 = await this.announceTemplateRepository.findOne({
where:{
code : _code
where: {
code: _code,
},
select: ["detailBody","detailFooter"]
})
select: ["detailBody", "detailFooter"],
});
const before = null;
await new CallAPI()
.GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`)
.then(async (x) => {
evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId;
})
.catch();
.GetData(request, `/org/profile/keycloak/commander/${request.user.sub}`)
.then(async (x) => {
evaluation.rootDnaId = x.rootDnaId;
evaluation.child1DnaId = x.child1DnaId;
evaluation.child2DnaId = x.child2DnaId;
evaluation.child3DnaId = x.child3DnaId;
evaluation.child4DnaId = x.child4DnaId;
})
.catch();
evaluation.step = "PREPARE_DOC_V1";
evaluation.type = requestBody.type == "EXPERT" ? "EXPERT" : "SPECIAL_EXPERT";
evaluation.fullName = requestBody.fullName;
@ -538,10 +566,16 @@ export class EvaluationController {
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
evaluation.userId = request.user.sub;
evaluation.detailAnnounceStep5Body = announceTemplate5?.detailBody??_null;
evaluation.detailAnnounceStep5Footer = announceTemplate5?.detailFooter??_null;
evaluation.positionArea = requestBody.positionArea && requestBody.positionArea !== "" ? requestBody.positionArea : _null;
evaluation.posExecutive = requestBody.posExecutive && requestBody.posExecutive !== "" ? requestBody.posExecutive : _null;
evaluation.detailAnnounceStep5Body = announceTemplate5?.detailBody ?? _null;
evaluation.detailAnnounceStep5Footer = announceTemplate5?.detailFooter ?? _null;
evaluation.positionArea =
requestBody.positionArea && requestBody.positionArea !== ""
? requestBody.positionArea
: _null;
evaluation.posExecutive =
requestBody.posExecutive && requestBody.posExecutive !== ""
? requestBody.posExecutive
: _null;
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
@ -663,7 +697,7 @@ export class EvaluationController {
salaries.lastUpdateUserId = request.user.sub;
salaries.lastUpdateFullName = request.user.name;
salaries.lastUpdatedAt = new Date();
await this.salaryRepository.save(salaries, { data: request });
setLogDataDiff(request, { before, after: salaries });
});
@ -714,7 +748,7 @@ export class EvaluationController {
await this.assessmentRepository.save(assessment, { data: request });
setLogDataDiff(request, { before, after: assessment });
});
//Portfolio
if (requestBody.portfolios != null)
requestBody.portfolios.forEach(async (pfo) => {
@ -730,7 +764,7 @@ export class EvaluationController {
portfolio.evaluation = evaluation;
await this.portfolioRepository.save(portfolio, { data: request });
setLogDataDiff(request, { before, after: portfolio });
});
});
//Performance
if (requestBody.performances != null)
@ -749,8 +783,8 @@ export class EvaluationController {
performance.evaluation = evaluation;
await this.performanceRepository.save(performance, { data: request });
setLogDataDiff(request, { before, after: performance });
});
});
//EvaluationLogs
const evaluationLogs = new EvaluationLogs();
evaluationLogs.step = (await ConvertToThaiStep("PREPARE_DOC_V1")) ?? _null;
@ -1807,21 +1841,20 @@ export class EvaluationController {
})
.catch((x) => {});
await Promise.all(
_director.map((director:any) => {
_director.map((director: any) => {
return new CallAPI()
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
receiverUserId: director.keycloak,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {
})
.catch((x) => {});
})
.PostData(request, "/placement/noti/keycloak", {
subject: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
body: `${evaluation.fullName} แบบประเมินมีการบันทึกตรวจสอบจัดเตรียมเอกสารเล่ม 1`,
receiverUserId: director.keycloak,
payload: "",
isSendMail: true,
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
}),
);
return new HttpSuccess();
} catch (error: any) {
@ -2115,39 +2148,43 @@ export class EvaluationController {
}
}
/**
/**
* API template
*
* @summary template (ADMIN)
*
* @param {string} id id
*/
@Put("edit-announce-template/{id}")
async editAnnounceTemp(@Path() id: string, @Request() request: RequestWithUser, @Body() body: {detailBody: string, detailFooter: string}) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const before = structuredClone(evaluation);
evaluation.detailAnnounceStep5Body = body.detailBody;
evaluation.detailAnnounceStep5Footer = body.detailFooter;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
@Put("edit-announce-template/{id}")
async editAnnounceTemp(
@Path() id: string,
@Request() request: RequestWithUser,
@Body() body: { detailBody: string; detailFooter: string },
) {
try {
await new permission().PermissionUpdate(request, "SYS_EVA_REQ");
const evaluation = await this.evaluationRepository.findOne({ where: { id } });
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const before = structuredClone(evaluation);
evaluation.detailAnnounceStep5Body = body.detailBody;
evaluation.detailAnnounceStep5Footer = body.detailFooter;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
await this.evaluationRepository.save(evaluation, { data: request });
setLogDataDiff(request, { before, after: evaluation });
return new HttpSuccess();
} catch (error: any) {
if (error instanceof HttpError) {
throw error;
} else throw new HttpError(HttpStatusCode.INTERNAL_SERVER_ERROR, error);
}
}
/**
* API
@ -2196,7 +2233,7 @@ export class EvaluationController {
evaluation.commanderAboveOrgDoc2 = evaluation.commanderAboveOrg;
evaluation.commanderAboveOrgOldDoc2 = evaluation.commanderAboveOrgOld;
evaluation.commanderAbovePositionOldDoc2 = evaluation.commanderAbovePositionOld;
evaluation.datePrepareDoc2 = new Date();
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
@ -2770,7 +2807,7 @@ export class EvaluationController {
"commanderAbovePositionOld",
],
});
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
@ -2951,19 +2988,19 @@ export class EvaluationController {
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const _null:any = null;
const _null: any = null;
evaluation.author = body.author;
evaluation.subject = body.subject;
evaluation.commanderFullname = body.commanderFullname;
evaluation.commanderOrg = body.commanderOrg??_null;
evaluation.commanderOrgOld = body.commanderOrgOld??_null;
evaluation.commanderOrg = body.commanderOrg ?? _null;
evaluation.commanderOrgOld = body.commanderOrgOld ?? _null;
evaluation.commanderPosition = body.commanderPosition;
evaluation.commanderPositionOld = body.commanderPositionOld??_null;
evaluation.commanderPositionOld = body.commanderPositionOld ?? _null;
evaluation.commanderAboveFullname = body.commanderAboveFullname;
evaluation.commanderAboveOrg = body.commanderAboveOrg??_null;
evaluation.commanderAboveOrgOld = body.commanderAboveOrgOld??_null;
evaluation.commanderAboveOrg = body.commanderAboveOrg ?? _null;
evaluation.commanderAboveOrgOld = body.commanderAboveOrgOld ?? _null;
evaluation.commanderAbovePosition = body.commanderAbovePosition;
evaluation.commanderAbovePositionOld = body.commanderAbovePositionOld??_null;
evaluation.commanderAbovePositionOld = body.commanderAbovePositionOld ?? _null;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;
evaluation.lastUpdatedAt = new Date();
@ -3024,20 +3061,20 @@ export class EvaluationController {
if (!evaluation) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "not found.");
}
const _null:any = null;
const _null: any = null;
evaluation.authorDoc2 = body.authorDoc2;
evaluation.subjectDoc2 = body.subjectDoc2;
evaluation.assignedPosition = body.assignedPosition;
evaluation.commanderFullnameDoc2 = body.commanderFullnameDoc2;
evaluation.commanderOrgDoc2 = body.commanderOrgDoc2??_null;
evaluation.commanderOrgOldDoc2 = body.commanderOrgOldDoc2??_null;
evaluation.commanderOrgDoc2 = body.commanderOrgDoc2 ?? _null;
evaluation.commanderOrgOldDoc2 = body.commanderOrgOldDoc2 ?? _null;
evaluation.commanderPositionDoc2 = body.commanderPositionDoc2;
evaluation.commanderPositionOldDoc2 = body.commanderPositionOldDoc2??_null;
evaluation.commanderPositionOldDoc2 = body.commanderPositionOldDoc2 ?? _null;
evaluation.commanderAboveFullnameDoc2 = body.commanderAboveFullnameDoc2;
evaluation.commanderAboveOrgDoc2 = body.commanderAboveOrgDoc2??_null;
evaluation.commanderAboveOrgOldDoc2 = body.commanderAboveOrgOldDoc2??_null;
evaluation.commanderAboveOrgDoc2 = body.commanderAboveOrgDoc2 ?? _null;
evaluation.commanderAboveOrgOldDoc2 = body.commanderAboveOrgOldDoc2 ?? _null;
evaluation.commanderAbovePositionDoc2 = body.commanderAbovePositionDoc2;
evaluation.commanderAbovePositionOldDoc2 = body.commanderAbovePositionOldDoc2??_null;
evaluation.commanderAbovePositionOldDoc2 = body.commanderAbovePositionOldDoc2 ?? _null;
evaluation.isUpdated = true;
evaluation.lastUpdateUserId = request.user.sub;
evaluation.lastUpdateFullName = request.user.name;