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