API กลุ่มงาน แก้ไข

This commit is contained in:
AnandaTon 2024-04-17 18:15:24 +07:00
parent 5f640f5a7e
commit eaff0dac2c
4 changed files with 53 additions and 53 deletions

View file

@ -19,7 +19,7 @@ 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 { KpiGroup, creatGroupKpi, updateGroupKpi } from "../entities/kpiGrop";
import { KpiGroup, creatKpiGroup, updateKpiGroup } from "../entities/kpiGrop";
@Route("api/v1/kpi/group")
@Tags("kpi")
@Security("bearerAuth")
@ -29,7 +29,7 @@ import { KpiGroup, creatGroupKpi, updateGroupKpi } from "../entities/kpiGrop";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiGroupController extends Controller {
private kpiRepository = AppDataSource.getRepository(KpiGroup);
private kpiGroupRepository = AppDataSource.getRepository(KpiGroup);
/**
* API
@ -41,17 +41,17 @@ export class kpiGroupController extends Controller {
@Example({
nameGroupKPI: "string", //ชื่อกลุ่มงาน
})
async createKpi(
@Body() requestBody: creatGroupKpi,
async createKpiGroup(
@Body() requestBody: creatKpiGroup,
@Request() request: { user: Record<string, any> },
) {
const kpi = Object.assign(new KpiGroup(), requestBody);
kpi.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase();
kpi.nameGroupKPI = requestBody.nameGroupKPI;
kpi.createdUserId = request.user.sub;
kpi.createdFullName = request.user.name;
kpi.lastUpdateUserId = request.user.sub;
kpi.lastUpdateFullName = request.user.name;
await this.kpiRepository.save(kpi);
await this.kpiGroupRepository.save(kpi);
return new HttpSuccess(kpi.id);
}
@ -60,25 +60,25 @@ export class kpiGroupController extends Controller {
* @param id
*/
@Put("{id}")
async update_kpi(
async updateKpiGroup(
@Path() id: string,
@Body() requestBody: updateGroupKpi,
@Body() requestBody: updateKpiGroup,
@Request() request: { user: Record<string, any> },
) {
const kpi_update = await this.kpiRepository.findOne({
const kpiUpdate = await this.kpiGroupRepository.findOne({
where: { id: id },
});
if (!kpi_update) {
if (!kpiUpdate) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
}
requestBody.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase();
this.kpiRepository.merge(kpi_update, requestBody);
kpi_update.createdUserId = request.user.sub;
kpi_update.createdFullName = request.user.name;
kpi_update.lastUpdateUserId = request.user.sub;
kpi_update.lastUpdateFullName = request.user.name;
await this.kpiRepository.save(kpi_update);
this.kpiGroupRepository.merge(kpiUpdate, requestBody);
kpiUpdate.createdUserId = request.user.sub;
kpiUpdate.createdFullName = request.user.name;
kpiUpdate.lastUpdateUserId = request.user.sub;
kpiUpdate.lastUpdateFullName = request.user.name;
await this.kpiGroupRepository.save(kpiUpdate);
return new HttpSuccess(id);
}
@ -90,8 +90,8 @@ export class kpiGroupController extends Controller {
@Example({
nameGroupKPI: "string", //ชื่อกลุ่มงาน
})
async CloseSalaryById(@Path() id: string) {
const kpi = await this.kpiRepository.findOne({
async KpiGroupById(@Path() id: string) {
const kpi = await this.kpiGroupRepository.findOne({
where: { id: id },
select: ["nameGroupKPI"],
});
@ -106,15 +106,15 @@ export class kpiGroupController extends Controller {
* @param id
*/
@Delete("{id}")
async delete_salary(@Path() id: string) {
const chk_KpiGroup = await this.kpiRepository.findOne({
async deleteKpiGroup(@Path() id: string) {
const chkKpiGroup = await this.kpiGroupRepository.findOne({
where: { id: id },
});
if (!chk_KpiGroup) {
if (!chkKpiGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
}
await this.kpiRepository.remove(chk_KpiGroup);
await this.kpiGroupRepository.remove(chkKpiGroup);
return new HttpSuccess();
}
}

View file

@ -19,7 +19,7 @@ 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, createKpi, updateKpi } from "../entities/kpi";
import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpi";
@Route("api/v1/kpi/period")
@Tags("kpi")
@ -30,7 +30,7 @@ import { KpiPeriod, createKpi, updateKpi } from "../entities/kpi";
)
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
export class kpiController extends Controller {
private kpiRepository = AppDataSource.getRepository(KpiPeriod);
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
/**
*
* @param requestBody
@ -43,7 +43,7 @@ export class kpiController extends Controller {
endDate: "datetime", //วันสิ้นสุด
})
async createKpi(
@Body() requestBody: createKpi,
@Body() requestBody: createKpiPeriod,
@Request() request: { user: Record<string, any> },
) {
const kpi = Object.assign(new KpiPeriod(), requestBody);
@ -52,7 +52,7 @@ export class kpiController extends Controller {
kpi.createdFullName = request.user.name;
kpi.lastUpdateUserId = request.user.sub;
kpi.lastUpdateFullName = request.user.name;
await this.kpiRepository.save(kpi);
await this.kpiPeriodRepository.save(kpi);
return new HttpSuccess(kpi.id);
}
@ -63,15 +63,15 @@ export class kpiController extends Controller {
* @param request
*/
@Put("{id}")
async update_kpi(
async updateKpiPeriod(
@Path() id: string,
@Body() requestBody: updateKpi,
@Body() requestBody: updateKpiPeriod,
@Request() request: { user: Record<string, any> },
) {
const kpi_update = await this.kpiRepository.findOne({
const kpiUpdate = await this.kpiPeriodRepository.findOne({
where: { id: id },
});
if (!kpi_update) {
if (!kpiUpdate) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
@ -79,12 +79,12 @@ export class kpiController extends Controller {
}
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
this.kpiRepository.merge(kpi_update, requestBody);
kpi_update.createdUserId = request.user.sub;
kpi_update.createdFullName = request.user.name;
kpi_update.lastUpdateUserId = request.user.sub;
kpi_update.lastUpdateFullName = request.user.name;
await this.kpiRepository.save(kpi_update);
this.kpiPeriodRepository.merge(kpiUpdate, requestBody);
kpiUpdate.createdUserId = request.user.sub;
kpiUpdate.createdFullName = request.user.name;
kpiUpdate.lastUpdateUserId = request.user.sub;
kpiUpdate.lastUpdateFullName = request.user.name;
await this.kpiPeriodRepository.save(kpiUpdate);
return new HttpSuccess(id);
}
@ -98,8 +98,8 @@ export class kpiController extends Controller {
startDate: "datetime", //วันเริ่มต้น
endDate: "datetime", //วันสิ้นสุด
})
async CloseSalaryById(@Path() id: string) {
const kpi = await this.kpiRepository.findOne({
async CloseKpiPeriodById(@Path() id: string) {
const kpi = await this.kpiPeriodRepository.findOne({
where: { id: id },
});
if (!kpi) {
@ -109,7 +109,7 @@ export class kpiController extends Controller {
);
}
kpi.isActive = false;
await this.kpiRepository.save(kpi);
await this.kpiPeriodRepository.save(kpi);
return new HttpSuccess(kpi);
}
@ -123,8 +123,8 @@ export class kpiController extends Controller {
startDate: "datetime", //วันเริ่มต้น
endDate: "datetime", //วันสิ้นสุด
})
async OpenSalaryById(@Path() id: string) {
const kpi = await this.kpiRepository.findOne({
async OpenKpiPeriodById(@Path() id: string) {
const kpi = await this.kpiPeriodRepository.findOne({
where: { id: id },
});
if (!kpi) {
@ -134,7 +134,7 @@ export class kpiController extends Controller {
);
}
kpi.isActive = true;
await this.kpiRepository.save(kpi);
await this.kpiPeriodRepository.save(kpi);
return new HttpSuccess(kpi);
}
@ -148,8 +148,8 @@ export class kpiController extends Controller {
startDate: "datetime", //วันเริ่มต้น
endDate: "datetime", //วันสิ้นสุด
})
async GetSalaryById(@Path() id: string) {
const kpi = await this.kpiRepository.findOne({
async GetKpiPeriodById(@Path() id: string) {
const kpi = await this.kpiPeriodRepository.findOne({
where: { id: id },
select: ["durationKPI", "startDate", "endDate", "isActive"],
});
@ -175,7 +175,7 @@ export class kpiController extends Controller {
@Query("year") year?: string,
@Query("keyword") keyword?: string,
) {
const [kpiPeriod, total] = await this.kpiRepository.findAndCount({
const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
// where: {
// name: Like(`%${keyword}%`),
// },
@ -190,18 +190,18 @@ export class kpiController extends Controller {
* @param id
*/
@Delete("{id}")
async delete_salary(@Path() id: string) {
const chk_KpiPeriod = await this.kpiRepository.findOne({
async deleteKpiPerriod(@Path() id: string) {
const chkKpiPeriod = await this.kpiPeriodRepository.findOne({
where: { id: id },
});
if (!chk_KpiPeriod) {
if (!chkKpiPeriod) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
);
}
await this.kpiRepository.remove(chk_KpiPeriod);
await this.kpiPeriodRepository.remove(chkKpiPeriod);
return new HttpSuccess();
}
}

View file

@ -32,7 +32,7 @@ export class KpiPeriod extends EntityBase {
})
isActive: boolean;
}
export class createKpi {
export class createKpiPeriod {
@Column()
durationKPI: string;
@Column()
@ -43,7 +43,7 @@ export class createKpi {
isActive: boolean;
}
export class updateKpi {
export class updateKpiPeriod {
@Column()
durationKPI: string;
@Column()

View file

@ -10,12 +10,12 @@ export class KpiGroup extends EntityBase {
})
nameGroupKPI: string;
}
export class creatGroupKpi {
export class creatKpiGroup {
@Column()
nameGroupKPI: string;
}
export class updateGroupKpi {
export class updateKpiGroup {
@Column()
nameGroupKPI: string;
}