API กลุ่มงาน แก้ไข
This commit is contained in:
parent
5f640f5a7e
commit
eaff0dac2c
4 changed files with 53 additions and 53 deletions
|
|
@ -19,7 +19,7 @@ import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
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")
|
@Route("api/v1/kpi/group")
|
||||||
@Tags("kpi")
|
@Tags("kpi")
|
||||||
@Security("bearerAuth")
|
@Security("bearerAuth")
|
||||||
|
|
@ -29,7 +29,7 @@ import { KpiGroup, creatGroupKpi, updateGroupKpi } from "../entities/kpiGrop";
|
||||||
)
|
)
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class kpiGroupController extends Controller {
|
export class kpiGroupController extends Controller {
|
||||||
private kpiRepository = AppDataSource.getRepository(KpiGroup);
|
private kpiGroupRepository = AppDataSource.getRepository(KpiGroup);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* API สร้างกลุ่มงาน
|
* API สร้างกลุ่มงาน
|
||||||
|
|
@ -41,17 +41,17 @@ export class kpiGroupController extends Controller {
|
||||||
@Example({
|
@Example({
|
||||||
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
||||||
})
|
})
|
||||||
async createKpi(
|
async createKpiGroup(
|
||||||
@Body() requestBody: creatGroupKpi,
|
@Body() requestBody: creatKpiGroup,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpi = Object.assign(new KpiGroup(), requestBody);
|
const kpi = Object.assign(new KpiGroup(), requestBody);
|
||||||
kpi.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase();
|
kpi.nameGroupKPI = requestBody.nameGroupKPI;
|
||||||
kpi.createdUserId = request.user.sub;
|
kpi.createdUserId = request.user.sub;
|
||||||
kpi.createdFullName = request.user.name;
|
kpi.createdFullName = request.user.name;
|
||||||
kpi.lastUpdateUserId = request.user.sub;
|
kpi.lastUpdateUserId = request.user.sub;
|
||||||
kpi.lastUpdateFullName = request.user.name;
|
kpi.lastUpdateFullName = request.user.name;
|
||||||
await this.kpiRepository.save(kpi);
|
await this.kpiGroupRepository.save(kpi);
|
||||||
return new HttpSuccess(kpi.id);
|
return new HttpSuccess(kpi.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,25 +60,25 @@ export class kpiGroupController extends Controller {
|
||||||
* @param id ไอดีของกลุ่มงาน
|
* @param id ไอดีของกลุ่มงาน
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async update_kpi(
|
async updateKpiGroup(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: updateGroupKpi,
|
@Body() requestBody: updateKpiGroup,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpi_update = await this.kpiRepository.findOne({
|
const kpiUpdate = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!kpi_update) {
|
if (!kpiUpdate) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBody.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase();
|
requestBody.nameGroupKPI = requestBody.nameGroupKPI.trim().toUpperCase();
|
||||||
this.kpiRepository.merge(kpi_update, requestBody);
|
this.kpiGroupRepository.merge(kpiUpdate, requestBody);
|
||||||
kpi_update.createdUserId = request.user.sub;
|
kpiUpdate.createdUserId = request.user.sub;
|
||||||
kpi_update.createdFullName = request.user.name;
|
kpiUpdate.createdFullName = request.user.name;
|
||||||
kpi_update.lastUpdateUserId = request.user.sub;
|
kpiUpdate.lastUpdateUserId = request.user.sub;
|
||||||
kpi_update.lastUpdateFullName = request.user.name;
|
kpiUpdate.lastUpdateFullName = request.user.name;
|
||||||
await this.kpiRepository.save(kpi_update);
|
await this.kpiGroupRepository.save(kpiUpdate);
|
||||||
return new HttpSuccess(id);
|
return new HttpSuccess(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -90,8 +90,8 @@ export class kpiGroupController extends Controller {
|
||||||
@Example({
|
@Example({
|
||||||
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
nameGroupKPI: "string", //ชื่อกลุ่มงาน
|
||||||
})
|
})
|
||||||
async CloseSalaryById(@Path() id: string) {
|
async KpiGroupById(@Path() id: string) {
|
||||||
const kpi = await this.kpiRepository.findOne({
|
const kpi = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
select: ["nameGroupKPI"],
|
select: ["nameGroupKPI"],
|
||||||
});
|
});
|
||||||
|
|
@ -106,15 +106,15 @@ export class kpiGroupController extends Controller {
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async delete_salary(@Path() id: string) {
|
async deleteKpiGroup(@Path() id: string) {
|
||||||
const chk_KpiGroup = await this.kpiRepository.findOne({
|
const chkKpiGroup = await this.kpiGroupRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!chk_KpiGroup) {
|
if (!chkKpiGroup) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกลุ่มงานนี้");
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.kpiRepository.remove(chk_KpiGroup);
|
await this.kpiGroupRepository.remove(chkKpiGroup);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -19,7 +19,7 @@ import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
import HttpError from "../interfaces/http-error";
|
import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
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")
|
@Route("api/v1/kpi/period")
|
||||||
@Tags("kpi")
|
@Tags("kpi")
|
||||||
|
|
@ -30,7 +30,7 @@ import { KpiPeriod, createKpi, updateKpi } from "../entities/kpi";
|
||||||
)
|
)
|
||||||
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
@SuccessResponse(HttpStatusCode.OK, "สำเร็จ")
|
||||||
export class kpiController extends Controller {
|
export class kpiController extends Controller {
|
||||||
private kpiRepository = AppDataSource.getRepository(KpiPeriod);
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
/**
|
/**
|
||||||
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
|
|
@ -43,7 +43,7 @@ export class kpiController extends Controller {
|
||||||
endDate: "datetime", //วันสิ้นสุด
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
})
|
})
|
||||||
async createKpi(
|
async createKpi(
|
||||||
@Body() requestBody: createKpi,
|
@Body() requestBody: createKpiPeriod,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpi = Object.assign(new KpiPeriod(), requestBody);
|
const kpi = Object.assign(new KpiPeriod(), requestBody);
|
||||||
|
|
@ -52,7 +52,7 @@ export class kpiController extends Controller {
|
||||||
kpi.createdFullName = request.user.name;
|
kpi.createdFullName = request.user.name;
|
||||||
kpi.lastUpdateUserId = request.user.sub;
|
kpi.lastUpdateUserId = request.user.sub;
|
||||||
kpi.lastUpdateFullName = request.user.name;
|
kpi.lastUpdateFullName = request.user.name;
|
||||||
await this.kpiRepository.save(kpi);
|
await this.kpiPeriodRepository.save(kpi);
|
||||||
return new HttpSuccess(kpi.id);
|
return new HttpSuccess(kpi.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -63,15 +63,15 @@ export class kpiController extends Controller {
|
||||||
* @param request
|
* @param request
|
||||||
*/
|
*/
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async update_kpi(
|
async updateKpiPeriod(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: updateKpi,
|
@Body() requestBody: updateKpiPeriod,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
const kpi_update = await this.kpiRepository.findOne({
|
const kpiUpdate = await this.kpiPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!kpi_update) {
|
if (!kpiUpdate) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
|
|
@ -79,12 +79,12 @@ export class kpiController extends Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||||
this.kpiRepository.merge(kpi_update, requestBody);
|
this.kpiPeriodRepository.merge(kpiUpdate, requestBody);
|
||||||
kpi_update.createdUserId = request.user.sub;
|
kpiUpdate.createdUserId = request.user.sub;
|
||||||
kpi_update.createdFullName = request.user.name;
|
kpiUpdate.createdFullName = request.user.name;
|
||||||
kpi_update.lastUpdateUserId = request.user.sub;
|
kpiUpdate.lastUpdateUserId = request.user.sub;
|
||||||
kpi_update.lastUpdateFullName = request.user.name;
|
kpiUpdate.lastUpdateFullName = request.user.name;
|
||||||
await this.kpiRepository.save(kpi_update);
|
await this.kpiPeriodRepository.save(kpiUpdate);
|
||||||
return new HttpSuccess(id);
|
return new HttpSuccess(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -98,8 +98,8 @@ export class kpiController extends Controller {
|
||||||
startDate: "datetime", //วันเริ่มต้น
|
startDate: "datetime", //วันเริ่มต้น
|
||||||
endDate: "datetime", //วันสิ้นสุด
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
})
|
})
|
||||||
async CloseSalaryById(@Path() id: string) {
|
async CloseKpiPeriodById(@Path() id: string) {
|
||||||
const kpi = await this.kpiRepository.findOne({
|
const kpi = await this.kpiPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!kpi) {
|
if (!kpi) {
|
||||||
|
|
@ -109,7 +109,7 @@ export class kpiController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
kpi.isActive = false;
|
kpi.isActive = false;
|
||||||
await this.kpiRepository.save(kpi);
|
await this.kpiPeriodRepository.save(kpi);
|
||||||
return new HttpSuccess(kpi);
|
return new HttpSuccess(kpi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -123,8 +123,8 @@ export class kpiController extends Controller {
|
||||||
startDate: "datetime", //วันเริ่มต้น
|
startDate: "datetime", //วันเริ่มต้น
|
||||||
endDate: "datetime", //วันสิ้นสุด
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
})
|
})
|
||||||
async OpenSalaryById(@Path() id: string) {
|
async OpenKpiPeriodById(@Path() id: string) {
|
||||||
const kpi = await this.kpiRepository.findOne({
|
const kpi = await this.kpiPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!kpi) {
|
if (!kpi) {
|
||||||
|
|
@ -134,7 +134,7 @@ export class kpiController extends Controller {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
kpi.isActive = true;
|
kpi.isActive = true;
|
||||||
await this.kpiRepository.save(kpi);
|
await this.kpiPeriodRepository.save(kpi);
|
||||||
return new HttpSuccess(kpi);
|
return new HttpSuccess(kpi);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -148,8 +148,8 @@ export class kpiController extends Controller {
|
||||||
startDate: "datetime", //วันเริ่มต้น
|
startDate: "datetime", //วันเริ่มต้น
|
||||||
endDate: "datetime", //วันสิ้นสุด
|
endDate: "datetime", //วันสิ้นสุด
|
||||||
})
|
})
|
||||||
async GetSalaryById(@Path() id: string) {
|
async GetKpiPeriodById(@Path() id: string) {
|
||||||
const kpi = await this.kpiRepository.findOne({
|
const kpi = await this.kpiPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
select: ["durationKPI", "startDate", "endDate", "isActive"],
|
select: ["durationKPI", "startDate", "endDate", "isActive"],
|
||||||
});
|
});
|
||||||
|
|
@ -175,7 +175,7 @@ export class kpiController extends Controller {
|
||||||
@Query("year") year?: string,
|
@Query("year") year?: string,
|
||||||
@Query("keyword") keyword?: string,
|
@Query("keyword") keyword?: string,
|
||||||
) {
|
) {
|
||||||
const [kpiPeriod, total] = await this.kpiRepository.findAndCount({
|
const [kpiPeriod, total] = await this.kpiPeriodRepository.findAndCount({
|
||||||
// where: {
|
// where: {
|
||||||
// name: Like(`%${keyword}%`),
|
// name: Like(`%${keyword}%`),
|
||||||
// },
|
// },
|
||||||
|
|
@ -190,18 +190,18 @@ export class kpiController extends Controller {
|
||||||
* @param id
|
* @param id
|
||||||
*/
|
*/
|
||||||
@Delete("{id}")
|
@Delete("{id}")
|
||||||
async delete_salary(@Path() id: string) {
|
async deleteKpiPerriod(@Path() id: string) {
|
||||||
const chk_KpiPeriod = await this.kpiRepository.findOne({
|
const chkKpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
});
|
});
|
||||||
if (!chk_KpiPeriod) {
|
if (!chkKpiPeriod) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.kpiRepository.remove(chk_KpiPeriod);
|
await this.kpiPeriodRepository.remove(chkKpiPeriod);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ export class KpiPeriod extends EntityBase {
|
||||||
})
|
})
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
}
|
}
|
||||||
export class createKpi {
|
export class createKpiPeriod {
|
||||||
@Column()
|
@Column()
|
||||||
durationKPI: string;
|
durationKPI: string;
|
||||||
@Column()
|
@Column()
|
||||||
|
|
@ -43,7 +43,7 @@ export class createKpi {
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class updateKpi {
|
export class updateKpiPeriod {
|
||||||
@Column()
|
@Column()
|
||||||
durationKPI: string;
|
durationKPI: string;
|
||||||
@Column()
|
@Column()
|
||||||
|
|
|
||||||
|
|
@ -10,12 +10,12 @@ export class KpiGroup extends EntityBase {
|
||||||
})
|
})
|
||||||
nameGroupKPI: string;
|
nameGroupKPI: string;
|
||||||
}
|
}
|
||||||
export class creatGroupKpi {
|
export class creatKpiGroup {
|
||||||
@Column()
|
@Column()
|
||||||
nameGroupKPI: string;
|
nameGroupKPI: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class updateGroupKpi {
|
export class updateKpiGroup {
|
||||||
@Column()
|
@Column()
|
||||||
nameGroupKPI: string;
|
nameGroupKPI: string;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue