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