2024-04-22 13:23:31 +07:00
import {
Controller ,
Get ,
Post ,
Put ,
Delete ,
Route ,
Security ,
Tags ,
Body ,
Path ,
Request ,
Example ,
SuccessResponse ,
Response ,
Query ,
2024-04-26 10:18:00 +07:00
ArrayValidator ,
2024-04-22 13:23:31 +07:00
} from "tsoa" ;
import { AppDataSource } from "../database/data-source" ;
import HttpSuccess from "../interfaces/http-success" ;
import HttpError from "../interfaces/http-error" ;
import HttpStatusCode from "../interfaces/http-status" ;
import { KpiPeriod } from "../entities/kpiPeriod" ;
2024-04-26 10:18:00 +07:00
import {
KpiUserEvaluation ,
createKpiUserEvaluation ,
2024-04-26 13:08:23 +07:00
updateKpiUserCheckEvaluation ,
2024-04-26 10:18:00 +07:00
updateKpiUserEvaluation ,
2024-04-26 17:39:24 +07:00
updateKpiUserPointEvaluation ,
2024-05-09 12:05:55 +07:00
updateKpiUserStatusEvaluation ,
updateKpiUserReqEditEvaluation ,
2024-05-09 18:07:15 +07:00
updateKpiUserResultEvaluation ,
2024-04-26 10:18:00 +07:00
} from "../entities/kpiUserEvaluation" ;
2024-06-28 14:02:41 +07:00
import { Like , In , Brackets , IsNull , Not } from "typeorm" ;
2024-04-22 13:23:31 +07:00
import CallAPI from "../interfaces/call-api" ;
2024-06-19 16:40:44 +07:00
import { KpiCapacity } from "../entities/kpiCapacity" ;
import { Position } from "../entities/position" ;
import { KpiLink } from "../entities/kpiLink" ;
import { KpiGroup } from "../entities/kpiGroup" ;
2024-08-09 16:28:52 +07:00
import { RequestWithUser } from "../middlewares/user" ;
import permission from "../interfaces/permission" ;
2024-04-22 13:23:31 +07:00
@Route ( "api/v1/kpi/user/evaluation" )
@Tags ( "kpiUserEvaluation" )
@Security ( "bearerAuth" )
@Response (
HttpStatusCode . INTERNAL_SERVER_ERROR ,
"เกิดข้อผิดพลาด ไม่สามารถแสดงรายการได้ กรุณาลองใหม่ในภายหลัง" ,
)
@SuccessResponse ( HttpStatusCode . OK , "สำเร็จ" )
export class KpiUserEvaluationController extends Controller {
private kpiPeriodRepository = AppDataSource . getRepository ( KpiPeriod ) ;
private kpiUserEvalutionRepository = AppDataSource . getRepository ( KpiUserEvaluation ) ;
2024-06-19 16:40:44 +07:00
private kpiCapacityRepository = AppDataSource . getRepository ( KpiCapacity ) ;
private kpiPositionRepository = AppDataSource . getRepository ( Position ) ;
private kpiLinkRepository = AppDataSource . getRepository ( KpiLink ) ;
private kpiGroupRepository = AppDataSource . getRepository ( KpiGroup ) ;
2024-04-22 13:23:31 +07:00
2024-04-26 10:18:00 +07:00
/ * *
* API
*
* @summary ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ท ั ้ ง ห ม ด
*
* /
2024-05-09 16:08:21 +07:00
@Post ( "admin" )
2024-04-26 10:18:00 +07:00
async listKpiAdminEvaluation (
2024-05-09 12:52:35 +07:00
@Request ( ) request : { user : Record < string , any > } ,
2024-05-09 16:08:21 +07:00
@Body ( )
requestBody : {
page : number ;
pageSize : number ;
kpiPeriodId? : string ;
keyword? : string ;
status? : string | null ;
results? : string | null ;
reqedit? : string | null ;
2024-05-17 14:17:01 +07:00
evaluating? : boolean | null ;
2024-05-09 16:08:21 +07:00
} ,
2024-04-26 10:18:00 +07:00
) {
2024-05-09 12:52:35 +07:00
let profileId : any = null ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-05-09 12:52:35 +07:00
. then ( ( x ) = > {
profileId = x . profileId ;
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
2024-05-13 18:14:08 +07:00
// let role = "EVALUATOR";
// if (profileId == item.commanderId) {
// role = "COMMANDER";
// } else if (profileId == item.commanderHighId) {
// role = "COMMANDERHIGH";
// }
2024-04-26 10:18:00 +07:00
const [ kpiUserEvaluation , total ] = await AppDataSource . getRepository ( KpiUserEvaluation )
. createQueryBuilder ( "kpiUserEvaluation" )
2024-05-09 16:08:21 +07:00
. andWhere ( requestBody . kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1" , {
kpiPeriodId : requestBody.kpiPeriodId ,
2024-05-09 15:20:49 +07:00
} )
. andWhere (
2024-05-09 16:08:21 +07:00
requestBody . status != null && requestBody . status != undefined
2024-05-13 18:14:08 +07:00
? requestBody . status . trim ( ) . toUpperCase ( ) == "NEW"
? ` evaluationStatus LIKE CASE WHEN evaluatorId = " ${ profileId } " THEN "NEW_EVALUATOR" WHEN commanderId = " ${ profileId } " THEN "NEW_COMMANDER" WHEN commanderHighId = " ${ profileId } " THEN "NEW_COMMANDER_HIGH" ELSE " ${ requestBody . status . trim ( ) . toUpperCase ( ) } " END `
2024-06-26 23:27:33 +07:00
: requestBody . status . trim ( ) . toUpperCase ( ) == "EVALUATING_EVALUATOR" ||
requestBody . status . trim ( ) . toUpperCase ( ) == "EVALUATING"
? "evaluationStatus LIKE :status"
: requestBody . status . trim ( ) . toUpperCase ( ) == "SUMMARY"
? "evaluationStatus LIKE :status"
: "evaluationStatus LIKE :status"
2024-05-09 16:08:21 +07:00
: "1=1" ,
{
2024-05-13 18:14:08 +07:00
status :
requestBody . status == null || requestBody . status == undefined
? null
2024-06-26 23:27:33 +07:00
: requestBody . status . trim ( ) . toUpperCase ( ) == "EVALUATING" ||
requestBody . status . trim ( ) . toUpperCase ( ) == "EVALUATING_EVALUATOR" ||
requestBody . status . trim ( ) . toUpperCase ( ) == "SUMMARY"
? requestBody . status . trim ( ) . toUpperCase ( ) == "SUMMARY"
? ` % ${ requestBody . status . trim ( ) . toUpperCase ( ) } % `
: ` %EVALUATING% `
: requestBody . status . trim ( ) . toUpperCase ( ) ,
2024-05-09 16:08:21 +07:00
} ,
)
. andWhere (
requestBody . results != null && requestBody . results != undefined
? "evaluationResults LIKE :results"
: "1=1" ,
2024-05-09 15:20:49 +07:00
{
2024-05-13 18:14:08 +07:00
results :
requestBody . results == null || requestBody . results == undefined
? null
: requestBody . results . trim ( ) . toUpperCase ( ) ,
2024-05-09 15:20:49 +07:00
} ,
)
. andWhere (
2024-05-09 16:08:21 +07:00
requestBody . reqedit != null && requestBody . reqedit != undefined
2024-05-13 18:14:08 +07:00
? requestBody . reqedit . trim ( ) . toUpperCase ( ) == "NEW"
? ` evaluationReqEdit LIKE CASE WHEN evaluatorId = " ${ profileId } " THEN "EVALUATOR" WHEN commanderId = " ${ profileId } " THEN "COMMANDER" WHEN commanderHighId = " ${ profileId } " THEN "COMMANDER_HIGH" ELSE " ${ requestBody . reqedit . trim ( ) . toUpperCase ( ) } " END `
: "evaluationReqEdit LIKE :reqedit"
2024-05-09 16:08:21 +07:00
: "1=1" ,
2024-05-09 15:20:49 +07:00
{
2024-05-13 18:14:08 +07:00
reqedit :
requestBody . reqedit == null || requestBody . reqedit == undefined
? null
: requestBody . reqedit . trim ( ) . toUpperCase ( ) ,
2024-05-09 15:20:49 +07:00
} ,
)
2024-05-09 12:52:35 +07:00
. andWhere (
new Brackets ( ( qb ) = > {
qb . orWhere ( "kpiUserEvaluation.evaluatorId LIKE :profileId" , {
2024-05-13 18:14:08 +07:00
profileId : ` ${ profileId } ` ,
2024-05-09 12:52:35 +07:00
} )
. orWhere ( "kpiUserEvaluation.commanderId LIKE :profileId" , {
2024-05-13 18:14:08 +07:00
profileId : ` ${ profileId } ` ,
2024-05-09 12:52:35 +07:00
} )
. orWhere ( "kpiUserEvaluation.commanderHighId LIKE :profileId" , {
2024-05-13 18:14:08 +07:00
profileId : ` ${ profileId } ` ,
2024-05-09 12:52:35 +07:00
} ) ;
} ) ,
)
2024-04-26 17:39:24 +07:00
. andWhere (
new Brackets ( ( qb ) = > {
2024-05-09 16:08:21 +07:00
qb . orWhere ( "kpiUserEvaluation.prefix LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.firstName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.lastName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} ) ;
2024-04-26 17:39:24 +07:00
} ) ,
)
2024-04-26 10:18:00 +07:00
. orderBy ( "kpiUserEvaluation.createdAt" , "ASC" )
2024-05-09 16:08:21 +07:00
. skip ( ( requestBody . page - 1 ) * requestBody . pageSize )
. take ( requestBody . pageSize )
2024-04-26 10:18:00 +07:00
. getManyAndCount ( ) ;
const mapData = kpiUserEvaluation . map ( ( item ) = > ( {
id : item.id ,
profileId : item.profileId ,
prefix : item.prefix ,
firstname : item.firstName ,
2024-06-13 11:48:15 +07:00
lastname : item.lastName ,
kpiPeriodId : item.kpiPeriodId ,
evaluationStatus : item.evaluationStatus ,
evaluationResults : item.evaluationResults ,
createdAt : item.createdAt ,
evaluatorId : item.evaluatorId ,
commanderId : item.commanderId ,
commanderHighId : item.commanderHighId ,
} ) ) ;
return new HttpSuccess ( { data : mapData , total } ) ;
}
/ * *
* API
*
* @summary ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ท ั ้ ง ห ม ด
*
* /
@Post ( "list" )
async listKpiListEvaluation (
@Request ( ) request : { user : Record < string , any > } ,
@Body ( )
requestBody : {
page : number ;
pageSize : number ;
kpiPeriodId? : string ;
keyword? : string ;
status? : string | null ;
results? : string | null ;
reqedit? : string | null ;
evaluating? : boolean | null ;
} ,
) {
2024-08-16 12:08:10 +07:00
let conditionFullName =
"CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword" ;
2024-06-13 11:48:15 +07:00
const [ kpiUserEvaluation , total ] = await AppDataSource . getRepository ( KpiUserEvaluation )
. createQueryBuilder ( "kpiUserEvaluation" )
. andWhere ( requestBody . kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1" , {
kpiPeriodId : requestBody.kpiPeriodId ,
} )
2024-07-09 14:39:43 +07:00
. andWhere (
requestBody . status != null && requestBody . status != undefined
? "evaluationstatus LIKE :status"
: "1=1" ,
{
status :
requestBody . status == null || requestBody . status == undefined
? null
: requestBody . status . trim ( ) . toUpperCase ( ) ,
} ,
)
2024-06-13 11:48:15 +07:00
. andWhere (
requestBody . results != null && requestBody . results != undefined
? "evaluationResults LIKE :results"
: "1=1" ,
{
results :
requestBody . results == null || requestBody . results == undefined
? null
: requestBody . results . trim ( ) . toUpperCase ( ) ,
} ,
)
. andWhere (
new Brackets ( ( qb ) = > {
qb . orWhere ( "kpiUserEvaluation.prefix LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
2024-08-14 10:35:48 +07:00
. orWhere ( "kpiUserEvaluation.firstName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.lastName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.org LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.position LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.posTypeName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
. orWhere ( "kpiUserEvaluation.posLevelName LIKE :keyword" , {
keyword : ` % ${ requestBody . keyword } % ` ,
} )
2024-08-16 12:08:10 +07:00
. orWhere ( conditionFullName , {
keyword : ` % ${ requestBody . keyword } % ` ,
2024-08-14 10:35:48 +07:00
} )
2024-06-13 11:48:15 +07:00
} ) ,
)
. orderBy ( "kpiUserEvaluation.createdAt" , "ASC" )
. skip ( ( requestBody . page - 1 ) * requestBody . pageSize )
. take ( requestBody . pageSize )
. getManyAndCount ( ) ;
2024-07-15 11:41:20 +07:00
const mapData = kpiUserEvaluation . map ( ( item ) = > {
const fullNameParts = [ item . child4 , item . child3 , item . child2 , item . child1 , item . org ] ;
const organization = fullNameParts
. filter ( ( part ) = > part !== undefined && part !== null )
. join ( "/" ) ;
return {
id : item.id ,
profileId : item.profileId ,
prefix : item.prefix ,
firstname : item.firstName ,
lastname : item.lastName ,
kpiPeriodId : item.kpiPeriodId ,
evaluationStatus : item.evaluationStatus ,
evaluationResults : item.evaluationResults ,
createdAt : item.createdAt ,
evaluatorId : item.evaluatorId ,
commanderId : item.commanderId ,
commanderHighId : item.commanderHighId ,
2024-07-16 12:52:50 +07:00
root : item.org ? item.org : null ,
rootId : item.orgId ? item.orgId : null ,
position : item.position ? item.position : null ,
2024-07-15 11:41:20 +07:00
// posTypeId: item.posTypeId,
2024-07-16 12:52:50 +07:00
posTypeName : item.posTypeName ? item.posTypeName : null ,
2024-07-15 11:41:20 +07:00
// posLevelId: item.posLevelId,
2024-07-16 12:52:50 +07:00
posLevelName : item.posLevelName ? item.posLevelName : null ,
organization : organization ? organization : null ,
2024-07-15 11:41:20 +07:00
} ;
} ) ;
2024-04-26 10:18:00 +07:00
return new HttpSuccess ( { data : mapData , total } ) ;
}
2024-04-22 13:23:31 +07:00
/ * *
* API ส ร ้ า ง ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
2024-04-22 13:23:31 +07:00
* @summary ส ร ้ า ง ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
*
2024-04-22 13:23:31 +07:00
* /
@Post ( )
async CreateKpiUserEvaluation (
@Body ( ) requestBody : createKpiUserEvaluation ,
2024-08-09 16:28:52 +07:00
@Request ( ) request : RequestWithUser ,
2024-04-26 10:18:00 +07:00
) {
2024-08-09 16:28:52 +07:00
await new permission ( ) . PermissionCreate ( request , "SYS_KPI_LIST" ) ;
2024-04-22 13:23:31 +07:00
const kpiPeriod = await this . kpiPeriodRepository . findOne ( {
where : { id : requestBody.kpiPeriodId } ,
} ) ;
if ( ! kpiPeriod ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้" ,
) ;
}
2024-08-15 22:15:15 +07:00
let isProbation = false ;
2024-04-22 13:23:31 +07:00
const kpiUserEvaluation = Object . assign ( new KpiUserEvaluation ( ) , requestBody ) ;
2024-06-27 17:16:23 +07:00
if ( requestBody . profileId != undefined && requestBody . profileId != null ) {
2024-06-07 10:24:56 +07:00
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/profileid/position/" + requestBody . profileId )
2024-06-07 10:24:56 +07:00
. then ( ( x ) = > {
kpiUserEvaluation . profileId = x . profileId ;
kpiUserEvaluation . prefix = x . prefix ;
kpiUserEvaluation . firstName = x . firstName ;
kpiUserEvaluation . lastName = x . lastName ;
kpiUserEvaluation . position = x . position ;
kpiUserEvaluation . posLevelName = x . posLevelName ;
kpiUserEvaluation . posTypeName = x . posTypeName ;
kpiUserEvaluation . posExecutiveName = x . posExecutiveName ;
2024-06-28 15:03:02 +07:00
kpiUserEvaluation . org = x . root ;
2024-07-09 09:44:25 +07:00
kpiUserEvaluation . orgId = x . rootId ;
kpiUserEvaluation . child1 = x . child1 ;
kpiUserEvaluation . child1Id = x . child1Id ;
kpiUserEvaluation . child2 = x . child2 ;
kpiUserEvaluation . child2Id = x . child2Id ;
kpiUserEvaluation . child3 = x . child3 ;
kpiUserEvaluation . child3Id = x . child3Id ;
kpiUserEvaluation . child4 = x . child4 ;
kpiUserEvaluation . child4Id = x . child4Id ;
2024-08-15 22:15:15 +07:00
isProbation = x . isProbation ;
2024-06-07 10:24:56 +07:00
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
} else {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-06-07 10:24:56 +07:00
. then ( ( x ) = > {
kpiUserEvaluation . profileId = x . profileId ;
kpiUserEvaluation . prefix = x . prefix ;
kpiUserEvaluation . firstName = x . firstName ;
kpiUserEvaluation . lastName = x . lastName ;
kpiUserEvaluation . position = x . position ;
kpiUserEvaluation . posLevelName = x . posLevelName ;
kpiUserEvaluation . posTypeName = x . posTypeName ;
kpiUserEvaluation . posExecutiveName = x . posExecutiveName ;
2024-06-28 15:03:02 +07:00
kpiUserEvaluation . org = x . root ;
2024-07-09 09:44:25 +07:00
kpiUserEvaluation . orgId = x . rootId ;
kpiUserEvaluation . child1 = x . child1 ;
kpiUserEvaluation . child1Id = x . child1Id ;
kpiUserEvaluation . child2 = x . child2 ;
kpiUserEvaluation . child2Id = x . child2Id ;
kpiUserEvaluation . child3 = x . child3 ;
kpiUserEvaluation . child3Id = x . child3Id ;
kpiUserEvaluation . child4 = x . child4 ;
kpiUserEvaluation . child4Id = x . child4Id ;
2024-08-15 22:15:15 +07:00
isProbation = x . isProbation ;
2024-06-07 10:24:56 +07:00
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
}
2024-06-28 15:03:02 +07:00
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/profileid/position/" + requestBody . evaluatorId )
2024-06-28 15:03:02 +07:00
. then ( ( x ) = > {
kpiUserEvaluation . prefixEvaluator = x . prefix ;
kpiUserEvaluation . firstNameEvaluator = x . firstName ;
kpiUserEvaluation . lastNameEvaluator = x . lastName ;
kpiUserEvaluation . positionEvaluator = x . position ;
kpiUserEvaluation . posLevelNameEvaluator = x . posLevelName ;
kpiUserEvaluation . posTypeNameEvaluator = x . posTypeName ;
kpiUserEvaluation . orgEvaluator = x . root ;
} ) ;
2024-05-08 14:03:13 +07:00
kpiUserEvaluation . evaluationStatus = "NEW" ;
2024-04-26 10:18:00 +07:00
kpiUserEvaluation . evaluationResults = "PENDING" ;
kpiUserEvaluation . createdUserId = request . user . sub ;
kpiUserEvaluation . createdFullName = request . user . name ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
2024-06-19 16:40:44 +07:00
2024-06-19 17:34:31 +07:00
enum CapacityType {
HEAD = "HEAD" ,
GROUP = "GROUP" ,
}
2024-06-19 16:40:44 +07:00
2024-06-19 17:34:31 +07:00
// MAIN CAPACITY
const mainCapacities = await this . kpiCapacityRepository . find ( {
where : { type : CapacityType . HEAD } ,
} ) ;
2024-06-19 16:40:44 +07:00
2024-06-19 18:06:13 +07:00
let level : any = null ;
if ( kpiUserEvaluation . posTypeName == "บริหาร" && kpiUserEvaluation . posLevelName == "สูง" )
level = "5" ;
if ( kpiUserEvaluation . posTypeName == "บริหาร" && kpiUserEvaluation . posLevelName == "ต้น" )
level = "4" ;
if ( kpiUserEvaluation . posTypeName == "อำนวยการ" && kpiUserEvaluation . posLevelName == "สูง" )
level = "4" ;
if ( kpiUserEvaluation . posTypeName == "อำนวยการ" && kpiUserEvaluation . posLevelName == "ต้น" )
level = "3" ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ทรงคุณวุฒิ"
)
level = "5" ;
if ( kpiUserEvaluation . posTypeName == "วิชาการ" && kpiUserEvaluation . posLevelName == "เชี่ยวชาญ" )
level = "4" ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ชำนาญการพิเศษ"
)
level = "3" ;
if ( kpiUserEvaluation . posTypeName == "วิชาการ" && kpiUserEvaluation . posLevelName == "ชำนาญการ" )
level = "2" ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ปฏิบัติการ"
)
level = "1" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ทักษะพิเศษ" )
level = "4" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "อาวุโส" )
level = "3" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ชำนาญงาน" )
level = "2" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ปฏิบัติงาน" )
level = "1" ;
2024-06-19 17:34:31 +07:00
for ( const capacity of mainCapacities ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/kpi/user/capacity" , {
2024-06-19 17:34:31 +07:00
kpiUserEvaluationId : kpiUserEvaluation.id ,
kpiCapacityId : capacity.id ,
level : level ,
weight : 100 ,
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , x ) ;
} ) ;
}
2024-06-19 16:40:44 +07:00
2024-06-19 17:34:31 +07:00
// GROUP CAPACITY
const findPosition = await this . kpiPositionRepository . findOne ( {
2024-06-28 14:02:41 +07:00
where : { name : kpiUserEvaluation.position , kpiLinkId : Not ( IsNull ( ) ) } ,
2024-06-19 17:34:31 +07:00
} ) ;
2024-06-19 16:40:44 +07:00
2024-06-19 18:06:13 +07:00
let levelForGourp : any = null ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ทรงคุณวุฒิ"
)
levelForGourp = "5" ;
if ( kpiUserEvaluation . posTypeName == "วิชาการ" && kpiUserEvaluation . posLevelName == "เชี่ยวชาญ" )
levelForGourp = "4" ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ชำนาญการพิเศษ"
)
levelForGourp = "4" ;
if ( kpiUserEvaluation . posTypeName == "วิชาการ" && kpiUserEvaluation . posLevelName == "ชำนาญการ" )
levelForGourp = "3" ;
if (
kpiUserEvaluation . posTypeName == "วิชาการ" &&
kpiUserEvaluation . posLevelName == "ปฏิบัติการ"
)
levelForGourp = "2" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ทักษะพิเศษ" )
levelForGourp = "4" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "อาวุโส" )
levelForGourp = "3" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ชำนาญงาน" )
levelForGourp = "2" ;
if ( kpiUserEvaluation . posTypeName == "ทั่วไป" && kpiUserEvaluation . posLevelName == "ปฏิบัติงาน" )
levelForGourp = "1" ;
2024-06-26 23:27:33 +07:00
kpiUserEvaluation . weightPoint1 = 80 ;
kpiUserEvaluation . weightPoint2 = 20 ;
kpiUserEvaluation . summaryWeight = 100 ;
2024-06-19 18:06:13 +07:00
if ( findPosition && findPosition . kpiLinkId && levelForGourp != null ) {
2024-06-26 23:27:33 +07:00
kpiUserEvaluation . weightPoint1 = 70 ;
kpiUserEvaluation . weightPoint2 = 30 ;
2024-06-19 17:34:31 +07:00
const findKpiLink = await this . kpiLinkRepository . findOne ( {
2024-06-19 18:06:13 +07:00
relations : [ "kpiCapacitys" ] ,
2024-06-19 17:34:31 +07:00
where : {
id : findPosition.kpiLinkId ,
} ,
} ) ;
if ( findKpiLink ) {
let groupCapacity = findKpiLink . kpiCapacitys ;
for ( const capacity of groupCapacity ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/kpi/user/capacity" , {
2024-06-19 17:34:31 +07:00
kpiUserEvaluationId : kpiUserEvaluation.id ,
kpiCapacityId : capacity.id ,
level : levelForGourp ,
weight : 100 ,
} )
. catch ( ( error ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่สามารถสร้างข้อมูลสมรรถนะได้" ) ;
} ) ;
}
}
}
2024-08-15 22:15:15 +07:00
if ( isProbation != false ) {
kpiUserEvaluation . weightPoint1 = 50 ;
kpiUserEvaluation . weightPoint2 = 50 ;
}
2024-06-27 16:58:59 +07:00
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
2024-06-19 16:40:44 +07:00
2024-04-26 10:18:00 +07:00
return new HttpSuccess ( kpiUserEvaluation . id ) ;
2024-04-22 13:23:31 +07:00
}
2024-04-26 13:08:23 +07:00
/ * *
* API แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "check/{id}" )
async updateKpiUserCheckEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserCheckEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
Object . assign ( kpiUserEvaluation , requestBody ) ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
2024-04-26 17:39:24 +07:00
/ * *
* API แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "point/{id}" )
async updateKpiUserPointEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserPointEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
2024-06-26 23:27:33 +07:00
if ( requestBody . summaryPoint != null ) {
if ( requestBody . summaryPoint >= 90 ) {
kpiUserEvaluation . evaluationResults = "EXCELLENT" ;
} else if ( requestBody . summaryPoint >= 80 ) {
kpiUserEvaluation . evaluationResults = "VERY_GOOD" ;
} else if ( requestBody . summaryPoint >= 70 ) {
kpiUserEvaluation . evaluationResults = "GOOD" ;
} else if ( requestBody . summaryPoint >= 60 ) {
kpiUserEvaluation . evaluationResults = "FAIR" ;
} else {
kpiUserEvaluation . evaluationResults = "IMPROVEMENT" ;
}
} else {
kpiUserEvaluation . evaluationResults = "IMPROVEMENT" ;
}
2024-04-26 17:39:24 +07:00
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
Object . assign ( kpiUserEvaluation , requestBody ) ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
2024-04-22 13:23:31 +07:00
/ * *
* API แ ก ้ ไ ข ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
2024-04-22 13:23:31 +07:00
* @summary แ ก ้ ไ ข ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
2024-04-22 13:23:31 +07:00
* @param { string } id Guid , * Id ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
* /
@Put ( "{id}" )
async updateKpiUserEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
2024-04-26 13:08:23 +07:00
if ( ! kpiUserEvaluation ) {
2024-04-22 13:23:31 +07:00
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
const kpiPeriod = await this . kpiPeriodRepository . findOne ( {
where : { id : requestBody.kpiPeriodId } ,
} ) ;
if ( ! kpiPeriod ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้" ,
) ;
}
2024-04-26 13:08:23 +07:00
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
2024-05-15 20:17:34 +07:00
Object . assign ( kpiUserEvaluation , requestBody ) ;
2024-04-26 13:08:23 +07:00
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
2024-04-22 13:23:31 +07:00
}
2024-05-09 12:05:55 +07:00
/ * *
* API แ ก ้ ไ ข ส ถ า น ะ ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "edit/{id}" )
async updateKpiUserReqEditEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserReqEditEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
kpiUserEvaluation . evaluationReqEdit = requestBody . status . trim ( ) . toUpperCase ( ) ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
2024-05-09 18:07:15 +07:00
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
/ * *
* API แ ก ้ ไ ข ส ถ า น ะ ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "result/{id}" )
async updateKpiUserResultEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserResultEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
kpiUserEvaluation . evaluationResults = requestBody . status . trim ( ) . toUpperCase ( ) ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
2024-05-09 12:05:55 +07:00
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
/ * *
* API แ ก ้ ไ ข ส ถ า น ะ ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ค น ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "status/{id}" )
async updateKpiUserStatusEvaluation (
@Path ( ) id : string ,
@Body ( ) requestBody : updateKpiUserStatusEvaluation ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
2024-07-09 17:03:35 +07:00
if ( requestBody . status . trim ( ) . toUpperCase ( ) == "NEW_EVALUATOR" ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/profile" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ส่งข้อตกลงการประเมินผลการปฏิบัติราชการระดับบุคคลให้อนุมัติ ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ส่งข้อตกลงการประเมินผลการปฏิบัติราชการระดับบุคคลให้อนุมัติ ` ,
receiverUserId : kpiUserEvaluation.evaluatorId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
} else if ( requestBody . status . trim ( ) . toUpperCase ( ) == "EVALUATING_EVALUATOR" ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/profile" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } สรุปการประเมินผลการปฏิบัติราชการระดับบุคคล ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } สรุปการประเมินผลการปฏิบัติราชการระดับบุคคล ` ,
receiverUserId : kpiUserEvaluation.evaluatorId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
}
2024-05-09 12:05:55 +07:00
kpiUserEvaluation . evaluationStatus = requestBody . status . trim ( ) . toUpperCase ( ) ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
2024-04-22 13:23:31 +07:00
/ * *
* API ร า ย ล ะ เ อ ี ย ด ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
*
* @summary ร า ย ล ะ เ อ ี ย ด ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
*
* @param { string } id Guid , * Id ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
* /
@Get ( "{id}" )
async GetKpiUserEvaluationById ( @Path ( ) id : string ) {
2024-04-26 13:08:23 +07:00
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
2024-05-09 11:25:08 +07:00
relations : [ "kpiPeriod" ] ,
2024-04-22 13:23:31 +07:00
where : { id : id } ,
2024-04-26 10:18:00 +07:00
} ) ;
2024-04-26 13:08:23 +07:00
if ( ! kpiUserEvaluation ) {
2024-04-22 13:23:31 +07:00
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
2024-05-09 10:59:49 +07:00
const mapData = {
id : kpiUserEvaluation.id ,
profileId : kpiUserEvaluation.profileId ,
prefix : kpiUserEvaluation.prefix ,
firstName : kpiUserEvaluation.firstName ,
lastName : kpiUserEvaluation.lastName ,
2024-05-15 20:17:34 +07:00
position : kpiUserEvaluation.position ,
posLevelName : kpiUserEvaluation.posLevelName ,
posTypeName : kpiUserEvaluation.posTypeName ,
posExecutiveName : kpiUserEvaluation.posExecutiveName ,
2024-05-09 10:59:49 +07:00
evaluationStatus : kpiUserEvaluation.evaluationStatus ,
evaluationResults : kpiUserEvaluation.evaluationResults ,
2024-05-09 11:25:08 +07:00
evaluationReqEdit : kpiUserEvaluation.evaluationReqEdit ,
2024-05-09 10:59:49 +07:00
createdAt : kpiUserEvaluation.createdAt ,
evaluatorId : kpiUserEvaluation.evaluatorId ,
commanderId : kpiUserEvaluation.commanderId ,
commanderHighId : kpiUserEvaluation.commanderHighId ,
2024-06-26 23:27:33 +07:00
// plannedPoint: kpiUserEvaluation.plannedPoint,
// rolePoint: kpiUserEvaluation.rolePoint,
// specialPoint: kpiUserEvaluation.specialPoint,
// capacityPoint: kpiUserEvaluation.capacityPoint,
2024-05-09 10:59:49 +07:00
kpiPeriodId : kpiUserEvaluation.kpiPeriodId ,
2024-06-26 23:27:33 +07:00
totalPoint1 : kpiUserEvaluation.totalPoint1 ,
totalPoint2_1 : kpiUserEvaluation.totalPoint2_1 ,
totalPoint2_2 : kpiUserEvaluation.totalPoint2_2 ,
summaryPoint : kpiUserEvaluation.summaryPoint ,
2024-06-27 09:37:43 +07:00
isOpen : kpiUserEvaluation.isOpen ,
2024-06-28 15:03:02 +07:00
openDate : kpiUserEvaluation.openDate ,
2024-05-09 10:59:49 +07:00
year : kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation . kpiPeriod . year ,
2024-05-09 11:25:08 +07:00
durationKPI :
kpiUserEvaluation . kpiPeriod == null ? null : kpiUserEvaluation . kpiPeriod . durationKPI ,
} ;
2024-05-09 10:59:49 +07:00
return new HttpSuccess ( mapData ) ;
2024-04-22 13:23:31 +07:00
}
/ * *
* API ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
*
* @summary ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
*
* /
@Get ( )
async listKpiUserEvaluation (
2024-05-08 16:17:07 +07:00
@Request ( ) request : { user : Record < string , any > } ,
2024-04-22 13:23:31 +07:00
@Query ( "page" ) page : number = 1 ,
@Query ( "pageSize" ) pageSize : number = 10 ,
2024-04-22 15:24:44 +07:00
@Query ( "kpiPeriodId" ) kpiPeriodId? : string ,
2024-05-08 16:17:07 +07:00
@Query ( "keyword" ) keyword? : string ,
@Query ( "status" ) status? : string ,
2024-04-22 13:23:31 +07:00
) {
2024-07-02 14:11:29 +07:00
let profileId : any = null ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-07-02 14:11:29 +07:00
. then ( ( x ) = > {
profileId = x . profileId ;
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
2024-04-22 13:23:31 +07:00
const [ kpiUserEvaluation , total ] = await AppDataSource . getRepository ( KpiUserEvaluation )
. createQueryBuilder ( "kpiUserEvaluation" )
2024-05-09 11:25:08 +07:00
. leftJoinAndSelect ( "kpiUserEvaluation.kpiPeriod" , "kpiPeriod" )
2024-04-26 10:18:00 +07:00
. andWhere ( kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1" , {
2024-04-26 12:40:43 +07:00
kpiPeriodId : kpiPeriodId ,
2024-04-26 10:18:00 +07:00
} )
2024-07-02 14:11:29 +07:00
// .andWhere({ createdUserId: request.user.sub })
2024-07-03 00:36:45 +07:00
. andWhere ( { profileId : profileId } )
2024-05-08 16:17:07 +07:00
. andWhere (
status == null || status == undefined ? "1=1" : "evaluationStatus LIKE :evaluationStatus" ,
{
evaluationStatus : status == undefined ? "" : status . trim ( ) . toUpperCase ( ) ,
} ,
)
2024-04-22 13:23:31 +07:00
. orderBy ( "kpiUserEvaluation.createdAt" , "ASC" )
. skip ( ( page - 1 ) * pageSize )
. take ( pageSize )
. getManyAndCount ( ) ;
const mapData = kpiUserEvaluation . map ( ( item ) = > ( {
id : item.id ,
profileId : item.profileId ,
prefix : item.prefix ,
firstname : item.firstName ,
lastname : item.lastName ,
kpiPeriodId : item.kpiPeriodId ,
2024-04-22 15:24:44 +07:00
evaluationStatus : item.evaluationStatus ,
evaluationResults : item.evaluationResults ,
2024-04-26 13:17:25 +07:00
evaluatorId : item.evaluatorId ,
commanderId : item.commanderId ,
commanderHighId : item.commanderHighId ,
2024-04-22 15:24:44 +07:00
createdAt : item.createdAt ,
2024-04-26 17:39:24 +07:00
plannedPoint : item.plannedPoint ,
rolePoint : item.rolePoint ,
specialPoint : item.specialPoint ,
capacityPoint : item.capacityPoint ,
2024-05-09 10:59:49 +07:00
year : item.kpiPeriod ? item.kpiPeriod.year : null ,
durationKPI : item.kpiPeriod ? item.kpiPeriod.durationKPI : null ,
2024-04-22 13:23:31 +07:00
} ) ) ;
return new HttpSuccess ( { data : mapData , total } ) ;
}
/ * *
* API ล บ ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
2024-04-22 13:23:31 +07:00
* @summary ล บ ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
2024-04-26 10:18:00 +07:00
*
2024-04-22 13:23:31 +07:00
* @param { string } id Guid , * Id ร า ย ก า ร ป ร ะ เ ม ิ น ผ ล ก า ร ป ฏ ิ บ ั ต ิ ร า ช ก า ร ร ะ ด ั บ บ ุ ค ค ล ( USER )
* /
@Delete ( "{id}" )
async deleteKpiUserEvaluation ( @Path ( ) id : string ) {
2024-04-26 13:08:23 +07:00
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
2024-04-22 13:23:31 +07:00
where : { id : id } ,
} ) ;
2024-04-26 13:08:23 +07:00
if ( ! kpiUserEvaluation ) {
2024-04-22 13:23:31 +07:00
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
2024-04-26 13:08:23 +07:00
await this . kpiUserEvalutionRepository . remove ( kpiUserEvaluation ) ;
2024-04-22 13:23:31 +07:00
return new HttpSuccess ( ) ;
}
2024-05-13 11:13:02 +07:00
/ * *
* API แ ก ้ ส ถ า น ะ แ บ บ ป ร ะ เ ม ิ น ต า ม ร า ย ก า ร ท ี ่ เ ล ื อ ก
*
* @summary แ ก ้ ส ถ า น ะ แ บ บ ป ร ะ เ ม ิ น ต า ม ร า ย ก า ร ท ี ่ เ ล ื อ ก
*
*
* /
@Post ( "admin/change-status" )
async ChangeStatus (
@Request ( ) request : { user : Record < string , any > } ,
@Body ( )
requestBody : {
status : string ;
id : string [ ] ;
} ,
) {
2024-05-13 16:19:46 +07:00
let profileId : any = null ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-05-13 16:19:46 +07:00
. then ( ( x ) = > {
profileId = x . profileId ;
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
2024-05-13 11:13:02 +07:00
const list = await this . kpiUserEvalutionRepository . find ( {
where : { id : In ( requestBody . id ) } ,
} ) ;
if ( ! list || list . length === 0 ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูล" ) ;
}
const hasAllData = requestBody . id . every ( ( id ) = > list . some ( ( item ) = > item . id === id ) ) ;
if ( ! hasAllData ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล" ) ;
}
2024-08-16 10:11:36 +07:00
await Promise . all (
list . map ( async ( item ) = > {
let role = "EVALUATOR" ;
if ( profileId == item . commanderId ) {
role = "COMMANDER" ;
} else if ( profileId == item . commanderHighId ) {
role = "COMMANDERHIGH" ;
}
if ( requestBody . status . trim ( ) . toUpperCase ( ) == "APPROVE" ) {
if ( role == "EVALUATOR" ) {
if ( item . evaluationStatus == "NEW_EVALUATOR" ) {
if ( item . commanderId == null || item . commanderId == "" ) {
item . evaluationStatus = "APPROVE" ;
} else {
await new CallAPI ( )
. PostData ( request , "/placement/noti/profile" , {
subject : ` ${ item . prefix } ${ item . firstName } ${ item . lastName } ผู้ประเมินอนุมัติข้อตกลง ` ,
body : ` ${ item . prefix } ${ item . firstName } ${ item . lastName } ผู้ประเมินอนุมัติข้อตกลง ` ,
receiverUserId : item.commanderId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
item . evaluationStatus = "NEW_COMMANDER" ;
}
2024-05-13 16:19:46 +07:00
}
2024-08-16 10:11:36 +07:00
} else if ( role == "COMMANDER" ) {
if ( item . evaluationStatus == "NEW_COMMANDER" ) {
if ( item . commanderHighId == null || item . commanderHighId == "" ) {
item . evaluationStatus = "APPROVE" ;
} else {
await new CallAPI ( )
. PostData ( request , "/placement/noti/profile" , {
subject : ` ${ item . prefix } ${ item . firstName } ${ item . lastName } ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง ` ,
body : ` ${ item . prefix } ${ item . firstName } ${ item . lastName } ผู้บังคับบัญชาเหนือขึ้นไปอนุมัติข้อตกลง ` ,
receiverUserId : item.commanderHighId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
item . evaluationStatus = "NEW_COMMANDER_HIGH" ;
}
2024-05-13 16:19:46 +07:00
}
2024-08-16 10:11:36 +07:00
} else {
item . evaluationStatus = requestBody . status . trim ( ) . toUpperCase ( ) ;
2024-05-13 16:19:46 +07:00
}
} else {
item . evaluationStatus = requestBody . status . trim ( ) . toUpperCase ( ) ;
}
2024-08-16 10:11:36 +07:00
item . lastUpdateUserId = request . user . sub ;
item . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( item ) ;
} ) ,
) ;
2024-05-13 11:13:02 +07:00
return new HttpSuccess ( ) ;
}
/ * *
* API อ น ุ ม ั ต ิ ก า ร ข อ แ ก ้ ไ ข แ บ บ ป ร ะ เ ม ิ น ต า ม ร า ย ก า ร ท ี ่ เ ล ื อ ก
*
* @summary อ น ุ ม ั ต ิ ก า ร ข อ แ ก ้ ไ ข แ บ บ ป ร ะ เ ม ิ น ต า ม ร า ย ก า ร ท ี ่ เ ล ื อ ก
*
*
* /
@Post ( "admin/req-edit" )
async RequestEdit (
@Request ( ) request : { user : Record < string , any > } ,
@Body ( )
requestBody : {
status : string ;
id : string [ ] ;
} ,
) {
2024-05-13 16:19:46 +07:00
let profileId : any = null ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-05-13 16:19:46 +07:00
. then ( ( x ) = > {
profileId = x . profileId ;
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
2024-05-13 11:13:02 +07:00
const list = await this . kpiUserEvalutionRepository . find ( {
where : { id : In ( requestBody . id ) } ,
} ) ;
if ( ! list || list . length === 0 ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูล" ) ;
}
const hasAllData = requestBody . id . every ( ( id ) = > list . some ( ( item ) = > item . id === id ) ) ;
if ( ! hasAllData ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล" ) ;
}
2024-05-13 16:19:46 +07:00
2024-05-13 11:13:02 +07:00
list . forEach ( async ( item ) = > {
2024-05-13 16:19:46 +07:00
let role = "EVALUATOR" ;
if ( profileId == item . commanderId ) {
role = "COMMANDER" ;
} else if ( profileId == item . commanderHighId ) {
role = "COMMANDERHIGH" ;
}
if ( requestBody . status . trim ( ) . toUpperCase ( ) == "DONE" ) {
if ( role == "EVALUATOR" ) {
if ( item . evaluationReqEdit == "EVALUATOR" ) {
2024-05-14 09:39:27 +07:00
if ( item . commanderId == null || item . commanderId == "" ) {
2024-05-13 16:19:46 +07:00
item . evaluationReqEdit = "DONE" ;
2024-05-16 14:22:03 +07:00
item . evaluationStatus = "NEW" ;
2024-05-13 16:19:46 +07:00
} else {
item . evaluationReqEdit = "COMMANDER" ;
}
}
} else if ( role == "COMMANDER" ) {
if ( item . evaluationReqEdit == "COMMANDER" ) {
2024-05-14 09:39:27 +07:00
if ( item . commanderHighId == null || item . commanderHighId == "" ) {
2024-05-13 16:19:46 +07:00
item . evaluationReqEdit = "DONE" ;
2024-05-16 14:22:03 +07:00
item . evaluationStatus = "NEW" ;
2024-05-13 16:19:46 +07:00
} else {
item . evaluationReqEdit = "COMMANDER_HIGH" ;
}
}
} else {
item . evaluationReqEdit = requestBody . status . trim ( ) . toUpperCase ( ) ;
2024-05-16 14:22:03 +07:00
item . evaluationStatus = "NEW" ;
2024-05-13 16:19:46 +07:00
}
} else {
item . evaluationReqEdit = requestBody . status . trim ( ) . toUpperCase ( ) ;
}
2024-05-13 11:13:02 +07:00
item . lastUpdateUserId = request . user . sub ;
item . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( item ) ;
} ) ;
return new HttpSuccess ( ) ;
}
2024-05-13 11:37:18 +07:00
2024-05-13 16:19:46 +07:00
/ * *
2024-05-13 11:37:18 +07:00
* API แ ก ้ ไ ข ส ถ า น ะ ผ ล ก า ร ป ร ะ เ ม ิ น
*
* @summary แ ก ้ ไ ข ส ถ า น ะ ผ ล ก า ร ป ร ะ เ ม ิ น
*
*
* /
2024-05-13 16:19:46 +07:00
@Post ( "admin/result-status" )
async ResultStatus (
@Request ( ) request : { user : Record < string , any > } ,
@Body ( )
requestBody : {
status : string ;
id : string [ ] ;
} ,
) {
let profileId : any = null ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. GetData ( request , "/org/profile/keycloak/position" )
2024-05-13 16:19:46 +07:00
. then ( ( x ) = > {
profileId = x . profileId ;
} )
. catch ( ( x ) = > {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูลในทะเบียนประวัติ" ) ;
} ) ;
const list = await this . kpiUserEvalutionRepository . find ( {
where : { id : In ( requestBody . id ) } ,
} ) ;
if ( ! list || list . length === 0 ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "ไม่พบข้อมูล" ) ;
}
const hasAllData = requestBody . id . every ( ( id ) = > list . some ( ( item ) = > item . id === id ) ) ;
if ( ! hasAllData ) {
throw new HttpError ( HttpStatusCode . NOT_FOUND , "พบบางไอดีผู้ประเมินที่ไม่มีข้อมูล" ) ;
}
list . forEach ( async ( item ) = > {
let role = "EVALUATOR" ;
if ( profileId == item . commanderId ) {
role = "COMMANDER" ;
} else if ( profileId == item . commanderHighId ) {
role = "COMMANDERHIGH" ;
}
2024-05-15 09:31:02 +07:00
// if (requestBody.status.trim().toUpperCase() == "DONE") {
if ( role == "EVALUATOR" ) {
if ( item . evaluationStatus == "EVALUATING_EVALUATOR" ) {
if ( item . commanderId == null || item . commanderId == "" ) {
2024-06-26 23:27:33 +07:00
item . evaluationStatus = "SUMMARY" ;
2024-05-15 09:31:02 +07:00
} else {
item . evaluationStatus = "EVALUATING_COMMANDER" ;
2024-05-13 16:19:46 +07:00
}
2024-05-15 09:31:02 +07:00
item . evaluationResults = requestBody . status . trim ( ) . toUpperCase ( ) ;
}
} else if ( role == "COMMANDER" ) {
if ( item . evaluationStatus == "EVALUATING_COMMANDER" ) {
if ( item . commanderHighId == null || item . commanderHighId == "" ) {
2024-06-26 23:27:33 +07:00
item . evaluationStatus = "SUMMARY" ;
2024-05-15 09:31:02 +07:00
} else {
item . evaluationStatus = "EVALUATING_COMMANDER_HIGH" ;
2024-05-13 16:19:46 +07:00
}
}
} else {
2024-06-26 23:27:33 +07:00
item . evaluationStatus = "SUMMARY" ;
2024-05-13 16:19:46 +07:00
}
2024-05-15 09:31:02 +07:00
// } else {
// // item.evaluationStatus = requestBody.status.trim().toUpperCase();
// }
2024-05-13 16:19:46 +07:00
item . lastUpdateUserId = request . user . sub ;
item . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( item ) ;
} ) ;
return new HttpSuccess ( ) ;
}
2024-06-26 12:41:38 +07:00
/ * *
*
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Get ( "open/{id}" )
async openKpiUserEvaluation (
@Path ( ) id : string ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
kpiUserEvaluation . isOpen = true ;
2024-06-28 15:03:02 +07:00
kpiUserEvaluation . openDate = new Date ( ) ;
2024-06-26 12:41:38 +07:00
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
/ * *
* API แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @summary แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "reason/user/{id}" )
async updateReasonKpiUserEvaluation (
@Path ( ) id : string ,
@Body ( )
requestBody : {
topicEvaluator? : string | null ;
developEvaluator? : string | null ;
timeEvaluator? : string | null ;
reasonEvaluator? : string | null ;
} ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
const _null : any = null ;
2024-06-26 23:27:33 +07:00
if ( kpiUserEvaluation . commanderId == null ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/keycloak" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
receiverUserId : "aec26ac3-417c-4cf9-9cbe-874939f99ecc" ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
2024-06-26 23:27:33 +07:00
} )
2024-07-09 17:03:35 +07:00
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
kpiUserEvaluation . evaluationStatus = "COMPLETE" ;
2024-06-26 23:27:33 +07:00
} else {
2024-07-09 17:03:35 +07:00
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/profile" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
receiverUserId : kpiUserEvaluation.commanderId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
2024-06-26 23:27:33 +07:00
kpiUserEvaluation . evaluationStatus = "SUMMARY_COMMANDER" ;
}
2024-06-26 12:41:38 +07:00
kpiUserEvaluation . topicEvaluator =
requestBody . topicEvaluator == null ? _null : requestBody.topicEvaluator ;
kpiUserEvaluation . developEvaluator =
requestBody . developEvaluator == null ? _null : requestBody.developEvaluator ;
kpiUserEvaluation . timeEvaluator =
requestBody . timeEvaluator == null ? _null : requestBody.timeEvaluator ;
kpiUserEvaluation . reasonEvaluator =
requestBody . reasonEvaluator == null ? _null : requestBody.reasonEvaluator ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
/ * *
* API แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ผ ู ้ บ ั ง ค ั บ บ ั ญ ช า เ ห น ื อ ข ึ ้ น ไ ป ( USER )
*
* @summary แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ผ ู ้ บ ั ง ค ั บ บ ั ญ ช า เ ห น ื อ ข ึ ้ น ไ ป ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "reason/commander/{id}" )
async updateReasonKpiCommanderEvaluation (
@Path ( ) id : string ,
@Body ( )
requestBody : {
isReason : boolean ;
reason? : string | null ;
} ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
const _null : any = null ;
2024-06-26 23:27:33 +07:00
if ( kpiUserEvaluation . commanderHighId == null ) {
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/keycloak" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
receiverUserId : "aec26ac3-417c-4cf9-9cbe-874939f99ecc" ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
2024-06-26 23:27:33 +07:00
} )
2024-07-09 17:03:35 +07:00
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
kpiUserEvaluation . evaluationStatus = "COMPLETE" ;
2024-06-26 23:27:33 +07:00
} else {
2024-07-09 17:03:35 +07:00
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/profile" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
receiverUserId : kpiUserEvaluation.commanderHighId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
2024-06-26 23:27:33 +07:00
kpiUserEvaluation . evaluationStatus = "SUMMARY_COMMANDER_HIGH" ;
}
2024-06-26 12:41:38 +07:00
kpiUserEvaluation . isReasonCommander = requestBody . isReason ;
kpiUserEvaluation . reasonCommander = requestBody . reason == null ? _null : requestBody.reason ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
/ * *
* API แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ผ ู ้ บ ั ง ค ั บ บ ั ญ ช า เ ห น ื อ ข ึ ้ น ไ ป อ ี ก ห น ึ ่ ง ข ั ้ น ( USER )
*
* @summary แ ก ้ ไ ข ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ผ ู ้ บ ั ง ค ั บ บ ั ญ ช า เ ห น ื อ ข ึ ้ น ไ ป อ ี ก ห น ึ ่ ง ข ั ้ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Put ( "reason/commanderHigh/{id}" )
async updateReasonKpiCommanderHighEvaluation (
@Path ( ) id : string ,
@Body ( )
requestBody : {
isReason : boolean ;
reason? : string | null ;
} ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
const _null : any = null ;
2024-06-26 23:27:33 +07:00
kpiUserEvaluation . evaluationStatus = "COMPLETE" ;
await new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/keycloak" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ผู้ประเมินแสดงความเห็น ` ,
receiverUserId : "aec26ac3-417c-4cf9-9cbe-874939f99ecc" ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
2024-06-26 23:27:33 +07:00
} )
2024-07-09 17:03:35 +07:00
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
2024-06-26 12:41:38 +07:00
kpiUserEvaluation . isReasonCommanderHigh = requestBody . isReason ;
kpiUserEvaluation . reasonCommanderHigh = requestBody . reason == null ? _null : requestBody.reason ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation . id ) ;
}
2024-07-09 00:03:47 +07:00
/ * *
* API บ ั น ท ึ ก ข ้ อ ม ู ล ล ง kp7 ( USER )
*
* @summary บ ั น ท ึ ก ข ้ อ ม ู ล ล ง kp7 ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Post ( "done/kp7" )
async updateKpiEvaluationTokp7 (
@Body ( )
requestBody : {
id : string [ ] ;
} ,
2024-08-09 16:28:52 +07:00
@Request ( ) request : RequestWithUser ,
2024-07-09 00:03:47 +07:00
) {
2024-08-09 16:28:52 +07:00
await new permission ( ) . PermissionCreate ( request , "SYS_RESULT" ) ;
2024-07-09 00:03:47 +07:00
const kpiUserEvaluations = await this . kpiUserEvalutionRepository . find ( {
where : { id : In ( requestBody . id ) } ,
} ) ;
2024-08-16 10:11:36 +07:00
await Promise . all (
2024-07-09 00:03:47 +07:00
kpiUserEvaluations . map ( async ( kpiUserEvaluation ) = > {
kpiUserEvaluation . evaluationStatus = "KP7" ;
2024-07-16 12:52:50 +07:00
new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/org/profile/assessments" , {
2024-07-09 00:03:47 +07:00
date : new Date ( ) ,
name : kpiUserEvaluation.evaluationResults ,
point1Total : kpiUserEvaluation.weightPoint1 ,
point1 : kpiUserEvaluation.totalPoint1 ,
point2Total : kpiUserEvaluation.weightPoint2 ,
point2 : kpiUserEvaluation.totalPoint2_1 + kpiUserEvaluation . totalPoint2_2 ,
pointSumTotal : kpiUserEvaluation.summaryWeight ,
pointSum : kpiUserEvaluation.summaryPoint ,
profileId : kpiUserEvaluation.profileId ,
} )
. then ( async ( x ) = > { } ) ;
2024-07-16 12:52:50 +07:00
new CallAPI ( )
2024-07-10 10:45:09 +07:00
. PostData ( request , "/placement/noti/profile" , {
2024-07-09 17:03:35 +07:00
subject : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ระดับผลการประเมินการปฏิบัติราชการระดับบุคคลของคุณอยู่ในเกณฑ์ ${ kpiUserEvaluation . summaryPoint } ` ,
body : ` ${ kpiUserEvaluation . prefix } ${ kpiUserEvaluation . firstName } ${ kpiUserEvaluation . lastName } ระดับผลการประเมินการปฏิบัติราชการระดับบุคคลของคุณอยู่ในเกณฑ์ ${ kpiUserEvaluation . summaryPoint } ` ,
receiverUserId : kpiUserEvaluation.profileId ,
payload : "" ,
isSendMail : true ,
isSendInbox : true ,
isSendNotification : true ,
} )
. then ( ( x ) = > { } )
. catch ( ( x ) = > { } ) ;
2024-07-09 00:03:47 +07:00
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
} ) ,
) ;
return new HttpSuccess ( ) ;
}
2024-06-26 12:41:38 +07:00
/ * *
* API ร า ย ล ะ เ อ ี ย ด ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @summary ร า ย ล ะ เ อ ี ย ด ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Get ( "reason/{id}" )
async getReasonKpiEvaluation (
@Path ( ) id : string ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
select : [
"topicEvaluator" ,
"developEvaluator" ,
"timeEvaluator" ,
"reasonEvaluator" ,
"isReasonCommander" ,
"reasonCommander" ,
"isReasonCommanderHigh" ,
"reasonCommanderHigh" ,
2024-06-26 23:27:33 +07:00
"plannedPoint" ,
"rolePoint" ,
"specialPoint" ,
"capacityPoint" ,
"totalPoint1" ,
"totalPoint2_1" ,
"totalPoint2_2" ,
"summaryPoint" ,
"weightPoint1" ,
"weightPoint2" ,
"summaryWeight" ,
"evaluationResults" ,
2024-06-26 12:41:38 +07:00
"isOpen" ,
] ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
return new HttpSuccess ( kpiUserEvaluation ) ;
}
/ * *
* API ร า ย ล ะ เ อ ี ย ด ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @summary ร า ย ล ะ เ อ ี ย ด ส ร ุ ป ผ ล ก า ร ป ร ะ เ ม ิ น ( USER )
*
* @param { string } id Guid , * Id ค น ป ร ะ เ ม ิ น ( USER )
* /
@Get ( "summary/{id}" )
async getSummaryKpiEvaluation (
@Path ( ) id : string ,
@Request ( ) request : { user : Record < string , any > } ,
) {
const kpiUserEvaluation = await this . kpiUserEvalutionRepository . findOne ( {
where : { id : id } ,
select : [ "id" , "evaluationStatus" , "lastUpdateUserId" , "lastUpdateFullName" ] ,
} ) ;
if ( ! kpiUserEvaluation ) {
throw new HttpError (
HttpStatusCode . NOT_FOUND ,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้" ,
) ;
}
kpiUserEvaluation . evaluationStatus = "SUMMARY" ;
kpiUserEvaluation . lastUpdateUserId = request . user . sub ;
kpiUserEvaluation . lastUpdateFullName = request . user . name ;
await this . kpiUserEvalutionRepository . save ( kpiUserEvaluation ) ;
return new HttpSuccess ( kpiUserEvaluation ) ;
}
2024-04-22 13:23:31 +07:00
}