ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error";
|
|||
import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict";
|
||||
import { District } from "../entities/District";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org/metadata/subDistrict")
|
||||
@Tags("SubDistrict")
|
||||
|
|
@ -78,7 +80,7 @@ export class SubDistrictController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateSubDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _subDistrict = Object.assign(new SubDistrict(), requestBody);
|
||||
if (!_subDistrict) {
|
||||
|
|
@ -102,14 +104,15 @@ export class SubDistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_subDistrict.createdUserId = request.user.sub;
|
||||
_subDistrict.createdFullName = request.user.name;
|
||||
_subDistrict.lastUpdateUserId = request.user.sub;
|
||||
_subDistrict.lastUpdateFullName = request.user.name;
|
||||
_subDistrict.createdAt = new Date();
|
||||
_subDistrict.lastUpdatedAt = new Date();
|
||||
await this.subDistrictRepository.save(_subDistrict);
|
||||
await this.subDistrictRepository.save(_subDistrict, { data: request });
|
||||
setLogDataDiff(request, { before, after: _subDistrict });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +128,7 @@ export class SubDistrictController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateSubDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
|
||||
if (!_subDistrict) {
|
||||
|
|
@ -149,12 +152,13 @@ export class SubDistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_subDistrict.lastUpdateUserId = request.user.sub;
|
||||
_subDistrict.lastUpdateFullName = request.user.name;
|
||||
_subDistrict.lastUpdatedAt = new Date();
|
||||
this.subDistrictRepository.merge(_subDistrict, requestBody);
|
||||
await this.subDistrictRepository.save(_subDistrict);
|
||||
await this.subDistrictRepository.save(_subDistrict, { data: request });
|
||||
setLogDataDiff(request, { before, after: _subDistrict });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue