log admin , master (ยกเว้น menu ข้อมูลปฎิทินวันหยุด)

This commit is contained in:
AdisakKanthawilang 2024-10-17 16:39:42 +07:00
parent e59f4f13e2
commit f0e5a83d02
11 changed files with 122 additions and 63 deletions

View file

@ -21,6 +21,9 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error";
import { CreatePosExecutive, PosExecutive } from "../entities/PosExecutive";
import { Position } from "../entities/Position";
import { RequestWithUser } from "../middlewares/user";
import { after } from "node:test";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/pos/executive")
@Tags("PosExecutive")
@Security("bearerAuth")
@ -43,7 +46,7 @@ export class PosExecutiveController extends Controller {
async createPosExecutive(
@Body()
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
const checkName = await this.posExecutiveRepository.findOne({
where: { posExecutiveName: requestBody.posExecutiveName },
@ -75,13 +78,15 @@ export class PosExecutiveController extends Controller {
if (_checkPriority) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
}
const before = null;
posExecutive.createdUserId = request.user.sub;
posExecutive.createdFullName = request.user.name;
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
posExecutive.createdAt = new Date();
posExecutive.lastUpdatedAt = new Date();
await this.posExecutiveRepository.save(posExecutive);
await this.posExecutiveRepository.save(posExecutive, {data: request});
setLogDataDiff(request, {before, after: posExecutive});
return new HttpSuccess(posExecutive.id);
}
@ -97,7 +102,7 @@ export class PosExecutiveController extends Controller {
@Path() id: string,
@Body()
requestBody: CreatePosExecutive,
@Request() request: { user: Record<string, any> },
@Request() request: RequestWithUser,
) {
const posExecutive = await this.posExecutiveRepository.findOne({ where: { id: id } });
if (!posExecutive) {
@ -136,13 +141,14 @@ export class PosExecutiveController extends Controller {
if (_checkPriority) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ลำดับนี้มีอยู่ในระบบแล้ว");
}
const before = structuredClone(posExecutive);
posExecutive.posExecutiveName = requestBody.posExecutiveName;
posExecutive.lastUpdateUserId = request.user.sub;
posExecutive.lastUpdateFullName = request.user.name;
posExecutive.lastUpdatedAt = new Date();
// this.posExecutiveRepository.merge(posExecutive, requestBody);
await this.posExecutiveRepository.save(posExecutive);
await this.posExecutiveRepository.save(posExecutive, {data: request});
setLogDataDiff(request, {before, after: posExecutive});
return new HttpSuccess();
}