เพิ่มฟิวผู้บังคับ

This commit is contained in:
Kittapath 2024-04-26 13:08:23 +07:00
parent ba00645cb8
commit ecbb9c0d9f
7 changed files with 171 additions and 64 deletions

View file

@ -37,10 +37,10 @@ export class kpiEvaluationController extends Controller {
* @param id * @param id
*/ */
@Put() @Put()
async updateKpiEvaluations( async updateKpiEvaluations(
@Body() requestBody: updateKpiEvaluation[], @Body() requestBody: updateKpiEvaluation[],
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const updatedIds: string[] = []; const updatedIds: string[] = [];
for (const item of requestBody) { for (const item of requestBody) {
@ -60,8 +60,7 @@ async updateKpiEvaluations(
} }
return new HttpSuccess(); return new HttpSuccess();
} }
/** /**
* API list * API list
@ -81,20 +80,20 @@ async updateKpiEvaluations(
where: [{ description: Like(`%${keyword}%`) }], where: [{ description: Like(`%${keyword}%`) }],
}; };
whereClause.where.push({ level: Like(`%${keyword}%`) }); whereClause.where.push({ level: Like(`%${keyword}%`) });
} }
const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({ const [kpiEvaluation, total] = await this.kpiEvaluationRepository.findAndCount({
...whereClause, ...whereClause,
...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }), ...(keyword ? {} : { skip: (page - 1) * pageSize, take: pageSize }),
order:{ order: {
level: "DESC"} level: "DESC",
},
}); });
const formatted = kpiEvaluation.map((item) => ({ const formatted = kpiEvaluation.map((item) => ({
id: item.id, id: item.id,
level: item.level, level: item.level,
description: item.description description: item.description,
})); }));
return new HttpSuccess({ data: formatted, total }); return new HttpSuccess({ data: formatted, total });
} }

View file

@ -24,6 +24,7 @@ import { KpiPeriod } from "../entities/kpiPeriod";
import { import {
KpiUserEvaluation, KpiUserEvaluation,
createKpiUserEvaluation, createKpiUserEvaluation,
updateKpiUserCheckEvaluation,
updateKpiUserEvaluation, updateKpiUserEvaluation,
} from "../entities/kpiUserEvaluation"; } from "../entities/kpiUserEvaluation";
import { Like, In } from "typeorm"; import { Like, In } from "typeorm";
@ -120,6 +121,35 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess(kpiUserEvaluation.id); return new HttpSuccess(kpiUserEvaluation.id);
} }
/**
* 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);
}
/** /**
* API (USER) * API (USER)
* *
@ -136,7 +166,7 @@ export class KpiUserEvaluationController extends Controller {
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id }, where: { id: id },
}); });
if (!KpiUserEvaluation) { if (!kpiUserEvaluation) {
throw new HttpError( throw new HttpError(
HttpStatusCode.NOT_FOUND, HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
@ -153,7 +183,6 @@ export class KpiUserEvaluationController extends Controller {
); );
} }
if (kpiUserEvaluation) {
// kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus // kpiUserEvaluation.evaluationStatus = requestBody.evaluationStatus
// kpiUserEvaluation.evaluationResults = requestBody.evaluationResults // kpiUserEvaluation.evaluationResults = requestBody.evaluationResults
kpiUserEvaluation.lastUpdateUserId = request.user.sub; kpiUserEvaluation.lastUpdateUserId = request.user.sub;
@ -162,7 +191,6 @@ export class KpiUserEvaluationController extends Controller {
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id); return new HttpSuccess(kpiUserEvaluation.id);
} }
}
/** /**
* API (USER) * API (USER)
@ -173,7 +201,7 @@ export class KpiUserEvaluationController extends Controller {
*/ */
@Get("{id}") @Get("{id}")
async GetKpiUserEvaluationById(@Path() id: string) { async GetKpiUserEvaluationById(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id }, where: { id: id },
select: [ select: [
"id", "id",
@ -187,13 +215,13 @@ export class KpiUserEvaluationController extends Controller {
"createdAt", "createdAt",
], ],
}); });
if (!KpiUserEvaluation) { if (!kpiUserEvaluation) {
throw new HttpError( throw new HttpError(
HttpStatusCode.NOT_FOUND, HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", "ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
); );
} }
return new HttpSuccess(KpiUserEvaluation); return new HttpSuccess(kpiUserEvaluation);
} }
/** /**
@ -242,16 +270,16 @@ export class KpiUserEvaluationController extends Controller {
*/ */
@Delete("{id}") @Delete("{id}")
async deleteKpiUserEvaluation(@Path() id: string) { async deleteKpiUserEvaluation(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id }, where: { id: id },
}); });
if (!KpiUserEvaluation) { if (!kpiUserEvaluation) {
throw new HttpError( throw new HttpError(
HttpStatusCode.NOT_FOUND, HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้", "ไม่พบข้อมูลการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
); );
} }
await this.kpiUserEvalutionRepository.remove(KpiUserEvaluation); await this.kpiUserEvalutionRepository.remove(kpiUserEvaluation);
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -74,9 +74,12 @@ export class KpiUserPlannedController extends Controller {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiPlanId: requestBody.kpiPlanId, kpiPlanId: requestBody.kpiPlanId,
}, },
}) });
if (chk_indicator) { if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody); const kpiUserPlanned = Object.assign(new KpiUserPlanned(), requestBody);
@ -105,7 +108,6 @@ export class KpiUserPlannedController extends Controller {
@Body() requestBody: UpdateKpiUserPlanned, @Body() requestBody: UpdateKpiUserPlanned,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } }); const kpiUserPlanned = await this.kpiUserPlannedRepository.findOne({ where: { id } });
if (!kpiUserPlanned) { if (!kpiUserPlanned) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลงานตามแผนปฏิบัติราชการประจำปีนี้");
@ -117,9 +119,12 @@ export class KpiUserPlannedController extends Controller {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiPlanId: requestBody.kpiPlanId, kpiPlanId: requestBody.kpiPlanId,
}, },
}) });
if (chk_indicator) { if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
kpiUserPlanned.lastUpdateUserId = request.user.sub; kpiUserPlanned.lastUpdateUserId = request.user.sub;

View file

@ -82,9 +82,12 @@ export class KpiUserRoleController extends Controller {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiRoleId: requestBody.kpiRoleId, kpiRoleId: requestBody.kpiRoleId,
}, },
}) });
if (chk_indicator) { if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
kpiUserRole.createdUserId = request.user.sub; kpiUserRole.createdUserId = request.user.sub;
@ -135,9 +138,12 @@ export class KpiUserRoleController extends Controller {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
kpiRoleId: requestBody.kpiRoleId, kpiRoleId: requestBody.kpiRoleId,
}, },
}) });
if (chk_indicator) { if (chk_indicator) {
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
kpiUserRole.lastUpdateUserId = request.user.sub; kpiUserRole.lastUpdateUserId = request.user.sub;

View file

@ -63,17 +63,21 @@ export class KpiUserSpecialController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูล");
} }
const chk_indicator = await this.kpiUserSpecialRepository.findOne({ const chk_indicator = await this.kpiUserSpecialRepository.findOne({
where: { where: {
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
}, },
}) });
if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { if (
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); (chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
kpiUserSpecial.createdUserId = request.user.sub; kpiUserSpecial.createdUserId = request.user.sub;
kpiUserSpecial.createdFullName = request.user.name; kpiUserSpecial.createdFullName = request.user.name;
kpiUserSpecial.lastUpdateUserId = request.user.sub; kpiUserSpecial.lastUpdateUserId = request.user.sub;
@ -111,9 +115,15 @@ export class KpiUserSpecialController extends Controller {
id: Not(id), id: Not(id),
kpiUserEvaluationId: requestBody.kpiUserEvaluationId, kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
}, },
}) });
if (chk_indicator && chk_indicator.including == requestBody.including || chk_indicator && chk_indicator.includingName == requestBody.includingName) { if (
throw new HttpError(HttpStatusCode.CONFLICT, "ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ"); (chk_indicator && chk_indicator.including == requestBody.including) ||
(chk_indicator && chk_indicator.includingName == requestBody.includingName)
) {
throw new HttpError(
HttpStatusCode.CONFLICT,
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากข้อมูลตัวชี้วัดซ้ำ",
);
} }
kpiUserSpecial.lastUpdateUserId = request.user.sub; kpiUserSpecial.lastUpdateUserId = request.user.sub;

View file

@ -47,11 +47,36 @@ export class KpiUserEvaluation extends EntityBase {
}) })
profileId: string; profileId: string;
@Column({
nullable: true,
length: 40,
comment: "ไอดีผู้ประเมิน",
default: null,
})
evaluatorId: string;
@Column({
nullable: true,
length: 40,
comment: "ไอดีผู้บังคับบัญชาเหนือขึ้นไป",
default: null,
})
commanderId: string;
@Column({
nullable: true,
length: 40,
comment: "ไอดีผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง",
default: null,
})
commanderHighId: string;
@Column({ @Column({
// "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", // "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น",
nullable: true, nullable: true,
length: 40, length: 40,
comment: "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น", comment:
"สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น",
default: null, default: null,
}) })
evaluationStatus: string; evaluationStatus: string;
@ -60,7 +85,8 @@ export class KpiUserEvaluation extends EntityBase {
// "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", // "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน",
nullable: true, nullable: true,
length: 40, length: 40,
comment: "ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน", comment:
"ผลการประเมิน ดังนี้ PENDING = รอดำเนินการ, PASSED = ผ่านการประเมิน, NOTPASSED = ไม่ผ่านการประเมิน",
default: null, default: null,
}) })
evaluationResults: string; evaluationResults: string;
@ -93,6 +119,12 @@ export class createKpiUserEvaluation {
kpiPeriodId: string; kpiPeriodId: string;
@Column() @Column()
profileId: string; profileId: string;
@Column()
evaluatorId: string | null;
@Column()
commanderId: string | null;
@Column()
commanderHighId: string | null;
} }
export class updateKpiUserEvaluation { export class updateKpiUserEvaluation {
@ -107,3 +139,12 @@ export class updateKpiUserEvaluation {
@Column() @Column()
profileId: string; profileId: string;
} }
export class updateKpiUserCheckEvaluation {
@Column()
evaluatorId: string | null;
@Column()
commanderId: string | null;
@Column()
commanderHighId: string | null;
}

View file

@ -0,0 +1,18 @@
import { MigrationInterface, QueryRunner } from "typeorm";
export class UpdateTableKpiUserEvalutionAddEvaluatorId1714111345274 implements MigrationInterface {
name = 'UpdateTableKpiUserEvalutionAddEvaluatorId1714111345274'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`evaluatorId\` varchar(40) NULL COMMENT 'ไอดีผู้ประเมิน'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderId\` varchar(40) NULL COMMENT 'ไอดีผู้บังคับบัญชาเหนือขึ้นไป'`);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`commanderHighId\` varchar(40) NULL COMMENT 'ไอดีผู้บังคับบัญชาเหนือขึ้นไปอีกชั้นหนึ่ง'`);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderHighId\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`commanderId\``);
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`evaluatorId\``);
}
}