แก้ query total
This commit is contained in:
parent
b433a44000
commit
ba00645cb8
5 changed files with 124 additions and 65 deletions
|
|
@ -20,8 +20,14 @@ 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, createKpiPeriod, updateKpiPeriod } from "../entities/kpiPeriod";
|
import { KpiPeriod, createKpiPeriod, updateKpiPeriod } from "../entities/kpiPeriod";
|
||||||
import { Like } from "typeorm/browser";
|
import { In, Not } from "typeorm";
|
||||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
|
import { KpiPlan } from "../entities/kpiPlan";
|
||||||
|
import { KpiRole } from "../entities/kpiRole";
|
||||||
|
import { KpiUserRole } from "../entities/kpiUserRole";
|
||||||
|
import { KpiUserPlanned } from "../entities/kpiUserPlanned";
|
||||||
|
import { KpiUserCapacity } from "../entities/kpiUserCapacity";
|
||||||
|
import { KpiUserSpecial } from "../entities/kpiUserSpecial";
|
||||||
|
|
||||||
@Route("api/v1/kpi/period")
|
@Route("api/v1/kpi/period")
|
||||||
@Tags("kpiPeriod")
|
@Tags("kpiPeriod")
|
||||||
|
|
@ -34,6 +40,12 @@ import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
export class kpiPeriodController extends Controller {
|
export class kpiPeriodController extends Controller {
|
||||||
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
|
||||||
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
private kpiUserEvaluationRepository = AppDataSource.getRepository(KpiUserEvaluation);
|
||||||
|
private kpiRoleRepository = AppDataSource.getRepository(KpiRole);
|
||||||
|
private kpiPlanRepository = AppDataSource.getRepository(KpiPlan);
|
||||||
|
private kpiUserRoleRepository = AppDataSource.getRepository(KpiUserRole);
|
||||||
|
private kpiUserPlannedRepository = AppDataSource.getRepository(KpiUserPlanned);
|
||||||
|
private kpiUserCapacityRepository = AppDataSource.getRepository(KpiUserCapacity);
|
||||||
|
private kpiUserSpecialRepository = AppDataSource.getRepository(KpiUserSpecial);
|
||||||
/**
|
/**
|
||||||
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
* สร้างรอบการประเมินผลการปฏิบัติหน้าที่ราชการ
|
||||||
* @param requestBody
|
* @param requestBody
|
||||||
|
|
@ -49,6 +61,15 @@ export class kpiPeriodController extends Controller {
|
||||||
@Body() requestBody: createKpiPeriod,
|
@Body() requestBody: createKpiPeriod,
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
|
const chkkpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||||
|
where: {
|
||||||
|
durationKPI: requestBody.durationKPI,
|
||||||
|
year: requestBody.year,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (chkkpiPeriod) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "รอบการประเมินผลนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
const kpiPeriod = Object.assign(new KpiPeriod(), requestBody);
|
const kpiPeriod = Object.assign(new KpiPeriod(), requestBody);
|
||||||
kpiPeriod.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
kpiPeriod.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||||
kpiPeriod.createdUserId = request.user.sub;
|
kpiPeriod.createdUserId = request.user.sub;
|
||||||
|
|
@ -80,6 +101,16 @@ export class kpiPeriodController extends Controller {
|
||||||
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
const chkkpiPeriod = await this.kpiPeriodRepository.findOne({
|
||||||
|
where: {
|
||||||
|
id: Not(id),
|
||||||
|
durationKPI: requestBody.durationKPI,
|
||||||
|
year: requestBody.year,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
if (chkkpiPeriod) {
|
||||||
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "รอบการประเมินผลนี้มีอยู่ในระบบแล้ว");
|
||||||
|
}
|
||||||
|
|
||||||
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
requestBody.durationKPI = requestBody.durationKPI.trim().toUpperCase();
|
||||||
this.kpiPeriodRepository.merge(kpiPeriod, requestBody);
|
this.kpiPeriodRepository.merge(kpiPeriod, requestBody);
|
||||||
|
|
@ -207,15 +238,48 @@ export class kpiPeriodController extends Controller {
|
||||||
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
"ไม่พบข้อมูลรอบการประเมินผลการปฏิบัติหน้าที่ราชการนี้",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const chkKpiUserEvaluation = await this.kpiUserEvaluationRepository.find({
|
const kpiRole = await this.kpiRoleRepository.find({
|
||||||
where: { kpiPeriodId: id },
|
where: { kpiPeriodId: id },
|
||||||
})
|
});
|
||||||
if (chkKpiUserEvaluation) {
|
const kpiPlan = await this.kpiPlanRepository.find({
|
||||||
throw new HttpError(
|
where: { kpiPeriodId: id },
|
||||||
HttpStatusCode.NOT_FOUND,
|
});
|
||||||
"ไม่สามารถลบข้อมูลได้",
|
const kpiUserEvaluation = await this.kpiUserEvaluationRepository.find({
|
||||||
);
|
where: { kpiPeriodId: id },
|
||||||
}
|
});
|
||||||
|
|
||||||
|
const kpiUserRole = await this.kpiUserRoleRepository.find({
|
||||||
|
where: { kpiRoleId: In(kpiRole.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
|
||||||
|
const kpiUserPlanned = await this.kpiUserPlannedRepository.find({
|
||||||
|
where: { kpiPlanId: In(kpiPlan.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
|
||||||
|
const _kpiUserRole = await this.kpiUserRoleRepository.find({
|
||||||
|
where: { kpiUserEvaluationId: In(kpiRole.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
const _kpiUserPlanned = await this.kpiUserPlannedRepository.find({
|
||||||
|
where: { kpiUserEvaluationId: In(kpiPlan.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
const _kpiUserCapacity = await this.kpiUserCapacityRepository.find({
|
||||||
|
where: { kpiUserEvaluationId: In(kpiPlan.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
const _kpiUserSpecial = await this.kpiUserSpecialRepository.find({
|
||||||
|
where: { kpiUserEvaluationId: In(kpiPlan.map((x) => x.id)) },
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.kpiUserRoleRepository.remove(kpiUserRole);
|
||||||
|
await this.kpiUserPlannedRepository.remove(kpiUserPlanned);
|
||||||
|
|
||||||
|
await this.kpiUserRoleRepository.remove(_kpiUserRole);
|
||||||
|
await this.kpiUserPlannedRepository.remove(_kpiUserPlanned);
|
||||||
|
await this.kpiUserCapacityRepository.remove(_kpiUserCapacity);
|
||||||
|
await this.kpiUserSpecialRepository.remove(_kpiUserSpecial);
|
||||||
|
|
||||||
|
await this.kpiRoleRepository.remove(kpiRole);
|
||||||
|
await this.kpiPlanRepository.remove(kpiPlan);
|
||||||
|
await this.kpiUserEvaluationRepository.remove(kpiUserEvaluation);
|
||||||
await this.kpiPeriodRepository.remove(kpiPeriod);
|
await this.kpiPeriodRepository.remove(kpiPeriod);
|
||||||
return new HttpSuccess();
|
return new HttpSuccess();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ export class kpiPlanController extends Controller {
|
||||||
: "kpiPlan.rootId LIKE :nodeId"
|
: "kpiPlan.rootId LIKE :nodeId"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
nodeId: `${nodeId}`,
|
nodeId: nodeId,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(
|
.andWhere(
|
||||||
|
|
@ -317,7 +317,7 @@ export class kpiPlanController extends Controller {
|
||||||
? "kpiPlan.kpiPeriodId LIKE :kpiPeriodId"
|
? "kpiPlan.kpiPeriodId LIKE :kpiPeriodId"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
kpiPeriodId: `${kpiPeriodId}`,
|
kpiPeriodId: kpiPeriodId,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.select([
|
.select([
|
||||||
|
|
|
||||||
|
|
@ -243,7 +243,7 @@ export class kpiRoleController extends Controller {
|
||||||
: "kpiRole.rootId LIKE :nodeId"
|
: "kpiRole.rootId LIKE :nodeId"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
nodeId: `${nodeId}`,
|
nodeId: nodeId,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(
|
.andWhere(
|
||||||
|
|
@ -251,7 +251,7 @@ export class kpiRoleController extends Controller {
|
||||||
? "kpiRole.kpiPeriod LIKE :kpiPeriodId"
|
? "kpiRole.kpiPeriod LIKE :kpiPeriodId"
|
||||||
: "1=1",
|
: "1=1",
|
||||||
{
|
{
|
||||||
kpiPeriodId: `${kpiPeriodId}`,
|
kpiPeriodId: kpiPeriodId,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.andWhere(position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
|
.andWhere(position != undefined ? "kpiRole.position LIKE :position" : "1=1", {
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ import {
|
||||||
SuccessResponse,
|
SuccessResponse,
|
||||||
Response,
|
Response,
|
||||||
Query,
|
Query,
|
||||||
ArrayValidator
|
ArrayValidator,
|
||||||
} from "tsoa";
|
} from "tsoa";
|
||||||
import { AppDataSource } from "../database/data-source";
|
import { AppDataSource } from "../database/data-source";
|
||||||
import HttpSuccess from "../interfaces/http-success";
|
import HttpSuccess from "../interfaces/http-success";
|
||||||
|
|
@ -22,7 +22,7 @@ import HttpError from "../interfaces/http-error";
|
||||||
import HttpStatusCode from "../interfaces/http-status";
|
import HttpStatusCode from "../interfaces/http-status";
|
||||||
import { KpiCapacity } from "../entities/kpiCapacity";
|
import { KpiCapacity } from "../entities/kpiCapacity";
|
||||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||||
import { KpiUserCapacity, KpiUserCapacityDataPoint} from "../entities/kpiUserCapacity";
|
import { KpiUserCapacity, KpiUserCapacityDataPoint } from "../entities/kpiUserCapacity";
|
||||||
import { Like, In, Not } from "typeorm";
|
import { Like, In, Not } from "typeorm";
|
||||||
import { Double } from "typeorm/browser";
|
import { Double } from "typeorm/browser";
|
||||||
|
|
||||||
|
|
@ -48,16 +48,17 @@ export class KpiUserCapacityController extends Controller {
|
||||||
*/
|
*/
|
||||||
@Post()
|
@Post()
|
||||||
async CreateKpiUserCapacity(
|
async CreateKpiUserCapacity(
|
||||||
@Body() requestBody: {
|
@Body()
|
||||||
|
requestBody: {
|
||||||
kpiUserEvaluationId: string;
|
kpiUserEvaluationId: string;
|
||||||
kpiCapacityId: string;
|
kpiCapacityId: string;
|
||||||
level: string;
|
level: string;
|
||||||
// point: number;
|
// point: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
summary: Double
|
summary: Double;
|
||||||
},
|
},
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
){
|
) {
|
||||||
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
||||||
where: { id: requestBody.kpiUserEvaluationId },
|
where: { id: requestBody.kpiUserEvaluationId },
|
||||||
});
|
});
|
||||||
|
|
@ -71,18 +72,15 @@ export class KpiUserCapacityController extends Controller {
|
||||||
where: { id: requestBody.kpiCapacityId },
|
where: { id: requestBody.kpiCapacityId },
|
||||||
});
|
});
|
||||||
if (!kpiCapacity) {
|
if (!kpiCapacity) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการสมรรถนะนี้");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลรายการสมรรถนะนี้",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const chkRepleat = await this.kpiUserCapacityRepository.find({
|
const chkRepleat = await this.kpiUserCapacityRepository.find({
|
||||||
where: {
|
where: {
|
||||||
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
||||||
kpiCapacityId: requestBody.kpiCapacityId
|
kpiCapacityId: requestBody.kpiCapacityId,
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
if(chkRepleat.length > 0){
|
if (chkRepleat.length > 0) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
||||||
|
|
@ -95,7 +93,6 @@ export class KpiUserCapacityController extends Controller {
|
||||||
kpiUserCapacity.lastUpdateFullName = request.user.name;
|
kpiUserCapacity.lastUpdateFullName = request.user.name;
|
||||||
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
||||||
return new HttpSuccess(kpiUserCapacity.id);
|
return new HttpSuccess(kpiUserCapacity.id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -108,17 +105,17 @@ export class KpiUserCapacityController extends Controller {
|
||||||
@Put("{id}")
|
@Put("{id}")
|
||||||
async updateKpiUserCapacity(
|
async updateKpiUserCapacity(
|
||||||
@Path() id: string,
|
@Path() id: string,
|
||||||
@Body() requestBody: {
|
@Body()
|
||||||
|
requestBody: {
|
||||||
kpiUserEvaluationId: string;
|
kpiUserEvaluationId: string;
|
||||||
kpiCapacityId: string;
|
kpiCapacityId: string;
|
||||||
level: string;
|
level: string;
|
||||||
// point: number;
|
// point: number;
|
||||||
weight: number;
|
weight: number;
|
||||||
summary: Double
|
summary: Double;
|
||||||
},
|
},
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
) {
|
) {
|
||||||
|
|
||||||
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
||||||
where: { id: requestBody.kpiUserEvaluationId },
|
where: { id: requestBody.kpiUserEvaluationId },
|
||||||
});
|
});
|
||||||
|
|
@ -132,10 +129,7 @@ export class KpiUserCapacityController extends Controller {
|
||||||
where: { id: requestBody.kpiCapacityId },
|
where: { id: requestBody.kpiCapacityId },
|
||||||
});
|
});
|
||||||
if (!kpiCapacity) {
|
if (!kpiCapacity) {
|
||||||
throw new HttpError(
|
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการสมรรถนะนี้");
|
||||||
HttpStatusCode.NOT_FOUND,
|
|
||||||
"ไม่พบข้อมูลรายการสมรรถนะนี้",
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
|
|
@ -150,10 +144,10 @@ export class KpiUserCapacityController extends Controller {
|
||||||
where: {
|
where: {
|
||||||
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
||||||
kpiCapacityId: requestBody.kpiCapacityId,
|
kpiCapacityId: requestBody.kpiCapacityId,
|
||||||
id: Not(id)
|
id: Not(id),
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
if(chkRepleat.length > 0){
|
if (chkRepleat.length > 0) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
"ไม่สามารถแก้ไขข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
"ไม่สามารถแก้ไขข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
||||||
|
|
@ -165,7 +159,6 @@ export class KpiUserCapacityController extends Controller {
|
||||||
this.kpiUserCapacityRepository.merge(kpiUserCapacity, _kpiUserCapacity);
|
this.kpiUserCapacityRepository.merge(kpiUserCapacity, _kpiUserCapacity);
|
||||||
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
||||||
return new HttpSuccess(kpiUserCapacity.id);
|
return new HttpSuccess(kpiUserCapacity.id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -179,8 +172,8 @@ export class KpiUserCapacityController extends Controller {
|
||||||
async GetKpiUserCapacityById(@Path() id: string) {
|
async GetKpiUserCapacityById(@Path() id: string) {
|
||||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||||
where: { id: id },
|
where: { id: id },
|
||||||
relations: ["kpiCapacity"]
|
relations: ["kpiCapacity"],
|
||||||
})
|
});
|
||||||
if (!kpiUserCapacity) {
|
if (!kpiUserCapacity) {
|
||||||
throw new HttpError(
|
throw new HttpError(
|
||||||
HttpStatusCode.NOT_FOUND,
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
|
@ -194,8 +187,8 @@ export class KpiUserCapacityController extends Controller {
|
||||||
level: kpiUserCapacity.level,
|
level: kpiUserCapacity.level,
|
||||||
point: kpiUserCapacity.point,
|
point: kpiUserCapacity.point,
|
||||||
weight: kpiUserCapacity.weight,
|
weight: kpiUserCapacity.weight,
|
||||||
summary: kpiUserCapacity.summary
|
summary: kpiUserCapacity.summary,
|
||||||
}
|
};
|
||||||
return new HttpSuccess(mapData);
|
return new HttpSuccess(mapData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,15 +201,15 @@ export class KpiUserCapacityController extends Controller {
|
||||||
@Get()
|
@Get()
|
||||||
async listKpiUserCapacity(
|
async listKpiUserCapacity(
|
||||||
@Query("id") id: string, //kpiUserEvaluationId
|
@Query("id") id: string, //kpiUserEvaluationId
|
||||||
@Query("type") type: string
|
@Query("type") type: string,
|
||||||
) {
|
) {
|
||||||
const [kpiUserCapacity, total] = await AppDataSource.getRepository(KpiUserCapacity)
|
const [kpiUserCapacity, total] = await AppDataSource.getRepository(KpiUserCapacity)
|
||||||
.createQueryBuilder("kpiUserCapacity")
|
.createQueryBuilder("kpiUserCapacity")
|
||||||
.leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity")
|
.leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity")
|
||||||
.andWhere("kpiUserCapacity.kpiUserEvaluationId = :id", { id: id })
|
.andWhere("kpiUserCapacity.kpiUserEvaluationId = :id", { id: id })
|
||||||
.andWhere(type ? "kpiCapacity.type LIKE :type" : "1=1", { type: `%${type.toLocaleUpperCase()}%` })
|
.andWhere(type ? "kpiCapacity.type LIKE :type" : "1=1", { type: type.toLocaleUpperCase() })
|
||||||
.orderBy("kpiUserCapacity.createdAt", "ASC")
|
.orderBy("kpiUserCapacity.createdAt", "ASC")
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
|
|
||||||
const mapData = kpiUserCapacity.map((item) => ({
|
const mapData = kpiUserCapacity.map((item) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
|
|
@ -263,14 +256,16 @@ export class KpiUserCapacityController extends Controller {
|
||||||
async CreateKpiUserCapacityPoint(
|
async CreateKpiUserCapacityPoint(
|
||||||
@Body() requestBody: KpiUserCapacityDataPoint[],
|
@Body() requestBody: KpiUserCapacityDataPoint[],
|
||||||
@Request() request: { user: Record<string, any> },
|
@Request() request: { user: Record<string, any> },
|
||||||
){
|
) {
|
||||||
|
|
||||||
for (const item of requestBody) {
|
for (const item of requestBody) {
|
||||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||||
where: { id: item.id },
|
where: { id: item.id },
|
||||||
});
|
});
|
||||||
if (!kpiUserCapacity) {
|
if (!kpiUserCapacity) {
|
||||||
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลพฤติกรรมการปฎิบัติราชการ (สมรรถนะ): ${item.id}`);
|
throw new HttpError(
|
||||||
|
HttpStatusCode.NOT_FOUND,
|
||||||
|
`ไม่พบข้อมูลพฤติกรรมการปฎิบัติราชการ (สมรรถนะ): ${item.id}`,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
this.kpiUserCapacityRepository.merge(kpiUserCapacity, item);
|
this.kpiUserCapacityRepository.merge(kpiUserCapacity, item);
|
||||||
kpiUserCapacity.lastUpdateUserId = request.user.sub;
|
kpiUserCapacity.lastUpdateUserId = request.user.sub;
|
||||||
|
|
|
||||||
|
|
@ -57,7 +57,7 @@ export class KpiUserEvaluationController extends Controller {
|
||||||
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
|
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||||
.createQueryBuilder("kpiUserEvaluation")
|
.createQueryBuilder("kpiUserEvaluation")
|
||||||
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
|
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
|
||||||
kpiPeriodId: `%${kpiPeriodId}%`,
|
kpiPeriodId: kpiPeriodId,
|
||||||
})
|
})
|
||||||
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
|
|
@ -212,7 +212,7 @@ export class KpiUserEvaluationController extends Controller {
|
||||||
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
|
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
|
||||||
.createQueryBuilder("kpiUserEvaluation")
|
.createQueryBuilder("kpiUserEvaluation")
|
||||||
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
|
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
|
||||||
kpiPeriodId: `%${kpiPeriodId}%`,
|
kpiPeriodId: kpiPeriodId,
|
||||||
})
|
})
|
||||||
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
.orderBy("kpiUserEvaluation.createdAt", "ASC")
|
||||||
.skip((page - 1) * pageSize)
|
.skip((page - 1) * pageSize)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue