ผูก log เมนูทะเบียนประวัติ

This commit is contained in:
AdisakKanthawilang 2024-10-03 15:57:44 +07:00
parent 5643cc67c4
commit 6539804937
76 changed files with 909 additions and 431 deletions

View file

@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/certificate")
@Tags("ProfileCertificate")
@Security("bearerAuth")
@ -56,7 +57,10 @@ export class ProfileCertificateController extends Controller {
}
@Get("admin/history/{certificateId}")
public async certificateAdminHistory(@Path() certificateId: string, @Request() req: RequestWithUser) {
public async certificateAdminHistory(
@Path() certificateId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.certificateRepo.findOneBy({ id: certificateId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
@ -96,7 +100,7 @@ export class ProfileCertificateController 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 ProfileCertificate();
const meta = {
@ -112,9 +116,11 @@ export class ProfileCertificateController extends Controller {
const history = new ProfileCertificateHistory();
Object.assign(history, { ...data, id: undefined });
await this.certificateRepo.save(data);
await this.certificateRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileCertificateId = data.id;
await this.certificateHistoryRepo.save(history);
await this.certificateHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess();
}
@ -128,7 +134,8 @@ export class ProfileCertificateController extends Controller {
const record = await this.certificateRepo.findOneBy({ id: certificateId });
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 ProfileCertificateHistory();
Object.assign(record, body);
@ -146,8 +153,10 @@ export class ProfileCertificateController extends Controller {
history.lastUpdatedAt = new Date();
await Promise.all([
this.certificateRepo.save(record),
this.certificateHistoryRepo.save(history),
this.certificateRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.certificateHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess();