แก้ query total
This commit is contained in:
parent
b433a44000
commit
ba00645cb8
5 changed files with 124 additions and 65 deletions
|
|
@ -14,7 +14,7 @@ import {
|
|||
SuccessResponse,
|
||||
Response,
|
||||
Query,
|
||||
ArrayValidator
|
||||
ArrayValidator,
|
||||
} from "tsoa";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
|
|
@ -22,7 +22,7 @@ import HttpError from "../interfaces/http-error";
|
|||
import HttpStatusCode from "../interfaces/http-status";
|
||||
import { KpiCapacity } from "../entities/kpiCapacity";
|
||||
import { KpiUserEvaluation } from "../entities/kpiUserEvaluation";
|
||||
import { KpiUserCapacity, KpiUserCapacityDataPoint} from "../entities/kpiUserCapacity";
|
||||
import { KpiUserCapacity, KpiUserCapacityDataPoint } from "../entities/kpiUserCapacity";
|
||||
import { Like, In, Not } from "typeorm";
|
||||
import { Double } from "typeorm/browser";
|
||||
|
||||
|
|
@ -41,23 +41,24 @@ export class KpiUserCapacityController extends Controller {
|
|||
|
||||
/**
|
||||
* API สร้างองค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @summary สร้างองค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Post()
|
||||
async CreateKpiUserCapacity(
|
||||
@Body() requestBody: {
|
||||
@Body()
|
||||
requestBody: {
|
||||
kpiUserEvaluationId: string;
|
||||
kpiCapacityId: string;
|
||||
level: string;
|
||||
// point: number;
|
||||
weight: number;
|
||||
summary: Double
|
||||
summary: Double;
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
){
|
||||
) {
|
||||
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: requestBody.kpiUserEvaluationId },
|
||||
});
|
||||
|
|
@ -71,18 +72,15 @@ export class KpiUserCapacityController extends Controller {
|
|||
where: { id: requestBody.kpiCapacityId },
|
||||
});
|
||||
if (!kpiCapacity) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการสมรรถนะนี้",
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการสมรรถนะนี้");
|
||||
}
|
||||
const chkRepleat = await this.kpiUserCapacityRepository.find({
|
||||
where: {
|
||||
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
||||
kpiCapacityId: requestBody.kpiCapacityId
|
||||
}
|
||||
})
|
||||
if(chkRepleat.length > 0){
|
||||
kpiCapacityId: requestBody.kpiCapacityId,
|
||||
},
|
||||
});
|
||||
if (chkRepleat.length > 0) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่สามารถเพิ่มข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
||||
|
|
@ -95,30 +93,29 @@ export class KpiUserCapacityController extends Controller {
|
|||
kpiUserCapacity.lastUpdateFullName = request.user.name;
|
||||
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
||||
return new HttpSuccess(kpiUserCapacity.id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* API แก้ไของค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @summary แก้ไของค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @param {string} id Guid, *Id องค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*/
|
||||
@Put("{id}")
|
||||
async updateKpiUserCapacity(
|
||||
@Path() id: string,
|
||||
@Body() requestBody: {
|
||||
@Body()
|
||||
requestBody: {
|
||||
kpiUserEvaluationId: string;
|
||||
kpiCapacityId: string;
|
||||
level: string;
|
||||
// point: number;
|
||||
weight: number;
|
||||
summary: Double
|
||||
summary: Double;
|
||||
},
|
||||
@Request() request: { user: Record<string, any> },
|
||||
) {
|
||||
|
||||
const kpiUserEvalution = await this.kpiUserEvalutionRepository.findOne({
|
||||
where: { id: requestBody.kpiUserEvaluationId },
|
||||
});
|
||||
|
|
@ -132,10 +129,7 @@ export class KpiUserCapacityController extends Controller {
|
|||
where: { id: requestBody.kpiCapacityId },
|
||||
});
|
||||
if (!kpiCapacity) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่พบข้อมูลรายการสมรรถนะนี้",
|
||||
);
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลรายการสมรรถนะนี้");
|
||||
}
|
||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||
where: { id: id },
|
||||
|
|
@ -150,10 +144,10 @@ export class KpiUserCapacityController extends Controller {
|
|||
where: {
|
||||
kpiUserEvaluationId: requestBody.kpiUserEvaluationId,
|
||||
kpiCapacityId: requestBody.kpiCapacityId,
|
||||
id: Not(id)
|
||||
}
|
||||
})
|
||||
if(chkRepleat.length > 0){
|
||||
id: Not(id),
|
||||
},
|
||||
});
|
||||
if (chkRepleat.length > 0) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
"ไม่สามารถแก้ไขข้อมูลได้เนื่องจากรายการสมรรถนะซ้ำ",
|
||||
|
|
@ -165,7 +159,6 @@ export class KpiUserCapacityController extends Controller {
|
|||
this.kpiUserCapacityRepository.merge(kpiUserCapacity, _kpiUserCapacity);
|
||||
await this.kpiUserCapacityRepository.save(kpiUserCapacity);
|
||||
return new HttpSuccess(kpiUserCapacity.id);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -179,8 +172,8 @@ export class KpiUserCapacityController extends Controller {
|
|||
async GetKpiUserCapacityById(@Path() id: string) {
|
||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||
where: { id: id },
|
||||
relations: ["kpiCapacity"]
|
||||
})
|
||||
relations: ["kpiCapacity"],
|
||||
});
|
||||
if (!kpiUserCapacity) {
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
|
|
@ -194,8 +187,8 @@ export class KpiUserCapacityController extends Controller {
|
|||
level: kpiUserCapacity.level,
|
||||
point: kpiUserCapacity.point,
|
||||
weight: kpiUserCapacity.weight,
|
||||
summary: kpiUserCapacity.summary
|
||||
}
|
||||
summary: kpiUserCapacity.summary,
|
||||
};
|
||||
return new HttpSuccess(mapData);
|
||||
}
|
||||
|
||||
|
|
@ -208,15 +201,15 @@ export class KpiUserCapacityController extends Controller {
|
|||
@Get()
|
||||
async listKpiUserCapacity(
|
||||
@Query("id") id: string, //kpiUserEvaluationId
|
||||
@Query("type") type: string
|
||||
@Query("type") type: string,
|
||||
) {
|
||||
const [kpiUserCapacity, total] = await AppDataSource.getRepository(KpiUserCapacity)
|
||||
.createQueryBuilder("kpiUserCapacity")
|
||||
.leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity")
|
||||
.andWhere("kpiUserCapacity.kpiUserEvaluationId = :id", { id: id })
|
||||
.andWhere(type ? "kpiCapacity.type LIKE :type" : "1=1", { type: `%${type.toLocaleUpperCase()}%` })
|
||||
.orderBy("kpiUserCapacity.createdAt", "ASC")
|
||||
.getManyAndCount();
|
||||
.createQueryBuilder("kpiUserCapacity")
|
||||
.leftJoinAndSelect("kpiUserCapacity.kpiCapacity", "kpiCapacity")
|
||||
.andWhere("kpiUserCapacity.kpiUserEvaluationId = :id", { id: id })
|
||||
.andWhere(type ? "kpiCapacity.type LIKE :type" : "1=1", { type: type.toLocaleUpperCase() })
|
||||
.orderBy("kpiUserCapacity.createdAt", "ASC")
|
||||
.getManyAndCount();
|
||||
|
||||
const mapData = kpiUserCapacity.map((item) => ({
|
||||
id: item.id,
|
||||
|
|
@ -232,9 +225,9 @@ export class KpiUserCapacityController extends Controller {
|
|||
|
||||
/**
|
||||
* API ลบองค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @summary ลบองค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @param {string} id Guid, *Id องค์ประกอบที่ 2 พฤติกรรมการปฎิบัติราชการ (สมรรถนะ) (USER)
|
||||
*/
|
||||
@Delete("{id}")
|
||||
|
|
@ -254,23 +247,25 @@ export class KpiUserCapacityController extends Controller {
|
|||
|
||||
/**
|
||||
* API กรอกระดับคะแนนตามเกณฑ์การประเมิน (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
* @summary กรอกระดับคะแนนตามเกณฑ์การประเมิน (สมรรถนะ) (USER)
|
||||
*
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Post("point")
|
||||
async CreateKpiUserCapacityPoint(
|
||||
@Body() requestBody: KpiUserCapacityDataPoint[],
|
||||
@Request() request: { user: Record<string, any> },
|
||||
){
|
||||
|
||||
) {
|
||||
for (const item of requestBody) {
|
||||
const kpiUserCapacity = await this.kpiUserCapacityRepository.findOne({
|
||||
where: { id: item.id },
|
||||
});
|
||||
if (!kpiUserCapacity) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, `ไม่พบข้อมูลพฤติกรรมการปฎิบัติราชการ (สมรรถนะ): ${item.id}`);
|
||||
throw new HttpError(
|
||||
HttpStatusCode.NOT_FOUND,
|
||||
`ไม่พบข้อมูลพฤติกรรมการปฎิบัติราชการ (สมรรถนะ): ${item.id}`,
|
||||
);
|
||||
}
|
||||
this.kpiUserCapacityRepository.merge(kpiUserCapacity, item);
|
||||
kpiUserCapacity.lastUpdateUserId = request.user.sub;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue