เพิ่มวันที่เวลา แก้ไข/สร้าง

This commit is contained in:
kittapath 2024-09-03 15:39:45 +07:00
parent f8bebde592
commit 1c2bc1dbda
17 changed files with 505 additions and 361 deletions

View file

@ -34,10 +34,9 @@ import CallAPI from "../interfaces/call-api";
import { KpiCapacity } from "../entities/kpiCapacity";
import { Position } from "../entities/position";
import { KpiLink } from "../entities/kpiLink";
import { KpiGroup } from "../entities/kpiGroup";
import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/kpi/user/evaluation")
@Tags("kpiUserEvaluation")
@ -53,7 +52,6 @@ export class KpiUserEvaluationController extends Controller {
private kpiCapacityRepository = AppDataSource.getRepository(KpiCapacity);
private kpiPositionRepository = AppDataSource.getRepository(Position);
private kpiLinkRepository = AppDataSource.getRepository(KpiLink);
private kpiGroupRepository = AppDataSource.getRepository(KpiGroup);
/**
* API
@ -83,7 +81,7 @@ export class KpiUserEvaluationController extends Controller {
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
@ -476,7 +474,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.child4Id = x.child4Id;
isProbation = x.isProbation;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
} else {
@ -503,7 +501,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.child4Id = x.child4Id;
isProbation = x.isProbation;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
}
@ -525,6 +523,8 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.createdFullName = request.user.name;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.createdAt = new Date();
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -642,7 +642,7 @@ export class KpiUserEvaluationController extends Controller {
level: levelForGourp,
weight: 100,
})
.catch((error) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่สามารถสร้างข้อมูลสมรรถนะได้");
});
}
@ -685,6 +685,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -733,6 +734,7 @@ export class KpiUserEvaluationController extends Controller {
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -774,6 +776,7 @@ export class KpiUserEvaluationController extends Controller {
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
Object.assign(kpiUserEvaluation, requestBody);
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -806,6 +809,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.evaluationReqEdit = requestBody.status.trim().toUpperCase();
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
@ -837,6 +841,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.evaluationResults = requestBody.status.trim().toUpperCase();
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
@ -875,8 +880,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
} else if (requestBody.status.trim().toUpperCase() == "EVALUATING_EVALUATOR") {
await new CallAPI()
.PostData(request, "/placement/noti/profile", {
@ -888,13 +893,14 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
}
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.evaluationStatus = requestBody.status.trim().toUpperCase();
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
@ -975,7 +981,7 @@ export class KpiUserEvaluationController extends Controller {
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
const [kpiUserEvaluation, total] = await AppDataSource.getRepository(KpiUserEvaluation)
@ -1064,7 +1070,7 @@ export class KpiUserEvaluationController extends Controller {
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
const list = await this.kpiUserEvalutionRepository.find({
@ -1104,8 +1110,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
item.evaluationStatus = "NEW_COMMANDER";
}
}
@ -1124,8 +1130,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
item.evaluationStatus = "NEW_COMMANDER_HIGH";
}
}
@ -1138,6 +1144,7 @@ export class KpiUserEvaluationController extends Controller {
const before = null;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
item.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(item, { data: request });
setLogDataDiff(request, { before, after: item });
}),
@ -1167,7 +1174,7 @@ export class KpiUserEvaluationController extends Controller {
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
@ -1221,6 +1228,7 @@ export class KpiUserEvaluationController extends Controller {
const before = null;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
item.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(item, { data: request });
setLogDataDiff(request, { before, after: item });
});
@ -1250,7 +1258,7 @@ export class KpiUserEvaluationController extends Controller {
.then((x) => {
profileId = x.profileId;
})
.catch((x) => {
.catch(() => {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลในทะเบียนประวัติ");
});
@ -1301,6 +1309,7 @@ export class KpiUserEvaluationController extends Controller {
const before = null;
item.lastUpdateUserId = request.user.sub;
item.lastUpdateFullName = request.user.name;
item.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(item, { data: request });
setLogDataDiff(request, { before, after: item });
});
@ -1308,7 +1317,7 @@ export class KpiUserEvaluationController extends Controller {
return new HttpSuccess();
}
/**
/**
* API (ADMIN)
*
* @summary (ADMIN)
@ -1380,6 +1389,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.openDate = new Date();
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
@ -1425,8 +1435,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
} else {
await new CallAPI()
@ -1439,8 +1449,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER";
}
const before = structuredClone(kpiUserEvaluation);
@ -1455,6 +1465,7 @@ export class KpiUserEvaluationController extends Controller {
requestBody.reasonEvaluator == null ? _null : requestBody.reasonEvaluator;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
return new HttpSuccess(kpiUserEvaluation.id);
@ -1498,8 +1509,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "COMPLETE";
} else {
await new CallAPI()
@ -1512,8 +1523,8 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
kpiUserEvaluation.evaluationStatus = "SUMMARY_COMMANDER_HIGH";
}
const before = structuredClone(kpiUserEvaluation);
@ -1522,6 +1533,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.reasonCommander = requestBody.reason == null ? _null : requestBody.reason;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -1566,14 +1578,15 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
const before = structuredClone(kpiUserEvaluation);
kpiUserEvaluation.isReasonCommanderHigh = requestBody.isReason;
kpiUserEvaluation.reasonCommanderHigh = requestBody.reason == null ? _null : requestBody.reason;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
@ -1615,7 +1628,7 @@ export class KpiUserEvaluationController extends Controller {
pointSum: kpiUserEvaluation.summaryPoint,
profileId: kpiUserEvaluation.profileId,
})
.then(async (x) => {});
.then(async () => {});
kpiUserEvaluation.kpiUserDevelopments.map(async (kpiUserDevelopment) => {
new CallAPI()
@ -1636,7 +1649,7 @@ export class KpiUserEvaluationController extends Controller {
summary: kpiUserDevelopment.summary,
point: kpiUserDevelopment.point,
})
.then(async (x) => {});
.then(async () => {});
});
new CallAPI()
.PostData(request, "/placement/noti/profile", {
@ -1648,11 +1661,12 @@ export class KpiUserEvaluationController extends Controller {
isSendInbox: true,
isSendNotification: true,
})
.then((x) => {})
.catch((x) => {});
.then(() => {})
.catch(() => {});
const before = null;
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });
}),
@ -1736,6 +1750,7 @@ export class KpiUserEvaluationController extends Controller {
kpiUserEvaluation.evaluationStatus = "SUMMARY";
kpiUserEvaluation.lastUpdateUserId = request.user.sub;
kpiUserEvaluation.lastUpdateFullName = request.user.name;
kpiUserEvaluation.lastUpdatedAt = new Date();
await this.kpiUserEvalutionRepository.save(kpiUserEvaluation, { data: request });
setLogDataDiff(request, { before, after: kpiUserEvaluation });