ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -24,6 +24,7 @@ import {
|
|||
UpdateProfileDiscipline,
|
||||
} from "../entities/ProfileDiscipline";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/discipline")
|
||||
@Tags("ProfileDiscipline")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -66,7 +67,10 @@ export class ProfileDisciplineController extends Controller {
|
|||
}
|
||||
|
||||
@Get("admin/history/{disciplineId}")
|
||||
public async disciplineAdminHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) {
|
||||
public async disciplineAdminHistory(
|
||||
@Path() disciplineId: string,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
const _record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
|
|
@ -87,7 +91,7 @@ export class ProfileDisciplineController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Post()
|
||||
public async newDiscipline(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileDiscipline,
|
||||
|
|
@ -102,7 +106,7 @@ export class ProfileDisciplineController 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 ProfileDiscipline();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -118,9 +122,11 @@ export class ProfileDisciplineController extends Controller {
|
|||
const history = new ProfileDisciplineHistory();
|
||||
Object.assign(history, { ...data, id: undefined });
|
||||
|
||||
await this.disciplineRepository.save(data);
|
||||
await this.disciplineRepository.save(data, { data: req });
|
||||
setLogDataDiff(req, { before, after: data });
|
||||
history.profileDisciplineId = data.id;
|
||||
await this.disciplineHistoryRepository.save(history);
|
||||
await this.disciplineHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -134,7 +140,8 @@ export class ProfileDisciplineController extends Controller {
|
|||
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
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 ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -152,8 +159,10 @@ export class ProfileDisciplineController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
this.disciplineRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.disciplineHistoryRepository.save(history, { data: req }),
|
||||
setLogDataDiff(req, { before, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue