Merge branch 'nice' into develop

# Conflicts:
#	src/controllers/KpiUserCapacityController.ts
#	src/controllers/KpiUserEvaluationController.ts
This commit is contained in:
DESKTOP-1R2VSQH\Lenovo ThinkPad E490 2024-08-22 14:27:49 +07:00
commit dfd9ebb3c1
21 changed files with 526 additions and 236 deletions

View file

@ -25,6 +25,8 @@ import { KpiCapacity } from "../entities/kpiCapacity";
import { Position } from "../entities/position";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/kpi/link")
@Tags("kpiLink")
@Security("bearerAuth")
@ -56,6 +58,7 @@ export class kpiLinkController extends Controller {
if (!chkkpiGroup) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
const before = null;
const kpiLink = Object.assign(new KpiLink(), requestBody, {
createdUserId: request.user.sub,
@ -64,7 +67,8 @@ export class kpiLinkController extends Controller {
lastUpdateFullName: request.user.name,
kpiGroup: chkkpiGroup,
});
await this.kpiLinkRepository.save(kpiLink);
await this.kpiLinkRepository.save(kpiLink, { data: request });
setLogDataDiff(request, { before, after: kpiLink });
if (requestBody.positions != null) {
await Promise.all(
@ -76,7 +80,8 @@ export class kpiLinkController extends Controller {
position.createdFullName = request.user.name;
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
await this.positionRepository.save(position);
await this.positionRepository.save(position, { data: request });
setLogDataDiff(request, { before, after: position });
}),
);
}
@ -91,7 +96,8 @@ export class kpiLinkController extends Controller {
}
kpiLink.kpiCapacitys = chkCapacity;
await this.kpiLinkRepository.save(kpiLink);
await this.kpiLinkRepository.save(kpiLink, { data: request });
setLogDataDiff(request, { before, after: kpiLink });
return new HttpSuccess(kpiLink.id);
}
@ -119,8 +125,9 @@ export class kpiLinkController extends Controller {
if (!chkKpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
const before = structuredClone(chkKpiLink);
await this.positionRepository.remove(chkKpiLink.positions);
await this.positionRepository.remove(chkKpiLink.positions, { data: request });
Object.assign(chkKpiLink, {
...requestBody,
kpiCapacitys: [],
@ -139,7 +146,8 @@ export class kpiLinkController extends Controller {
position.createdFullName = request.user.name;
position.lastUpdateUserId = request.user.sub;
position.lastUpdateFullName = request.user.name;
await this.positionRepository.save(position);
await this.positionRepository.save(position, { data: request });
setLogDataDiff(request, { before: null, after: position });
}),
);
}
@ -154,7 +162,8 @@ export class kpiLinkController extends Controller {
}
chkKpiLink.kpiCapacitys = chkCapacity;
await this.kpiLinkRepository.save(chkKpiLink);
await this.kpiLinkRepository.save(chkKpiLink, { data: request });
setLogDataDiff(request, { before, after: chkKpiLink });
return new HttpSuccess(chkKpiLink.id);
}
@ -208,8 +217,9 @@ export class kpiLinkController extends Controller {
if (!kpiLink) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลการเชื่อมโยง");
}
kpiLink.kpiCapacitys = [];
await this.kpiLinkRepository.save(kpiLink);
await this.kpiLinkRepository.save(kpiLink, { data: request });
await this.positionRepository.delete({ kpiLinkId: id });
await this.kpiLinkRepository.delete({ id: id });