เพิ่ม node id

This commit is contained in:
Kittapath 2024-04-26 10:18:00 +07:00
parent 71eac974de
commit b433a44000
3 changed files with 95 additions and 38 deletions

View file

@ -257,6 +257,11 @@ export class kpiPlanController extends Controller {
achievement5: kpiPlan.achievement5, achievement5: kpiPlan.achievement5,
meaning: kpiPlan.meaning, meaning: kpiPlan.meaning,
formula: kpiPlan.formula, formula: kpiPlan.formula,
root: kpiPlan.rootId,
child1: kpiPlan.child1Id,
child2: kpiPlan.child2Id,
child3: kpiPlan.child3Id,
child4: kpiPlan.child4Id,
node: node, node: node,
nodeId: nodeId, nodeId: nodeId,
nodeName: nodeName, nodeName: nodeName,
@ -264,6 +269,11 @@ export class kpiPlanController extends Controller {
strategy: strategy, strategy: strategy,
strategyId: strategyId, strategyId: strategyId,
strategyName: strategyName, strategyName: strategyName,
strategyChild1: kpiPlan.strategyChild1Id,
strategyChild2: kpiPlan.strategyChild2Id,
strategyChild3: kpiPlan.strategyChild3Id,
strategyChild4: kpiPlan.strategyChild4Id,
strategyChild5: kpiPlan.strategyChild5Id,
}; };
return new HttpSuccess(formattedData); return new HttpSuccess(formattedData);
} }

View file

@ -197,6 +197,11 @@ export class kpiRoleController extends Controller {
achievement5: kpiRole.achievement5, achievement5: kpiRole.achievement5,
meaning: kpiRole.meaning, meaning: kpiRole.meaning,
formula: kpiRole.formula, formula: kpiRole.formula,
root: kpiRole.rootId,
child1: kpiRole.child1Id,
child2: kpiRole.child2Id,
child3: kpiRole.child3Id,
child4: kpiRole.child4Id,
node: node, node: node,
nodeId: nodeId, nodeId: nodeId,
nodeName: nodeName, nodeName: nodeName,

View file

@ -14,14 +14,18 @@ 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";
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 } from "../entities/kpiPeriod"; import { KpiPeriod } from "../entities/kpiPeriod";
import { KpiUserEvaluation, createKpiUserEvaluation, updateKpiUserEvaluation } from "../entities/kpiUserEvaluation"; import {
KpiUserEvaluation,
createKpiUserEvaluation,
updateKpiUserEvaluation,
} from "../entities/kpiUserEvaluation";
import { Like, In } from "typeorm"; import { Like, In } from "typeorm";
import CallAPI from "../interfaces/call-api"; import CallAPI from "../interfaces/call-api";
@ -37,6 +41,43 @@ export class KpiUserEvaluationController extends Controller {
private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod); private kpiPeriodRepository = AppDataSource.getRepository(KpiPeriod);
private kpiUserEvalutionRepository = AppDataSource.getRepository(KpiUserEvaluation); private kpiUserEvalutionRepository = AppDataSource.getRepository(KpiUserEvaluation);
/**
* API
*
* @summary
*
*/
@Get("admin")
async listKpiAdminEvaluation(
@Query("page") page: number = 1,
@Query("pageSize") pageSize: number = 10,
@Query("kpiPeriodId") kpiPeriodId?: string,
// @Query("keyword") keyword?: string,
) {
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation")
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
kpiPeriodId: `%${kpiPeriodId}%`,
})
.orderBy("kpiUserEvaluation.createdAt", "ASC")
.skip((page - 1) * pageSize)
.take(pageSize)
.getManyAndCount();
const mapData = kpiUserEvaluation.map((item) => ({
id: item.id,
profileId: item.profileId,
prefix: item.prefix,
firstname: item.firstName,
lastname: item.lastName,
kpiPeriodId: item.kpiPeriodId,
evaluationStatus: item.evaluationStatus,
evaluationResults: item.evaluationResults,
createdAt: item.createdAt,
}));
return new HttpSuccess({ data: mapData, total });
}
/** /**
* API (USER) * API (USER)
* *
@ -48,7 +89,7 @@ export class KpiUserEvaluationController extends Controller {
async CreateKpiUserEvaluation( async CreateKpiUserEvaluation(
@Body() requestBody: createKpiUserEvaluation, @Body() requestBody: createKpiUserEvaluation,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
){ ) {
const kpiPeriod = await this.kpiPeriodRepository.findOne({ const kpiPeriod = await this.kpiPeriodRepository.findOne({
where: { id: requestBody.kpiPeriodId }, where: { id: requestBody.kpiPeriodId },
}); });
@ -63,10 +104,10 @@ export class KpiUserEvaluationController extends Controller {
await new CallAPI() await new CallAPI()
.GetData(request, "org/profile/keycloak/position") .GetData(request, "org/profile/keycloak/position")
.then((x) => { .then((x) => {
kpiUserEvaluation.profileId = x.profileId kpiUserEvaluation.profileId = x.profileId;
kpiUserEvaluation.prefix = x.prefix kpiUserEvaluation.prefix = x.prefix;
kpiUserEvaluation.firstName = x.firstName kpiUserEvaluation.firstName = x.firstName;
kpiUserEvaluation.lastName = x.lastName kpiUserEvaluation.lastName = x.lastName;
}) })
.catch((x) => {}); .catch((x) => {});
kpiUserEvaluation.evaluationStatus = "PENDING"; kpiUserEvaluation.evaluationStatus = "PENDING";
@ -119,7 +160,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.lastUpdateFullName = request.user.name; kpiUserEvaluation.lastUpdateFullName = request.user.name;
this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody); this.kpiUserEvalutionRepository.merge(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation); await this.kpiUserEvalutionRepository.save(kpiUserEvaluation);
return new HttpSuccess(kpiUserEvaluation.id) return new HttpSuccess(kpiUserEvaluation.id);
} }
} }
@ -134,8 +175,18 @@ export class KpiUserEvaluationController extends Controller {
async GetKpiUserEvaluationById(@Path() id: string) { async GetKpiUserEvaluationById(@Path() id: string) {
const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({ const KpiUserEvaluation = await this.kpiUserEvalutionRepository.findOne({
where: { id: id }, where: { id: id },
select: ["id", "profileId", "prefix", "firstName", "lastName", "kpiPeriodId", "evaluationStatus", "evaluationResults", "createdAt"], select: [
}) "id",
"profileId",
"prefix",
"firstName",
"lastName",
"kpiPeriodId",
"evaluationStatus",
"evaluationResults",
"createdAt",
],
});
if (!KpiUserEvaluation) { if (!KpiUserEvaluation) {
throw new HttpError( throw new HttpError(
HttpStatusCode.NOT_FOUND, HttpStatusCode.NOT_FOUND,
@ -158,20 +209,11 @@ export class KpiUserEvaluationController extends Controller {
@Query("kpiPeriodId") kpiPeriodId?: string, @Query("kpiPeriodId") kpiPeriodId?: string,
// @Query("keyword") keyword?: string, // @Query("keyword") keyword?: string,
) { ) {
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation) const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
.createQueryBuilder("kpiUserEvaluation") .createQueryBuilder("kpiUserEvaluation")
// .leftJoinAndSelect("kpiUserEvaluation.kpiPeriod", "kpiPeriod") .andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", {
// .andWhere( kpiPeriodId: `%${kpiPeriodId}%`,
// keyword == undefined })
// ? "1=1"
// : [
// { prefix: Like(`%${keyword}%`) },
// { firstName: Like(`%${keyword}%`) },
// { lastName: Like(`%${keyword}%`) },
// ],
// )
.andWhere(kpiPeriodId ? "kpiPeriodId LIKE :kpiPeriodId" : "1=1", { kpiPeriodId: `%${kpiPeriodId}%` })
.orderBy("kpiUserEvaluation.createdAt", "ASC") .orderBy("kpiUserEvaluation.createdAt", "ASC")
.skip((page - 1) * pageSize) .skip((page - 1) * pageSize)
.take(pageSize) .take(pageSize)