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