diff --git a/src/controllers/KpiPeriodController.ts b/src/controllers/KpiPeriodController.ts index 58ebd8f..39423ed 100644 --- a/src/controllers/KpiPeriodController.ts +++ b/src/controllers/KpiPeriodController.ts @@ -59,10 +59,7 @@ export class kpiPeriodController extends Controller { startDate: "datetime", //วันเริ่มต้น endDate: "datetime", //วันสิ้นสุด }) - async createKpi( - @Body() requestBody: createKpiPeriod, - @Request() request: RequestWithUser, - ) { + async createKpi(@Body() requestBody: createKpiPeriod, @Request() request: RequestWithUser) { await new permission().PermissionCreate(request, "SYS_KPI_ROUND"); const chkkpiPeriod = await this.kpiPeriodRepository.findOne({ where: { @@ -176,6 +173,35 @@ export class kpiPeriodController extends Controller { return new HttpSuccess(kpiPeriod); } + /** + * API list รอบการประเมินผลการปฏิบัติหน้าที่ราชการ + * @param page + * @param pageSize + * @param keyword + */ + @Get("user") + async listKpiPeriodUser( + @Request() request: RequestWithUser, + @Query("page") page: number = 1, + @Query("pageSize") pageSize: number = 10, + @Query("year") year?: number, + @Query("keyword") keyword?: string, + ) { + const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod) + .createQueryBuilder("kpiPeriod") + .andWhere( + year !== 0 && year != null && year != undefined ? "kpiPeriod.year = :year" : "1=1", + { year: year }, + ) + .orderBy("kpiPeriod.startDate", "ASC") + .addOrderBy("kpiPeriod.year", "ASC") + .skip((page - 1) * pageSize) + .take(pageSize) + .getManyAndCount(); + + return new HttpSuccess({ data: kpiPeriod, total }); + } + /** * API รอบการประเมินผลการปฏิบัติหน้าที่ราชการ * @param id Guid, *Id รอบการประเมินผลการปฏิบัติหน้าที่ราชการ @@ -208,11 +234,13 @@ export class kpiPeriodController extends Controller { */ @Get() async listKpiPeriod( + @Request() request: RequestWithUser, @Query("page") page: number = 1, @Query("pageSize") pageSize: number = 10, @Query("year") year?: number, @Query("keyword") keyword?: string, ) { + await new permission().PermissionDelete(request, "SYS_KPI_ROUND"); const [kpiPeriod, total] = await AppDataSource.getRepository(KpiPeriod) .createQueryBuilder("kpiPeriod") .andWhere( @@ -220,7 +248,7 @@ export class kpiPeriodController extends Controller { { year: year }, ) .orderBy("kpiPeriod.startDate", "ASC") - .addOrderBy("kpiPeriod.year", "ASC") + .addOrderBy("kpiPeriod.year", "ASC") .skip((page - 1) * pageSize) .take(pageSize) .getManyAndCount(); diff --git a/src/controllers/KpiUserCapacityController.ts b/src/controllers/KpiUserCapacityController.ts index 2d38288..0e2764f 100644 --- a/src/controllers/KpiUserCapacityController.ts +++ b/src/controllers/KpiUserCapacityController.ts @@ -166,7 +166,8 @@ export class KpiUserCapacityController extends Controller { * @param {string} id Guid, *Id องค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER) */ @Get("{id}") - async GetKpiUserCapacityById(@Path() id: string) { + async GetKpiUserCapacityById(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({ where: { id: id }, relations: ["kpiCapacity"], @@ -197,9 +198,11 @@ export class KpiUserCapacityController extends Controller { */ @Get() async listKpiUserCapacity( + @Request() request: RequestWithUser, @Query("id") id: string, //kpiUserEvaluationId @Query("type") type: string, ) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const [kpiUserCapacity, total] = await AppDataSource.getRepository(KpiUserCapacity) .createQueryBuilder("kpiUserCapacity") .leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity") diff --git a/src/controllers/KpiUserDevelopmentController.ts b/src/controllers/KpiUserDevelopmentController.ts index 1e32ea0..a43a604 100644 --- a/src/controllers/KpiUserDevelopmentController.ts +++ b/src/controllers/KpiUserDevelopmentController.ts @@ -221,7 +221,8 @@ export class KpiUserDevelopmentController extends Controller { * @param {string} id Id พัฒนาตนเอง */ @Get("{id}") - async GetKpiUserDevelopmentDetail(@Path() id: string) { + async GetKpiUserDevelopmentDetail(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ relations: ["kpiUserEvaluation", "developmentProjects"], where: { id: id }, @@ -262,7 +263,8 @@ export class KpiUserDevelopmentController extends Controller { * */ @Get() - async GetKpiUserDevelopment(@Query("id") id: string) { + async GetKpiUserDevelopment(@Request() request: RequestWithUser, @Query("id") id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.find({ where: { kpiUserEvaluationId: id, @@ -424,7 +426,11 @@ export class KpiUserDevelopmentController extends Controller { * */ @Get("admin/detail/{id}") - async GetKpiDevelopmentStatusKP7ById(@Path("id") id: string) { + async GetKpiDevelopmentStatusKP7ById( + @Request() request: RequestWithUser, + @Path("id") id: string, + ) { + await new permission().PermissionGet(request, "SYS_RESULT"); const kpiUserDevelopment = await this.kpiUserDevelopmentRepository.findOne({ relations: [ "kpiUserEvaluation", diff --git a/src/controllers/KpiUserEvaluationController.ts b/src/controllers/KpiUserEvaluationController.ts index 44adf8e..5ed37ce 100644 --- a/src/controllers/KpiUserEvaluationController.ts +++ b/src/controllers/KpiUserEvaluationController.ts @@ -198,9 +198,9 @@ export class KpiUserEvaluationController extends Controller { * @summary รายการประเมินผลการปฏิบัติราชการระดับบุคคลทั้งหมด * */ - @Post("list") - async listKpiListEvaluation( - @Request() request: { user: Record }, + @Post("list-announce") + async listKpiListEvaluationAnnounce( + @Request() request: RequestWithUser, @Body() requestBody: { page: number; @@ -213,6 +213,124 @@ export class KpiUserEvaluationController extends Controller { evaluating?: boolean | null; }, ) { + await new permission().PermissionDelete(request, "SYS_RESULT"); + let conditionFullName = + "CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword"; + const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) + .createQueryBuilder("kpiUserEvaluation") + .andWhere(requestBody.kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { + kpiPeriodId: requestBody.kpiPeriodId, + }) + .andWhere( + requestBody.status != null && requestBody.status != undefined + ? "evaluationstatus LIKE :status" + : "1=1", + { + status: + requestBody.status == null || requestBody.status == undefined + ? null + : requestBody.status.trim().toUpperCase(), + }, + ) + .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}%`, + }) + .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}%`, + }) + .orWhere(conditionFullName, { + keyword: `%${requestBody.keyword}%`, + }); + }), + ) + .orderBy("kpiUserEvaluation.createdAt", "ASC") + .skip((requestBody.page - 1) * requestBody.pageSize) + .take(requestBody.pageSize) + .getManyAndCount(); + + 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, + root: item.org ? item.org : null, + rootId: item.orgId ? item.orgId : null, + position: item.position ? item.position : null, + // posTypeId: item.posTypeId, + posTypeName: item.posTypeName ? item.posTypeName : null, + // posLevelId: item.posLevelId, + posLevelName: item.posLevelName ? item.posLevelName : null, + organization: organization ? organization : null, + }; + }); + return new HttpSuccess({ data: mapData, total }); + } + + /** + * API + * + * @summary รายการประเมินผลการปฏิบัติราชการระดับบุคคลทั้งหมด + * + */ + @Post("list") + async listKpiListEvaluation( + @Request() request: RequestWithUser, + @Body() + requestBody: { + page: number; + pageSize: number; + kpiPeriodId?: string; + keyword?: string; + status?: string | null; + results?: string | null; + reqedit?: string | null; + evaluating?: boolean | null; + }, + ) { + await new permission().PermissionDelete(request, "SYS_KPI_LIST"); let conditionFullName = "CONCAT(kpiUserEvaluation.prefix, kpiUserEvaluation.firstName, ' ', kpiUserEvaluation.lastName) LIKE :keyword"; const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) @@ -1440,10 +1558,8 @@ export class KpiUserEvaluationController extends Controller { * @param {string} id Guid, *Id คนประเมิน (USER) */ @Get("reason/{id}") - async getReasonKpiEvaluation( - @Path() id: string, - @Request() request: { user: Record }, - ) { + async getReasonKpiEvaluation(@Path() id: string, @Request() request: RequestWithUser) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ where: { id: id }, select: [ diff --git a/src/controllers/KpiUserPlannedController.ts b/src/controllers/KpiUserPlannedController.ts index d868eb4..8249dc0 100644 --- a/src/controllers/KpiUserPlannedController.ts +++ b/src/controllers/KpiUserPlannedController.ts @@ -183,7 +183,8 @@ export class KpiUserPlannedController extends Controller { * @param {string} id Id งานตามแผนปฏิบัติราชการประจำปี */ @Get("{id}") - async GetKpiUserPlannedDetail(@Path() id: string) { + async GetKpiUserPlannedDetail(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ relations: ["kpiPlan", "kpiUserEvaluation"], where: { id: id }, @@ -225,7 +226,8 @@ export class KpiUserPlannedController extends Controller { * */ @Get() - async GetKpiUserPlanned(@Query("id") id: string) { + async GetKpiUserPlanned(@Request() request: RequestWithUser, @Query("id") id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserPlanned = await this.kpiUserPlannedRepository.find({ where: { kpiUserEvaluationId: id, diff --git a/src/controllers/KpiUserRoleController.ts b/src/controllers/KpiUserRoleController.ts index 6e6f79e..f0f7ebe 100644 --- a/src/controllers/KpiUserRoleController.ts +++ b/src/controllers/KpiUserRoleController.ts @@ -185,7 +185,8 @@ export class KpiUserRoleController extends Controller { * @param {string} id Id งานตามหน้าที่ความรับผิดชอบหลัก */ @Get("{id}") - async GetKpiUserRoleDetail(@Path() id: string) { + async GetKpiUserRoleDetail(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserRole = await this.kpiUserRoleRepository.findOne({ relations: ["kpiRole", "kpiUserEvaluation"], where: { id: id }, @@ -227,7 +228,8 @@ export class KpiUserRoleController extends Controller { * */ @Get() - async GetKpiUserRole(@Query("id") id: string) { + async GetKpiUserRole(@Request() request: RequestWithUser, @Query("id") id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserRole = await this.kpiUserRoleRepository.find({ where: { kpiUserEvaluationId: id, diff --git a/src/controllers/KpiUserSpecialController.ts b/src/controllers/KpiUserSpecialController.ts index d8f57b6..1345029 100644 --- a/src/controllers/KpiUserSpecialController.ts +++ b/src/controllers/KpiUserSpecialController.ts @@ -210,7 +210,8 @@ export class KpiUserSpecialController extends Controller { * @param {string} id Id งานที่ได้รับมอบหมายพิเศษ */ @Get("{id}") - async GetKpiUserSpecialDetail(@Path() id: string) { + async GetKpiUserSpecialDetail(@Request() request: RequestWithUser, @Path() id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const getKpiUserSpecial = await this.kpiUserSpecialRepository.findOne({ relations: ["kpiUserEvaluation"], where: { id: id }, @@ -263,7 +264,8 @@ export class KpiUserSpecialController extends Controller { * */ @Get() - async GetKpiUserSpecial(@Query("id") id: string) { + async GetKpiUserSpecial(@Request() request: RequestWithUser, @Query("id") id: string) { + await new permission().PermissionGet(request, "SYS_KPI_LIST"); const kpiUserSpecial = await this.kpiUserSpecialRepository.find({ where: { kpiUserEvaluationId: id,