ผูก 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 { CreateBloodGroup, BloodGroup } from "../entities/BloodGroup";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
@Route("api/v1/org/metadata/bloodGroup")
|
||||
@Tags("BloodGroup")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +42,7 @@ export class BloodGroupController extends Controller {
|
|||
async createBloodGroup(
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -49,7 +51,7 @@ export class BloodGroupController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
||||
bloodGroup.createdUserId = request.user.sub;
|
||||
bloodGroup.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +59,8 @@ export class BloodGroupController extends Controller {
|
|||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
bloodGroup.lastUpdatedAt = new Date();
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
await this.bloodGroupRepository.save(bloodGroup, { data: request });
|
||||
setLogDataDiff(request, { before, after: bloodGroup });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ export class BloodGroupController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({ where: { id: id } });
|
||||
if (!bloodGroup) {
|
||||
|
|
@ -87,12 +90,13 @@ export class BloodGroupController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(bloodGroup);
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
bloodGroup.lastUpdatedAt = new Date();
|
||||
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
await this.bloodGroupRepository.save(bloodGroup, { data: request });
|
||||
setLogDataDiff(request, { before, after: bloodGroup });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +108,7 @@ export class BloodGroupController extends Controller {
|
|||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteBloodGroup(@Path() id: string) {
|
||||
async deleteBloodGroup(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delBloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
|
@ -112,7 +116,7 @@ export class BloodGroupController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกรุ๊ปเลือดนี้");
|
||||
}
|
||||
|
||||
await this.bloodGroupRepository.delete({ id: id });
|
||||
await this.bloodGroupRepository.remove(delBloodGroup,{ data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue