ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { updateName } from "../keycloak";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/changeName")
|
||||
@Tags("ProfileChangeNameEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -81,7 +82,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChangeName();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -97,14 +98,17 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
const history = new ProfileChangeNameHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
|
||||
await this.changeNameRepository.save(data);
|
||||
await this.changeNameRepository.save(data, { data: req });
|
||||
setLogDataDiff( req , {before, after: data});
|
||||
history.profileChangeNameId = data.id;
|
||||
await this.changeNameHistoryRepository.save(history);
|
||||
await this.changeNameHistoryRepository.save(history, { data: req });
|
||||
setLogDataDiff( req , {before, after: history});
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
profile.prefix = body.prefix ?? profile.prefix;
|
||||
await this.profileEmployeeRepo.save(profile);
|
||||
await this.profileEmployeeRepo.save(profile, {data: req});
|
||||
setLogDataDiff( req, {before, after: profile});
|
||||
|
||||
if (profile != null && profile.keycloak != null) {
|
||||
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
|
||||
|
|
@ -126,7 +130,8 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -144,8 +149,10 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
this.changeNameRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.changeNameHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue