แก้ api search reason

This commit is contained in:
Kittapath 2024-05-14 01:45:55 +07:00
parent 99a30faac4
commit 247f3f741a

View file

@ -77,7 +77,7 @@ export class kpiReasonController extends Controller {
where: { id: id },
relations: ["kpiUserEvaluation"],
});
if (!kpiUserEvaluation) {
throw new HttpError(
HttpStatusCode.NOT_FOUND,
@ -103,10 +103,7 @@ export class kpiReasonController extends Controller {
} else {
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
where: { id: id },
relations: [
"kpiUserPlanned",
"kpiUserPlanned.kpiUserEvaluation",
],
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -151,10 +148,7 @@ export class kpiReasonController extends Controller {
) {
const kpiReason = await this.kpiUserEvaluationReasonPlan.findOne({
where: { id: id },
relations: [
"kpiUserPlanned",
"kpiUserPlanned.kpiUserEvaluation",
],
relations: ["kpiUserPlanned", "kpiUserPlanned.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -183,19 +177,20 @@ export class kpiReasonController extends Controller {
async listKpiUserPlanReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROGRESS") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: { kpiUserPlannedId: id },
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: { kpiUserPlannedId: id },
where: { kpiUserPlannedId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -204,6 +199,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -212,6 +208,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonPlan.find({
where: {
kpiUserPlannedId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
@ -260,10 +257,7 @@ export class kpiReasonController extends Controller {
} else {
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
where: { id: id },
relations: [
"kpiUserRole",
"kpiUserRole.kpiUserEvaluation",
],
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -308,10 +302,7 @@ export class kpiReasonController extends Controller {
) {
const kpiReason = await this.kpiUserEvaluationReasonRole.findOne({
where: { id: id },
relations: [
"kpiUserRole",
"kpiUserRole.kpiUserEvaluation",
],
relations: ["kpiUserRole", "kpiUserRole.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -340,19 +331,20 @@ export class kpiReasonController extends Controller {
async listKpiUserRoleReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROGRESS") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: { kpiUserRoleId: id },
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: { kpiUserRoleId: id },
where: { kpiUserRoleId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -361,6 +353,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -369,6 +362,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonRole.find({
where: {
kpiUserRoleId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
@ -420,10 +414,7 @@ export class kpiReasonController extends Controller {
} else {
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
where: { id: id },
relations: [
"kpiUserSpecial",
"kpiUserSpecial.kpiUserEvaluation",
],
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -468,10 +459,7 @@ export class kpiReasonController extends Controller {
) {
const kpiReason = await this.kpiUserEvaluationReasonSpecial.findOne({
where: { id: id },
relations: [
"kpiUserSpecial",
"kpiUserSpecial.kpiUserEvaluation",
],
relations: ["kpiUserSpecial", "kpiUserSpecial.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -500,19 +488,20 @@ export class kpiReasonController extends Controller {
async listKpiUserSpecialReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROGRESS") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: { kpiUserSpecialId: id },
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: { kpiUserSpecialId: id },
where: { kpiUserSpecialId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -521,6 +510,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -529,6 +519,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonSpecial.find({
where: {
kpiUserSpecialId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
@ -580,10 +571,7 @@ export class kpiReasonController extends Controller {
} else {
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
where: { id: id },
relations: [
"kpiUserDevelopment",
"kpiUserDevelopment.kpiUserEvaluation",
],
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -628,10 +616,7 @@ export class kpiReasonController extends Controller {
) {
const kpiReason = await this.kpiUserEvaluationReasonDevelopment.findOne({
where: { id: id },
relations: [
"kpiUserDevelopment",
"kpiUserDevelopment.kpiUserEvaluation",
],
relations: ["kpiUserDevelopment", "kpiUserDevelopment.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -664,19 +649,20 @@ export class kpiReasonController extends Controller {
) {
if (type.trim().toUpperCase() == "PROGRESS") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: { kpiUserDevelopmentId: id },
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: { kpiUserDevelopmentId: id },
where: { kpiUserDevelopmentId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -685,6 +671,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -693,6 +680,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonDevelopment.find({
where: {
kpiUserDevelopmentId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});
@ -744,10 +732,7 @@ export class kpiReasonController extends Controller {
} else {
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
where: { id: id },
relations: [
"kpiUserCapacity",
"kpiUserCapacity.kpiUserEvaluation",
],
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -792,10 +777,7 @@ export class kpiReasonController extends Controller {
) {
const kpiReason = await this.kpiUserEvaluationReasonCapacity.findOne({
where: { id: id },
relations: [
"kpiUserCapacity",
"kpiUserCapacity.kpiUserEvaluation",
],
relations: ["kpiUserCapacity", "kpiUserCapacity.kpiUserEvaluation"],
});
if (!kpiReason) {
throw new HttpError(
@ -824,19 +806,20 @@ export class kpiReasonController extends Controller {
async listKpiUserCapacityReason(@Path() id: string, @Path() type: string, @Path() user: string) {
if (type.trim().toUpperCase() == "PROGRESS") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: { kpiUserCapacityId: id },
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else {
if (user.trim().toUpperCase() == "USER") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: { kpiUserCapacityId: id },
where: { kpiUserCapacityId: id, type: type.trim().toUpperCase() },
});
return new HttpSuccess(kpiUserEvaluationReason);
} else if (user.trim().toUpperCase() == "EVALUATOR") {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["EVALUATOR", "COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -845,6 +828,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDER", "COMMANDERHIGH", "DONE"]),
},
});
@ -853,6 +837,7 @@ export class kpiReasonController extends Controller {
const kpiUserEvaluationReason = await this.kpiUserEvaluationReasonCapacity.find({
where: {
kpiUserCapacityId: id,
type: type.trim().toUpperCase(),
status: In(["COMMANDERHIGH", "DONE"]),
},
});