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

@ -26,6 +26,8 @@ import { KpiSpecial } from "../entities/kpiSpecial";
import { KpiRole } from "../entities/kpiRole";
import permission from "../interfaces/permission";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence, setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/kpi/plan")
@Tags("kpiPlan")
@Security("bearerAuth")
@ -177,12 +179,15 @@ export class kpiPlanController extends Controller {
})
.getRawOne();
}
const before = null;
kpiPlan.including = maxIncludingPlan.maxIncluding + 1;
kpiPlan.createdUserId = request.user.sub;
kpiPlan.createdFullName = request.user.name;
kpiPlan.lastUpdateUserId = request.user.sub;
kpiPlan.lastUpdateFullName = request.user.name;
await this.kpiPlanRepository.save(kpiPlan);
await this.kpiPlanRepository.save(kpiPlan, { data: request });
setLogDataDiff(request, { before, after: kpiPlan });
const history = new KpiPlanHistory();
history.kpiPlanId = kpiPlan.id;
@ -190,7 +195,8 @@ export class kpiPlanController extends Controller {
history.createdFullName = request.user.name;
history.lastUpdateUserId = request.user.sub;
history.lastUpdateFullName = request.user.name;
await this.kpiPlanHistoryRepository.save(history);
await this.kpiPlanHistoryRepository.save(history, { data: request });
setLogDataDiff(request, { before: null, after: history });
return new HttpSuccess(kpiPlan.id);
}
@ -267,19 +273,25 @@ export class kpiPlanController extends Controller {
kpiPlan.strategyChild5Id = requestBody.strategy <= 4 ? null : x.strategyChild5Id;
})
.catch((x) => {});
const before = structuredClone(kpiPlan);
kpiPlan.createdUserId = request.user.sub;
kpiPlan.createdFullName = request.user.name;
kpiPlan.lastUpdateUserId = request.user.sub;
kpiPlan.lastUpdateFullName = request.user.name;
await this.kpiPlanRepository.save(kpiPlan);
await this.kpiPlanRepository.save(kpiPlan, { data: request });
setLogDataDiff(request, { before, after: kpiPlan });
const history = new KpiPlanHistory();
history.kpiPlanId = kpiPlan.id;
history.createdUserId = request.user.sub;
history.createdFullName = request.user.name;
history.lastUpdateUserId = request.user.sub;
history.lastUpdateFullName = request.user.name;
await this.kpiPlanHistoryRepository.save(history);
await this.kpiPlanHistoryRepository.save(history, { data: request });
setLogDataDiff(request, { before: null, after: history });
return new HttpSuccess(id);
}
@ -522,7 +534,7 @@ export class kpiPlanController extends Controller {
type = 4;
}
await this.kpiPlanHistoryRepository.delete({ kpiPlanId: id });
await this.kpiPlanRepository.remove(kpiPlan);
await this.kpiPlanRepository.remove(kpiPlan, { data: request });
if (kpiPlan) {
let remainingKpiPlans: any;
@ -579,7 +591,7 @@ export class kpiPlanController extends Controller {
remainingKpiPlans.forEach((kpiPlan: any, index: any) => {
kpiPlan.including = index + 1;
});
await this.kpiPlanRepository.save(remainingKpiPlans);
await this.kpiPlanRepository.save(remainingKpiPlans, { data: request });
}
return new HttpSuccess();