no message
This commit is contained in:
parent
dfd9ebb3c1
commit
483ad486dc
9 changed files with 943 additions and 41 deletions
|
|
@ -172,9 +172,9 @@ export class kpiLinkController extends Controller {
|
|||
* API เชื่อมโยง
|
||||
* @param id
|
||||
*/
|
||||
@Get("{id}")
|
||||
async KpiLinkById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
let _data = await new permission().PermissionList(request, "SYS_EVA_COMPETENCY");
|
||||
@Get("edit/{id}")
|
||||
async KpiLinkByIdEdit(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
let _data = await new permission().PermissionGet(request, "SYS_EVA_COMPETENCY");
|
||||
const kpiLink = await this.kpiLinkRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["positions", "kpiCapacitys", "kpiGroup"],
|
||||
|
|
@ -202,38 +202,13 @@ export class kpiLinkController extends Controller {
|
|||
};
|
||||
return new HttpSuccess(formattedResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบเชื่อมโยง
|
||||
* @param id
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteKpiLink(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
|
||||
const kpiLink = await this.kpiLinkRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["kpiCapacitys"],
|
||||
});
|
||||
if (!kpiLink) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
|
||||
}
|
||||
|
||||
kpiLink.kpiCapacitys = [];
|
||||
await this.kpiLinkRepository.save(kpiLink, { data: request });
|
||||
|
||||
await this.positionRepository.delete({ kpiLinkId: id });
|
||||
await this.kpiLinkRepository.delete({ id: id });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API list เชื่อมโยง
|
||||
* @param page
|
||||
* @param pageSize
|
||||
*/
|
||||
@Get()
|
||||
async listKpiLink(
|
||||
@Get("edit")
|
||||
async listKpiLinkEdit(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
|
|
@ -281,6 +256,134 @@ export class kpiLinkController extends Controller {
|
|||
});
|
||||
}
|
||||
|
||||
const formattedResponse = kpiLink.map((item) => ({
|
||||
id: item.id,
|
||||
groupName: item.kpiGroup.nameGroupKPI,
|
||||
groupId: item.kpiGroup.id,
|
||||
positions: item.positions.map((position) => ({
|
||||
id: position.id,
|
||||
name: position.name,
|
||||
})),
|
||||
capacitys: item.kpiCapacitys.map((capacity) => ({
|
||||
id: capacity.id,
|
||||
name: capacity.name,
|
||||
type: capacity.type,
|
||||
description: capacity.description,
|
||||
})),
|
||||
}));
|
||||
return new HttpSuccess({ data: formattedResponse, total });
|
||||
}
|
||||
/**
|
||||
* API เชื่อมโยง
|
||||
* @param id
|
||||
*/
|
||||
@Get("{id}")
|
||||
async KpiLinkById(@Request() request: RequestWithUser, @Path() id: string) {
|
||||
const kpiLink = await this.kpiLinkRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["positions", "kpiCapacitys", "kpiGroup"],
|
||||
order: {
|
||||
createdAt: "ASC",
|
||||
},
|
||||
});
|
||||
if (!kpiLink) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
|
||||
}
|
||||
const formattedResponse = {
|
||||
id: kpiLink.id,
|
||||
groupName: kpiLink.kpiGroup.nameGroupKPI,
|
||||
groupId: kpiLink.kpiGroup.id,
|
||||
positions: kpiLink.positions.map((position) => ({
|
||||
id: position.id,
|
||||
name: position.name,
|
||||
})),
|
||||
capacitys: kpiLink.kpiCapacitys.map((capacity) => ({
|
||||
id: capacity.id,
|
||||
name: capacity.name,
|
||||
type: capacity.type,
|
||||
description: capacity.description,
|
||||
})),
|
||||
};
|
||||
return new HttpSuccess(formattedResponse);
|
||||
}
|
||||
|
||||
/**
|
||||
* API ลบเชื่อมโยง
|
||||
* @param id
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteKpiLink(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
await new permission().PermissionDelete(request, "SYS_EVA_COMPETENCY");
|
||||
const kpiLink = await this.kpiLinkRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["kpiCapacitys"],
|
||||
});
|
||||
if (!kpiLink) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
|
||||
}
|
||||
|
||||
kpiLink.kpiCapacitys = [];
|
||||
await this.kpiLinkRepository.save(kpiLink, { data: request });
|
||||
|
||||
await this.positionRepository.delete({ kpiLinkId: id });
|
||||
await this.kpiLinkRepository.delete({ id: id });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* API list เชื่อมโยง
|
||||
* @param page
|
||||
* @param pageSize
|
||||
*/
|
||||
@Get()
|
||||
async listKpiLink(
|
||||
@Request() request: RequestWithUser,
|
||||
@Query("page") page: number = 1,
|
||||
@Query("pageSize") pageSize: number = 10,
|
||||
@Query("keyword") keyword?: string,
|
||||
) {
|
||||
const [_kpiLink, _total] = await AppDataSource.getRepository(KpiLink)
|
||||
.createQueryBuilder("kpiLink")
|
||||
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
|
||||
.leftJoinAndSelect("kpiLink.positions", "positions")
|
||||
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
|
||||
.andWhere(
|
||||
new Brackets((qb) => {
|
||||
qb.orWhere("kpiGroup.nameGroupKPI LIKE :keyword", { keyword: `%${keyword}%` })
|
||||
.orWhere("positions.name LIKE :keyword", { keyword: `%${keyword}%` })
|
||||
.orWhere("kpiCapacitys.name LIKE :keyword", { keyword: `%${keyword}%` });
|
||||
}),
|
||||
)
|
||||
.getManyAndCount();
|
||||
|
||||
if (_total === 0) {
|
||||
return new HttpSuccess({
|
||||
data: [],
|
||||
total: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const [kpiLink, total] = await AppDataSource.getRepository(KpiLink)
|
||||
.createQueryBuilder("kpiLink")
|
||||
.leftJoinAndSelect("kpiLink.kpiGroup", "kpiGroup")
|
||||
.leftJoinAndSelect("kpiLink.positions", "positions")
|
||||
.leftJoinAndSelect("kpiLink.kpiCapacitys", "kpiCapacitys")
|
||||
.andWhere("kpiLink.id In (:id)", {
|
||||
id: _kpiLink.map((x) => x.id),
|
||||
})
|
||||
.skip((page - 1) * pageSize)
|
||||
.take(pageSize)
|
||||
.orderBy("kpiLink.createdAt", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
if (_total === 0) {
|
||||
return new HttpSuccess({
|
||||
data: [],
|
||||
total: 0,
|
||||
});
|
||||
}
|
||||
|
||||
const formattedResponse = kpiLink.map((item) => ({
|
||||
id: item.id,
|
||||
groupName: item.kpiGroup.nameGroupKPI,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue