ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -19,6 +19,9 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { request } from "axios";
|
||||
|
||||
@Route("api/v1/org/metadata/prefix")
|
||||
@Tags("Prefix")
|
||||
|
|
@ -78,7 +81,7 @@ export class PrefixController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreatePrefixe,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _prefix = Object.assign(new Prefixe(), requestBody);
|
||||
if (!_prefix) {
|
||||
|
|
@ -93,13 +96,15 @@ export class PrefixController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_prefix.createdUserId = request.user.sub;
|
||||
_prefix.createdFullName = request.user.name;
|
||||
_prefix.lastUpdateUserId = request.user.sub;
|
||||
_prefix.lastUpdateFullName = request.user.name;
|
||||
_prefix.createdAt = new Date();
|
||||
_prefix.lastUpdatedAt = new Date();
|
||||
await this.prefixRepository.save(_prefix);
|
||||
await this.prefixRepository.save(_prefix, { data: request });
|
||||
setLogDataDiff( request, { before, after: _prefix} )
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +120,7 @@ export class PrefixController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdatePrefixe,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _prefix = await this.prefixRepository.findOne({ where: { id: id } });
|
||||
if (!_prefix) {
|
||||
|
|
@ -128,11 +133,13 @@ export class PrefixController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(_prefix);
|
||||
_prefix.lastUpdateUserId = request.user.sub;
|
||||
_prefix.lastUpdateFullName = request.user.name;
|
||||
_prefix.lastUpdatedAt = new Date();
|
||||
this.prefixRepository.merge(_prefix, requestBody);
|
||||
await this.prefixRepository.save(_prefix);
|
||||
await this.prefixRepository.save(_prefix, { data: request });
|
||||
setLogDataDiff(request, { before, after: _prefix });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -144,14 +151,14 @@ export class PrefixController extends Controller {
|
|||
* @param {string} id Id คำนำหน้า
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const _delPrefix = await this.prefixRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!_delPrefix) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำนำหน้าชื่อนี้");
|
||||
}
|
||||
await this.prefixRepository.delete(_delPrefix.id);
|
||||
await this.prefixRepository.remove(_delPrefix,{ data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue