fix isNull and fix Get{id}

This commit is contained in:
AdisakKanthawilang 2024-05-08 14:03:42 +07:00
parent d632d5e10b
commit 5834958081
2 changed files with 63 additions and 28 deletions

View file

@ -340,8 +340,10 @@ export class kpiPlanController extends Controller {
}
const formattedData = {
id: kpiPlan.id,
year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year,
round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI,
// year: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.year,
// round: kpiPlan.kpiPeriod == null ? null : kpiPlan.kpiPeriod.durationKPI,
year: kpiPlan.kpiPeriod == null ? null : kpiPlan.year,
round: kpiPlan.kpiPeriod == null ? null : kpiPlan.period,
kpiPeriodId: kpiPlan.kpiPeriodId,
including: kpiPlan.including,
includingName: kpiPlan.includingName,
@ -372,6 +374,7 @@ export class kpiPlanController extends Controller {
strategyChild3: kpiPlan.strategyChild3Id,
strategyChild4: kpiPlan.strategyChild4Id,
strategyChild5: kpiPlan.strategyChild5Id,
documentInfoEvidence: kpiPlan.documentInfoEvidence,
};
return new HttpSuccess(formattedData);
}
@ -392,9 +395,9 @@ export class kpiPlanController extends Controller {
period?: string | null;
nodeId?: string | null;
node?: number | null;
keyword?: string;
isAll?: boolean;
isNull?: boolean;
keyword?: string | null;
isAll?: boolean | false;
// isNull?: boolean | false;
},
) {
let condition = "";
@ -442,21 +445,37 @@ export class kpiPlanController extends Controller {
}
parameters.nodeId = `%${requestBody.nodeId}%`;
}
if (requestBody.year && requestBody.period && requestBody.isNull === true) {
condition += ` AND (kpiPlan.year LIKE :year OR kpiPlan.year IS NULL) AND (kpiPlan.period LIKE :period OR kpiPlan.period IS NULL)`;
parameters.year = `%${requestBody.year}%`;
parameters.period = `%${requestBody.period}%`;
}
// if (requestBody.year && requestBody.period && requestBody.isNull === true) {
// condition += ` AND (kpiPlan.year LIKE :year OR kpiPlan.year IS NULL) AND (kpiPlan.period LIKE :period OR kpiPlan.period IS NULL)`;
// parameters.year = `%${requestBody.year}%`;
// parameters.period = `%${requestBody.period}%`;
// }
const [kpiPlan, total] = await AppDataSource.getRepository(KpiPlan)
.createQueryBuilder("kpiPlan")
.leftJoinAndSelect("kpiPlan.kpiPeriod", "kpiPeriod")
.andWhere(condition, parameters)
// .andWhere(
// requestBody.year && requestBody.period
// ? "kpiPlan.year LIKE :year AND kpiPlan.period LIKE :period"
// : "1=1",
// {
// year: `%${requestBody.year}%`,
// period: `%${requestBody.period}%`,
// },
// )
.andWhere(
requestBody.isNull === false && requestBody.year && requestBody.period
? "kpiPlan.year LIKE :year AND kpiPlan.period LIKE :period"
requestBody.year
? "kpiPlan.year LIKE :year"
: "1=1",
{
year: `%${requestBody.year}%`,
},
)
.andWhere(
requestBody.period
? "kpiPlan.period LIKE :period"
: "1=1",
{
period: `%${requestBody.period}%`,
},
)