add reject
This commit is contained in:
parent
9646659f4c
commit
6f1b3f9216
5 changed files with 262 additions and 7 deletions
|
|
@ -38,6 +38,8 @@ import { KpiLink } from "../entities/kpiLink";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { KpiUserRejectAgreement } from "../entities/kpiUserRejectAgreement";
|
||||
import { KpiUserRejectResult } from "../entities/kpiUserRejectResult";
|
||||
|
||||
@Route("api/v1/kpi/user/evaluation")
|
||||
@Tags("kpiUserEvaluation")
|
||||
|
|
@ -53,6 +55,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity);
|
||||
private kpiPositionRepository = AppDataSource.getRepository(Position);
|
||||
private kpiLinkRepository = AppDataSource.getRepository(KpiLink);
|
||||
private kpiUserRejectAgreementRepository = AppDataSource.getRepository(KpiUserRejectAgreement);
|
||||
private kpiUserRejectResultRepository = AppDataSource.getRepository(KpiUserRejectResult);
|
||||
|
||||
/**
|
||||
* API
|
||||
|
|
@ -195,6 +199,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
evaluatorId: item.evaluatorId,
|
||||
commanderId: item.commanderId,
|
||||
commanderHighId: item.commanderHighId,
|
||||
reasonReject: item.reasonReject,
|
||||
isReject: item.reasonReject ? true : false,
|
||||
}));
|
||||
return new HttpSuccess({ data: mapData, total });
|
||||
}
|
||||
|
|
@ -1004,6 +1010,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
let _null: any = null;
|
||||
kpiUserEvaluation.reasonReject = _null;
|
||||
} else if (requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR") {
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profile", {
|
||||
|
|
@ -1019,6 +1027,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
.catch(() => {});
|
||||
}
|
||||
const before = structuredClone(kpiUserEvaluation);
|
||||
let _null: any = null;
|
||||
kpiUserEvaluation.reasonReject = _null;
|
||||
kpiUserEvaluation.evaluationStatus = requestBody.status.trim().toUpperCase();
|
||||
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
|
||||
kpiUserEvaluation.lastUpdateFullName = request.user.name;
|
||||
|
|
@ -1028,6 +1038,118 @@ export class KpiUserEvaluationController extends Controller {
|
|||
return new HttpSuccess(kpiUserEvaluation.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขสถานะประเมิน (USER)
|
||||
*
|
||||
* @summary แก้ไขคนประเมิน (USER)
|
||||
*
|
||||
* @param {string} id Guid, *Id คนประเมิน (USER)
|
||||
*/
|
||||
@Put("reject-agreement/{id}")
|
||||
async updateKpiUserStatusRejectAgreementEvaluation(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: { reason: string },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiUserEvaluation) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
||||
);
|
||||
}
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profile", {
|
||||
subject: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
|
||||
body: `${kpiUserEvaluation.prefix}${kpiUserEvaluation.firstName} ${kpiUserEvaluation.lastName} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
|
||||
receiverUserId: kpiUserEvaluation.profileId,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.then(async () => {})
|
||||
.catch((error) => {
|
||||
console.error("Error details:", error.response.data);
|
||||
});
|
||||
const before = structuredClone(kpiUserEvaluation);
|
||||
kpiUserEvaluation.evaluationStatus = "NEW";
|
||||
kpiUserEvaluation.reasonReject = requestBody.reason;
|
||||
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
|
||||
kpiUserEvaluation.lastUpdateFullName = request.user.name;
|
||||
kpiUserEvaluation.lastUpdatedAt = new Date();
|
||||
let kpiReject = {
|
||||
reason: requestBody.reason,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
|
||||
await this.kpiUserRejectAgreementRepository.save(kpiReject);
|
||||
setLogDataDiff(request, { before, after: kpiUserEvaluation });
|
||||
return new HttpSuccess(kpiUserEvaluation.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไขสถานะประเมิน (USER)
|
||||
*
|
||||
* @summary แก้ไขคนประเมิน (USER)
|
||||
*
|
||||
* @param {string} id Guid, *Id คนประเมิน (USER)
|
||||
*/
|
||||
@Put("reject-result/{id}")
|
||||
async updateKpiUserStatusRejectResultEvaluation(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: { reason: string },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!kpiUserEvaluation) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการประเมินผลการปฏิบัติราชการระดับบุคคลนี้",
|
||||
);
|
||||
}
|
||||
await new CallAPI()
|
||||
.PostData(request, "/placement/noti/profile", {
|
||||
subject: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
|
||||
body: `${kpiUserEvaluation.prefixEvaluator}${kpiUserEvaluation.firstNameEvaluator} ${kpiUserEvaluation.lastNameEvaluator} ไม่อนุมัติเนื่องจาก: ${requestBody.reason}`,
|
||||
receiverUserId: kpiUserEvaluation.evaluatorId,
|
||||
payload: "",
|
||||
isSendMail: true,
|
||||
isSendInbox: true,
|
||||
isSendNotification: true,
|
||||
})
|
||||
.then(() => {})
|
||||
.catch(() => {});
|
||||
const before = structuredClone(kpiUserEvaluation);
|
||||
kpiUserEvaluation.evaluationStatus = "EVALUATING_EVALUATOR";
|
||||
kpiUserEvaluation.reasonReject = requestBody.reason;
|
||||
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
|
||||
kpiUserEvaluation.lastUpdateFullName = request.user.name;
|
||||
kpiUserEvaluation.lastUpdatedAt = new Date();
|
||||
let kpiReject = {
|
||||
reason: requestBody.reason,
|
||||
createdUserId: request.user.sub,
|
||||
createdFullName: request.user.name,
|
||||
lastUpdateUserId: request.user.sub,
|
||||
lastUpdateFullName: request.user.name,
|
||||
createdAt: new Date(),
|
||||
lastUpdatedAt: new Date(),
|
||||
};
|
||||
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
|
||||
await this.kpiUserRejectResultRepository.save(kpiReject);
|
||||
setLogDataDiff(request, { before, after: kpiUserEvaluation });
|
||||
return new HttpSuccess(kpiUserEvaluation.id);
|
||||
}
|
||||
|
||||
/**
|
||||
* API รายละเอียดรายการประเมินผลการปฏิบัติราชการระดับบุคคล (USER)
|
||||
*
|
||||
|
|
@ -1081,6 +1203,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
child2: kpiUserEvaluation.child2,
|
||||
child3: kpiUserEvaluation.child3,
|
||||
child4: kpiUserEvaluation.child4,
|
||||
reasonReject: kpiUserEvaluation.reasonReject,
|
||||
isReject: kpiUserEvaluation.reasonReject ? true : false,
|
||||
year: kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.year,
|
||||
durationKPI:
|
||||
kpiUserEvaluation.kpiPeriod == null ? null : kpiUserEvaluation.kpiPeriod.durationKPI,
|
||||
|
|
@ -1159,6 +1283,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
rolePoint: item.rolePoint,
|
||||
specialPoint: item.specialPoint,
|
||||
capacityPoint: item.capacityPoint,
|
||||
reasonReject: item.reasonReject,
|
||||
isReject: item.reasonReject ? true : false,
|
||||
year: item.kpiPeriod ? item.kpiPeriod.year : null,
|
||||
durationKPI: item.kpiPeriod ? item.kpiPeriod.durationKPI : null,
|
||||
}));
|
||||
|
|
@ -1281,6 +1407,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
item.evaluationStatus = requestBody.status.trim().toUpperCase();
|
||||
}
|
||||
const before = null;
|
||||
let _null: any = null;
|
||||
item.reasonReject = _null;
|
||||
item.lastUpdateUserId = request.user.sub;
|
||||
item.lastUpdateFullName = request.user.name;
|
||||
item.lastUpdatedAt = new Date();
|
||||
|
|
@ -1446,6 +1574,8 @@ export class KpiUserEvaluationController extends Controller {
|
|||
// // item.evaluationStatus = requestBody.status.trim().toUpperCase();
|
||||
// }
|
||||
const before = null;
|
||||
let _null: any = null;
|
||||
item.reasonReject = _null;
|
||||
item.lastUpdateUserId = request.user.sub;
|
||||
item.lastUpdateFullName = request.user.name;
|
||||
item.lastUpdatedAt = new Date();
|
||||
|
|
@ -1915,24 +2045,24 @@ export class KpiUserEvaluationController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* API รายการผลการประเมินภายใน 5 ปี
|
||||
* API รายการผลการประเมินภายใน 5 ปี
|
||||
*
|
||||
* @summary รายการผลการประเมินภายใน 5 ปี
|
||||
* @summary รายการผลการประเมินภายใน 5 ปี
|
||||
*
|
||||
* @param {string} id Guid, *Id คนประเมิน
|
||||
* @param {string} id Guid, *Id คนประเมิน
|
||||
*/
|
||||
@Get("summaryFiveYear/{id}")
|
||||
async getsummaryFiveYear(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const year = new Date().getFullYear();
|
||||
const kpiUserEvaluation = await this.kpiUserEvalutionRepository.find({
|
||||
relations: ["kpiPeriod"],
|
||||
where: {
|
||||
profileId: id ,
|
||||
where: {
|
||||
profileId: id,
|
||||
evaluationResults: Not("PENDING"),
|
||||
evaluationStatus: "KP7",
|
||||
kpiPeriod: {
|
||||
year: MoreThanOrEqual(year - 5),
|
||||
}
|
||||
year: MoreThanOrEqual(year - 5),
|
||||
},
|
||||
},
|
||||
select: ["id", "evaluationStatus", "evaluationResults", "kpiPeriod"],
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import { KpiUserRole } from "./kpiUserRole";
|
|||
import { KpiUserPlanned } from "./kpiUserPlanned";
|
||||
import { KpiUserCapacity } from "./kpiUserCapacity";
|
||||
import { KpiUserDevelopment } from "./kpiUserDevelopment";
|
||||
import { KpiUserRejectAgreement } from "./kpiUserRejectAgreement";
|
||||
import { KpiUserRejectResult } from "./kpiUserRejectResult";
|
||||
@Entity("kpiUserEvaluation")
|
||||
export class KpiUserEvaluation extends EntityBase {
|
||||
@Column({
|
||||
|
|
@ -296,6 +298,14 @@ export class KpiUserEvaluation extends EntityBase {
|
|||
})
|
||||
commanderHighId: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "หมายเหตุไม่อนุมัติ",
|
||||
length: 255,
|
||||
default: null,
|
||||
})
|
||||
reasonReject: string;
|
||||
|
||||
@Column({
|
||||
// "สถานะการประเมินผล ดังนี้ PENDING = รอดำเนินการ, INPROGRESS = กําลังดำเนินการ, DONE = ประเมินเสร็จสิ้น",
|
||||
nullable: true,
|
||||
|
|
@ -522,6 +532,18 @@ export class KpiUserEvaluation extends EntityBase {
|
|||
|
||||
@OneToMany(() => KpiUserDevelopment, (kpiUserDevelopment) => kpiUserDevelopment.kpiUserEvaluation)
|
||||
kpiUserDevelopments: KpiUserDevelopment[];
|
||||
|
||||
@OneToMany(
|
||||
() => KpiUserRejectAgreement,
|
||||
(kpiUserRejectAgreement) => kpiUserRejectAgreement.kpiUserEvaluation,
|
||||
)
|
||||
kpiUserRejectAgreements: KpiUserRejectAgreement[];
|
||||
|
||||
@OneToMany(
|
||||
() => KpiUserRejectResult,
|
||||
(kpiUserRejectResult) => kpiUserRejectResult.kpiUserEvaluation,
|
||||
)
|
||||
kpiUserRejectResults: KpiUserRejectResult[];
|
||||
}
|
||||
|
||||
export class createKpiUserEvaluation {
|
||||
|
|
|
|||
42
src/entities/kpiUserRejectAgreement.ts
Normal file
42
src/entities/kpiUserRejectAgreement.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { KpiUserEvaluation } from "./kpiUserEvaluation";
|
||||
|
||||
@Entity("kpiUserRejectAgreement")
|
||||
export class KpiUserRejectAgreement extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "หมายเหตุ",
|
||||
default: null,
|
||||
})
|
||||
reason: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง kpiUserEvaluation",
|
||||
default: null,
|
||||
})
|
||||
kpiUserEvaluationId: string;
|
||||
|
||||
@ManyToOne(
|
||||
() => KpiUserEvaluation,
|
||||
(kpiUserEvaluation) => kpiUserEvaluation.kpiUserRejectAgreements,
|
||||
)
|
||||
@JoinColumn({ name: "kpiUserEvaluationId" })
|
||||
kpiUserEvaluation: KpiUserEvaluation;
|
||||
}
|
||||
|
||||
export class CreateKpiUserRejectAgreement {
|
||||
@Column()
|
||||
fullname: string | null;
|
||||
@Column()
|
||||
resaon: string | null;
|
||||
}
|
||||
|
||||
export class UpdateKpiUserRejectAgreement {
|
||||
@Column()
|
||||
fullname: string | null;
|
||||
@Column()
|
||||
resaon: string | null;
|
||||
}
|
||||
39
src/entities/kpiUserRejectResult.ts
Normal file
39
src/entities/kpiUserRejectResult.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { Entity, Column, ManyToOne, JoinColumn } from "typeorm";
|
||||
import { EntityBase } from "./base/Base";
|
||||
import { KpiUserEvaluation } from "./kpiUserEvaluation";
|
||||
|
||||
@Entity("kpiUserRejectResult")
|
||||
export class KpiUserRejectResult extends EntityBase {
|
||||
@Column({
|
||||
nullable: true,
|
||||
comment: "หมายเหตุ",
|
||||
default: null,
|
||||
})
|
||||
reason: string;
|
||||
|
||||
@Column({
|
||||
nullable: true,
|
||||
length: 40,
|
||||
comment: "คีย์นอก(FK)ของตาราง kpiUserEvaluation",
|
||||
default: null,
|
||||
})
|
||||
kpiUserEvaluationId: string;
|
||||
|
||||
@ManyToOne(() => KpiUserEvaluation, (kpiUserEvaluation) => kpiUserEvaluation.kpiUserRejectResults)
|
||||
@JoinColumn({ name: "kpiUserEvaluationId" })
|
||||
kpiUserEvaluation: KpiUserEvaluation;
|
||||
}
|
||||
|
||||
export class CreateKpiUserRejectAgreement {
|
||||
@Column()
|
||||
fullname: string | null;
|
||||
@Column()
|
||||
resaon: string | null;
|
||||
}
|
||||
|
||||
export class UpdateKpiUserRejectAgreement {
|
||||
@Column()
|
||||
fullname: string | null;
|
||||
@Column()
|
||||
resaon: string | null;
|
||||
}
|
||||
22
src/migration/1738120767835-Updateevaaddreject.ts
Normal file
22
src/migration/1738120767835-Updateevaaddreject.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
|
||||
export class Updateevaaddreject1738120767835 implements MigrationInterface {
|
||||
name = 'Updateevaaddreject1738120767835'
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`CREATE TABLE \`kpiUserRejectAgreement\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`kpiUserEvaluationId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserEvaluation', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`CREATE TABLE \`kpiUserRejectResult\` (\`id\` varchar(36) NOT NULL, \`createdAt\` datetime(6) NOT NULL COMMENT 'สร้างข้อมูลเมื่อ' DEFAULT CURRENT_TIMESTAMP(6), \`createdUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่สร้างข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`lastUpdatedAt\` datetime(6) NOT NULL COMMENT 'แก้ไขข้อมูลล่าสุดเมื่อ' DEFAULT CURRENT_TIMESTAMP(6) ON UPDATE CURRENT_TIMESTAMP(6), \`lastUpdateUserId\` varchar(40) NOT NULL COMMENT 'User Id ที่แก้ไขข้อมูล' DEFAULT '00000000-0000-0000-0000-000000000000', \`createdFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่สร้างข้อมูล' DEFAULT 'string', \`lastUpdateFullName\` varchar(200) NOT NULL COMMENT 'ชื่อ User ที่แก้ไขข้อมูลล่าสุด' DEFAULT 'string', \`reason\` varchar(255) NULL COMMENT 'หมายเหตุ', \`kpiUserEvaluationId\` varchar(40) NULL COMMENT 'คีย์นอก(FK)ของตาราง kpiUserEvaluation', PRIMARY KEY (\`id\`)) ENGINE=InnoDB`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` ADD \`reasonReject\` varchar(255) NULL COMMENT 'หมายเหตุไม่อนุมัติ'`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserRejectAgreement\` ADD CONSTRAINT \`FK_37bc083922722e568b9ad8bb8b2\` FOREIGN KEY (\`kpiUserEvaluationId\`) REFERENCES \`kpiUserEvaluation\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserRejectResult\` ADD CONSTRAINT \`FK_78d9327de17d5f1f36a4b2c927c\` FOREIGN KEY (\`kpiUserEvaluationId\`) REFERENCES \`kpiUserEvaluation\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserRejectResult\` DROP FOREIGN KEY \`FK_78d9327de17d5f1f36a4b2c927c\``);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserRejectAgreement\` DROP FOREIGN KEY \`FK_37bc083922722e568b9ad8bb8b2\``);
|
||||
await queryRunner.query(`ALTER TABLE \`kpiUserEvaluation\` DROP COLUMN \`reasonReject\``);
|
||||
await queryRunner.query(`DROP TABLE \`kpiUserRejectResult\``);
|
||||
await queryRunner.query(`DROP TABLE \`kpiUserRejectAgreement\``);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue