ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/duty")
|
||||
@Tags("ProfileDuty")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -65,7 +66,7 @@ export class ProfileDutyController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{dutyId}")
|
||||
public async dutyHistory(@Path() dutyId: string,) {
|
||||
public async dutyHistory(@Path() dutyId: string) {
|
||||
const record = await this.dutyHistoryRepository.find({
|
||||
where: { profileDutyId: dutyId },
|
||||
order: { createdAt: "DESC" },
|
||||
|
|
@ -84,7 +85,7 @@ export class ProfileDutyController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDuty();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -100,10 +101,11 @@ export class ProfileDutyController extends Controller {
|
|||
const history = new ProfileDutyHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
|
||||
await this.dutyRepository.save(data);
|
||||
await this.dutyRepository.save(data, { data: req });
|
||||
setLogDataDiff(req, { before, after: data });
|
||||
history.profileDutyId = data.id;
|
||||
await this.dutyHistoryRepository.save(history);
|
||||
|
||||
await this.dutyHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +118,8 @@ export class ProfileDutyController extends Controller {
|
|||
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -133,7 +136,12 @@ export class ProfileDutyController extends Controller {
|
|||
history.createdAt = new Date();
|
||||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]);
|
||||
await Promise.all([
|
||||
this.dutyRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.dutyHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue