ผูก log เมนูทะเบียนประวัติ

This commit is contained in:
AdisakKanthawilang 2024-10-03 15:57:44 +07:00
parent 5643cc67c4
commit 6539804937
76 changed files with 909 additions and 431 deletions

View file

@ -9,6 +9,7 @@ import error from "./middlewares/error";
import { AppDataSource } from "./database/data-source"; import { AppDataSource } from "./database/data-source";
import { RegisterRoutes } from "./routes"; import { RegisterRoutes } from "./routes";
import { OrganizationController } from "./controllers/OrganizationController"; import { OrganizationController } from "./controllers/OrganizationController";
import logMiddleware from "./middlewares/logs";
async function main() { async function main() {
await AppDataSource.initialize(); await AppDataSource.initialize();
@ -22,6 +23,7 @@ async function main() {
); );
app.use(express.json()); app.use(express.json());
app.use(express.urlencoded({ extended: true })); app.use(express.urlencoded({ extended: true }));
app.use(logMiddleware);
app.use("/", express.static("static")); app.use("/", express.static("static"));
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument)); app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocument));

View file

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

View file

@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error";
import { District, CreateDistrict, UpdateDistrict } from "../entities/District"; import { District, CreateDistrict, UpdateDistrict } from "../entities/District";
import { Province } from "../entities/Province"; import { Province } from "../entities/Province";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/metadata/district") @Route("api/v1/org/metadata/district")
@Tags("District") @Tags("District")
@ -79,7 +81,7 @@ export class DistrictController extends Controller {
async Post( async Post(
@Body() @Body()
requestBody: CreateDistrict, requestBody: CreateDistrict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _district = Object.assign(new District(), requestBody); const _district = Object.assign(new District(), requestBody);
if (!_district) { if (!_district) {
@ -100,14 +102,15 @@ export class DistrictController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_district.createdUserId = request.user.sub; _district.createdUserId = request.user.sub;
_district.createdFullName = request.user.name; _district.createdFullName = request.user.name;
_district.createdAt = new Date(); _district.createdAt = new Date();
_district.lastUpdateUserId = request.user.sub; _district.lastUpdateUserId = request.user.sub;
_district.lastUpdateFullName = request.user.name; _district.lastUpdateFullName = request.user.name;
_district.lastUpdatedAt = new Date(); _district.lastUpdatedAt = new Date();
await this.districtRepository.save(_district); await this.districtRepository.save(_district, { data: request});
setLogDataDiff(request, { before, after: _district });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -123,7 +126,7 @@ export class DistrictController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateDistrict, requestBody: UpdateDistrict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _district = await this.districtRepository.findOne({ where: { id: id } }); const _district = await this.districtRepository.findOne({ where: { id: id } });
if (!_district) { if (!_district) {
@ -143,12 +146,13 @@ export class DistrictController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(_district);
_district.lastUpdateUserId = request.user.sub; _district.lastUpdateUserId = request.user.sub;
_district.lastUpdateFullName = request.user.name; _district.lastUpdateFullName = request.user.name;
_district.lastUpdatedAt = new Date(); _district.lastUpdatedAt = new Date();
this.districtRepository.merge(_district, requestBody); this.districtRepository.merge(_district, requestBody);
await this.districtRepository.save(_district); await this.districtRepository.save(_district, { data: request });
setLogDataDiff(request, { before, after: _district });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel"; import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/metadata/educationLevel") @Route("api/v1/org/metadata/educationLevel")
@Tags("EducationLevel") @Tags("EducationLevel")
@Security("bearerAuth") @Security("bearerAuth")
@ -40,7 +42,7 @@ export class EducationLevelController extends Controller {
async createEducationLevel( async createEducationLevel(
@Body() @Body()
requestBody: CreateEducationLevel, requestBody: CreateEducationLevel,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const checkName = await this.educationLevelRepository.findOne({ const checkName = await this.educationLevelRepository.findOne({
where: { name: requestBody.name }, where: { name: requestBody.name },
@ -49,7 +51,7 @@ export class EducationLevelController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
const educationLevel = Object.assign(new EducationLevel(), requestBody); const educationLevel = Object.assign(new EducationLevel(), requestBody);
educationLevel.createdUserId = request.user.sub; educationLevel.createdUserId = request.user.sub;
educationLevel.createdFullName = request.user.name; educationLevel.createdFullName = request.user.name;
@ -57,7 +59,8 @@ export class EducationLevelController extends Controller {
educationLevel.lastUpdateUserId = request.user.sub; educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name; educationLevel.lastUpdateFullName = request.user.name;
educationLevel.lastUpdatedAt = new Date(); educationLevel.lastUpdatedAt = new Date();
await this.educationLevelRepository.save(educationLevel); await this.educationLevelRepository.save(educationLevel, { data: request });
setLogDataDiff( request, { before, after: educationLevel } );
return new HttpSuccess(); return new HttpSuccess();
} }
@ -73,7 +76,7 @@ export class EducationLevelController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreateEducationLevel, requestBody: CreateEducationLevel,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const educationLevel = await this.educationLevelRepository.findOne({ where: { id: id } }); const educationLevel = await this.educationLevelRepository.findOne({ where: { id: id } });
if (!educationLevel) { if (!educationLevel) {
@ -87,12 +90,13 @@ export class EducationLevelController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(educationLevel);
educationLevel.lastUpdateUserId = request.user.sub; educationLevel.lastUpdateUserId = request.user.sub;
educationLevel.lastUpdateFullName = request.user.name; educationLevel.lastUpdateFullName = request.user.name;
educationLevel.lastUpdatedAt = new Date(); educationLevel.lastUpdatedAt = new Date();
this.educationLevelRepository.merge(educationLevel, requestBody); this.educationLevelRepository.merge(educationLevel, requestBody);
await this.educationLevelRepository.save(educationLevel); await this.educationLevelRepository.save(educationLevel, { data: request });
setLogDataDiff( request, { before, after: educationLevel } );
return new HttpSuccess(); return new HttpSuccess();
} }
@ -104,14 +108,14 @@ export class EducationLevelController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async deleteEducationLevel(@Path() id: string) { async deleteEducationLevel(@Path() id: string , @Request() request: RequestWithUser) {
const delEducationLevel = await this.educationLevelRepository.findOne({ const delEducationLevel = await this.educationLevelRepository.findOne({
where: { id }, where: { id },
}); });
if (!delEducationLevel) { if (!delEducationLevel) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับการศึกษานี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับการศึกษานี้");
} }
await this.educationLevelRepository.delete({ id: id }); await this.educationLevelRepository.remove(delEducationLevel,{ data: request });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Gender, CreateGender, UpdateGender } from "../entities/Gender"; import { Gender, CreateGender, UpdateGender } from "../entities/Gender";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/metadata/gender") @Route("api/v1/org/metadata/gender")
@Tags("Gender") @Tags("Gender")
@ -79,7 +81,7 @@ export class GenderController extends Controller {
async Post( async Post(
@Body() @Body()
requestBody: CreateGender, requestBody: CreateGender,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _gender = Object.assign(new Gender(), requestBody); const _gender = Object.assign(new Gender(), requestBody);
if (!_gender) { if (!_gender) {
@ -93,14 +95,15 @@ export class GenderController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_gender.createdUserId = request.user.sub; _gender.createdUserId = request.user.sub;
_gender.createdFullName = request.user.name; _gender.createdFullName = request.user.name;
_gender.lastUpdateUserId = request.user.sub; _gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name; _gender.lastUpdateFullName = request.user.name;
_gender.createdAt = new Date(); _gender.createdAt = new Date();
_gender.lastUpdatedAt = new Date(); _gender.lastUpdatedAt = new Date();
await this.genderRepository.save(_gender); await this.genderRepository.save(_gender, { data: request });
setLogDataDiff( request, { before, after: _gender } );
return new HttpSuccess(); return new HttpSuccess();
} }
@ -116,7 +119,7 @@ export class GenderController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateGender, requestBody: UpdateGender,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _gender = await this.genderRepository.findOne({ where: { id: id } }); const _gender = await this.genderRepository.findOne({ where: { id: id } });
if (!_gender) { if (!_gender) {
@ -128,12 +131,13 @@ export class GenderController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(_gender);
_gender.lastUpdateUserId = request.user.sub; _gender.lastUpdateUserId = request.user.sub;
_gender.lastUpdateFullName = request.user.name; _gender.lastUpdateFullName = request.user.name;
_gender.lastUpdatedAt = new Date(); _gender.lastUpdatedAt = new Date();
this.genderRepository.merge(_gender, requestBody); this.genderRepository.merge(_gender, requestBody);
await this.genderRepository.save(_gender); await this.genderRepository.save(_gender, { data: request });
setLogDataDiff( request, { before, after: _gender } );
return new HttpSuccess(); return new HttpSuccess();
} }
@ -145,14 +149,14 @@ export class GenderController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async Delete(@Path() id: string) { async Delete(@Path() id: string, @Request() request: RequestWithUser) {
const _delGender = await this.genderRepository.findOne({ const _delGender = await this.genderRepository.findOne({
where: { id: id }, where: { id: id },
}); });
if (!_delGender) { if (!_delGender) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
} }
await this.genderRepository.delete(_delGender.id); await this.genderRepository.remove(_delGender, {data: request});
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -19,6 +19,9 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe"; import { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
import { request } from "axios";
@Route("api/v1/org/metadata/prefix") @Route("api/v1/org/metadata/prefix")
@Tags("Prefix") @Tags("Prefix")
@ -78,7 +81,7 @@ export class PrefixController extends Controller {
async Post( async Post(
@Body() @Body()
requestBody: CreatePrefixe, requestBody: CreatePrefixe,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _prefix = Object.assign(new Prefixe(), requestBody); const _prefix = Object.assign(new Prefixe(), requestBody);
if (!_prefix) { if (!_prefix) {
@ -93,13 +96,15 @@ export class PrefixController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_prefix.createdUserId = request.user.sub; _prefix.createdUserId = request.user.sub;
_prefix.createdFullName = request.user.name; _prefix.createdFullName = request.user.name;
_prefix.lastUpdateUserId = request.user.sub; _prefix.lastUpdateUserId = request.user.sub;
_prefix.lastUpdateFullName = request.user.name; _prefix.lastUpdateFullName = request.user.name;
_prefix.createdAt = new Date(); _prefix.createdAt = new Date();
_prefix.lastUpdatedAt = 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(); return new HttpSuccess();
} }
@ -115,7 +120,7 @@ export class PrefixController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdatePrefixe, requestBody: UpdatePrefixe,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _prefix = await this.prefixRepository.findOne({ where: { id: id } }); const _prefix = await this.prefixRepository.findOne({ where: { id: id } });
if (!_prefix) { if (!_prefix) {
@ -128,11 +133,13 @@ export class PrefixController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(_prefix);
_prefix.lastUpdateUserId = request.user.sub; _prefix.lastUpdateUserId = request.user.sub;
_prefix.lastUpdateFullName = request.user.name; _prefix.lastUpdateFullName = request.user.name;
_prefix.lastUpdatedAt = new Date(); _prefix.lastUpdatedAt = new Date();
this.prefixRepository.merge(_prefix, requestBody); 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(); return new HttpSuccess();
} }
@ -144,14 +151,14 @@ export class PrefixController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async Delete(@Path() id: string) { async Delete(@Path() id: string, @Request() request: RequestWithUser) {
const _delPrefix = await this.prefixRepository.findOne({ const _delPrefix = await this.prefixRepository.findOne({
where: { id: id }, where: { id: id },
}); });
if (!_delPrefix) { if (!_delPrefix) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำนำหน้าชื่อนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำนำหน้าชื่อนี้");
} }
await this.prefixRepository.delete(_delPrefix.id); await this.prefixRepository.remove(_delPrefix,{ data: request });
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -24,6 +24,7 @@ import HttpError from "../interfaces/http-error";
import HttpStatus from "../interfaces/http-status"; import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/ability") @Route("api/v1/org/profile/ability")
@Tags("ProfileAbility") @Tags("ProfileAbility")
@Security("bearerAuth") @Security("bearerAuth")
@ -66,10 +67,10 @@ export class ProfileAbilityController extends Controller {
@Path() abilityId: string, @Path() abilityId: string,
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
) { ) {
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
} }
const record = await this.profileAbilityHistoryRepo.find({ const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId }, where: { profileAbilityId: abilityId },
@ -83,9 +84,7 @@ export class ProfileAbilityController extends Controller {
} }
@Get("history/{abilityId}") @Get("history/{abilityId}")
public async getProfileAbilityHistory( public async getProfileAbilityHistory(@Path() abilityId: string) {
@Path() abilityId: string,
) {
const record = await this.profileAbilityHistoryRepo.find({ const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId }, where: { profileAbilityId: abilityId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -111,7 +110,7 @@ export class ProfileAbilityController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileAbility(); const data = new ProfileAbility();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -126,10 +125,11 @@ export class ProfileAbilityController extends Controller {
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAbilityRepo.save(data); await this.profileAbilityRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAbilityId = data.id; history.profileAbilityId = data.id;
await this.profileAbilityHistoryRepo.save(history); await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -144,7 +144,8 @@ export class ProfileAbilityController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
const before = structuredClone(record);
// const before_null = null;
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });
@ -160,8 +161,10 @@ export class ProfileAbilityController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAbilityRepo.save(record), this.profileAbilityRepo.save(record, { data: req }),
this.profileAbilityHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAbilityHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/ability") @Route("api/v1/org/profile-employee/ability")
@Tags("ProfileAbilityEmployee") @Tags("ProfileAbilityEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -88,9 +89,7 @@ export class ProfileAbilityEmployeeController extends Controller {
} }
@Get("history/{abilityId}") @Get("history/{abilityId}")
public async getProfileAbilityHistory( public async getProfileAbilityHistory(@Path() abilityId: string) {
@Path() abilityId: string,
) {
const record = await this.profileAbilityHistoryRepo.find({ const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId }, where: { profileAbilityId: abilityId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -115,7 +114,7 @@ export class ProfileAbilityEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileAbility(); const data = new ProfileAbility();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -130,9 +129,11 @@ export class ProfileAbilityEmployeeController extends Controller {
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAbilityRepo.save(data); await this.profileAbilityRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAbilityId = data.id; history.profileAbilityId = data.id;
await this.profileAbilityHistoryRepo.save(history); await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -150,7 +151,8 @@ export class ProfileAbilityEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
Object.assign(record, body); Object.assign(record, body);
@ -168,8 +170,10 @@ export class ProfileAbilityEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAbilityRepo.save(record), this.profileAbilityRepo.save(record, { data: req }),
this.profileAbilityHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAbilityHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import HttpStatus from "../interfaces/http-status";
import HttpSuccess from "../interfaces/http-success"; import HttpSuccess from "../interfaces/http-success";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/ability") @Route("api/v1/org/profile-temp/ability")
@Tags("ProfileAbilityEmployee") @Tags("ProfileAbilityEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -84,9 +85,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
} }
@Get("history/{abilityId}") @Get("history/{abilityId}")
public async getProfileAbilityHistory( public async getProfileAbilityHistory(@Path() abilityId: string) {
@Path() abilityId: string,
) {
const record = await this.profileAbilityHistoryRepo.find({ const record = await this.profileAbilityHistoryRepo.find({
where: { profileAbilityId: abilityId }, where: { profileAbilityId: abilityId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -111,7 +110,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = null;
const data = new ProfileAbility(); const data = new ProfileAbility();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -126,9 +125,11 @@ export class ProfileAbilityEmployeeTempController extends Controller {
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAbilityRepo.save(data); await this.profileAbilityRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAbilityId = data.id; history.profileAbilityId = data.id;
await this.profileAbilityHistoryRepo.save(history); await this.profileAbilityHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -142,7 +143,8 @@ export class ProfileAbilityEmployeeTempController extends Controller {
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
Object.assign(record, body); Object.assign(record, body);
@ -160,8 +162,10 @@ export class ProfileAbilityEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAbilityRepo.save(record), this.profileAbilityRepo.save(record, { data: req }),
this.profileAbilityHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAbilityHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -7,6 +7,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile, ProfileAddressHistory, UpdateProfileAddress } from "../entities/Profile"; import { Profile, ProfileAddressHistory, UpdateProfileAddress } from "../entities/Profile";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/address") @Route("api/v1/org/profile/address")
@Tags("ProfileAddress") @Tags("ProfileAddress")
@Security("bearerAuth") @Security("bearerAuth")
@ -169,7 +170,8 @@ export class ProfileAddressController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const record = await this.profileRepo.findOneBy({ id: profileId }); const record = await this.profileRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAddressHistory(); const history = new ProfileAddressHistory();
Object.assign(record, body); Object.assign(record, body);
@ -187,8 +189,10 @@ export class ProfileAddressController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileRepo.save(record), this.profileRepo.save(record, { data: req }),
this.profileAddressHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAddressHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -8,6 +8,7 @@ import { ProfileAddressHistory } from "../entities/Profile";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/address") @Route("api/v1/org/profile-employee/address")
@Tags("ProfileAddressEmployee") @Tags("ProfileAddressEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -173,7 +174,8 @@ export class ProfileAddressEmployeeController extends Controller {
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId }); const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.id);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAddressHistory(); const history = new ProfileAddressHistory();
Object.assign(record, body); Object.assign(record, body);
@ -191,8 +193,10 @@ export class ProfileAddressEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileEmployeeRepo.save(record), this.profileEmployeeRepo.save(record, { data: req }),
this.profileAddressHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAddressHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -8,6 +8,7 @@ import { ProfileAddressHistory } from "../entities/Profile";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/address") @Route("api/v1/org/profile-temp/address")
@Tags("ProfileAddressEmployee") @Tags("ProfileAddressEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -173,7 +174,8 @@ export class ProfileAddressEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId }); const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAddressHistory(); const history = new ProfileAddressHistory();
Object.assign(record, body); Object.assign(record, body);
@ -191,8 +193,10 @@ export class ProfileAddressEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileEmployeeRepo.save(record), this.profileEmployeeRepo.save(record, { data: req }),
this.profileAddressHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAddressHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/assessments") @Route("api/v1/org/profile/assessments")
@Tags("ProfileAssessments") @Tags("ProfileAssessments")
@Security("bearerAuth") @Security("bearerAuth")
@ -123,7 +124,7 @@ export class ProfileAssessmentsController extends Controller {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileAssessment(); const data = new ProfileAssessment();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -137,9 +138,11 @@ export class ProfileAssessmentsController extends Controller {
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAssessmentsRepository.save(data); await this.profileAssessmentsRepository.save(data, { data: req });
setLogDataDiff( req, { before, after: data } );
history.profileAssessmentId = data.id; history.profileAssessmentId = data.id;
await this.profileAssessmentsHistoryRepository.save(history); await this.profileAssessmentsHistoryRepository.save(history, { data: req });
setLogDataDiff( req, { before, after: history } );
return new HttpSuccess(); return new HttpSuccess();
} }
@ -153,7 +156,8 @@ export class ProfileAssessmentsController extends Controller {
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const before_null = null;
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(record, body); Object.assign(record, body);
@ -171,8 +175,10 @@ export class ProfileAssessmentsController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAssessmentsRepository.save(record), this.profileAssessmentsRepository.save(record, { data: req }),
this.profileAssessmentsHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
setLogDataDiff(req, { before, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/assessments") @Route("api/v1/org/profile-employee/assessments")
@Tags("ProfileEmployeeAssessments") @Tags("ProfileEmployeeAssessments")
@Security("bearerAuth") @Security("bearerAuth")
@ -120,7 +121,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileAssessment(); const data = new ProfileAssessment();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -134,9 +135,11 @@ export class ProfileAssessmentsEmployeeController extends Controller {
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAssessmentsRepository.save(data); await this.profileAssessmentsRepository.save(data, { data: req });
setLogDataDiff( req, { before, after: data });
history.profileAssessmentId = data.id; history.profileAssessmentId = data.id;
await this.profileAssessmentsHistoryRepository.save(history); await this.profileAssessmentsHistoryRepository.save(history, { data: req });
setLogDataDiff( req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -155,6 +158,8 @@ export class ProfileAssessmentsEmployeeController extends Controller {
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(record, body); Object.assign(record, body);
@ -172,8 +177,10 @@ export class ProfileAssessmentsEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAssessmentsRepository.save(record), this.profileAssessmentsRepository.save(record, { data: req }),
this.profileAssessmentsHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/assessments") @Route("api/v1/org/profile-temp/assessments")
@Tags("ProfileEmployeeAssessments") @Tags("ProfileEmployeeAssessments")
@Security("bearerAuth") @Security("bearerAuth")
@ -88,9 +89,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
} }
@Get("history/{assessmentId}") @Get("history/{assessmentId}")
public async getProfileAssessmentsHistory( public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
@Path() assessmentId: string,
) {
const record = await this.profileAssessmentsHistoryRepository.find({ const record = await this.profileAssessmentsHistoryRepository.find({
where: { where: {
profileAssessmentId: assessmentId, profileAssessmentId: assessmentId,
@ -119,7 +118,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileAssessment(); const data = new ProfileAssessment();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -133,9 +132,11 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileAssessmentsRepository.save(data); await this.profileAssessmentsRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileAssessmentId = data.id; history.profileAssessmentId = data.id;
await this.profileAssessmentsHistoryRepository.save(history); await this.profileAssessmentsHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -149,7 +150,8 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
Object.assign(record, body); Object.assign(record, body);
@ -167,8 +169,10 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileAssessmentsRepository.save(record), this.profileAssessmentsRepository.save(record, { data: req }),
this.profileAssessmentsHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/certificate") @Route("api/v1/org/profile/certificate")
@Tags("ProfileCertificate") @Tags("ProfileCertificate")
@Security("bearerAuth") @Security("bearerAuth")
@ -56,7 +57,10 @@ export class ProfileCertificateController extends Controller {
} }
@Get("admin/history/{certificateId}") @Get("admin/history/{certificateId}")
public async certificateAdminHistory(@Path() certificateId: string, @Request() req: RequestWithUser) { public async certificateAdminHistory(
@Path() certificateId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.certificateRepo.findOneBy({ id: certificateId }); const _record = await this.certificateRepo.findOneBy({ id: certificateId });
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
@ -96,7 +100,7 @@ export class ProfileCertificateController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileCertificate(); const data = new ProfileCertificate();
const meta = { const meta = {
@ -112,9 +116,11 @@ export class ProfileCertificateController extends Controller {
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.certificateRepo.save(data); await this.certificateRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileCertificateId = data.id; history.profileCertificateId = data.id;
await this.certificateHistoryRepo.save(history); await this.certificateHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -128,7 +134,8 @@ export class ProfileCertificateController extends Controller {
const record = await this.certificateRepo.findOneBy({ id: certificateId }); const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(record, body); Object.assign(record, body);
@ -146,8 +153,10 @@ export class ProfileCertificateController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.certificateRepo.save(record), this.certificateRepo.save(record, { data: req }),
this.certificateHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.certificateHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/certificate") @Route("api/v1/org/profile-employee/certificate")
@Tags("ProfileEmployeeCertificate") @Tags("ProfileEmployeeCertificate")
@Security("bearerAuth") @Security("bearerAuth")
@ -56,7 +57,10 @@ export class ProfileCertificateEmployeeController extends Controller {
} }
@Get("admin/history/{certificateId}") @Get("admin/history/{certificateId}")
public async certificateAdminHistory(@Path() certificateId: string, @Request() req: RequestWithUser) { public async certificateAdminHistory(
@Path() certificateId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.certificateRepo.findOneBy({ id: certificateId }); const _record = await this.certificateRepo.findOneBy({ id: certificateId });
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet( await new permission().PermissionOrgUserGet(
@ -100,6 +104,7 @@ export class ProfileCertificateEmployeeController extends Controller {
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileCertificate(); const data = new ProfileCertificate();
const meta = { const meta = {
@ -115,9 +120,11 @@ export class ProfileCertificateEmployeeController extends Controller {
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.certificateRepo.save(data); await this.certificateRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileCertificateId = data.id; history.profileCertificateId = data.id;
await this.certificateHistoryRepo.save(history); await this.certificateHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -135,7 +142,8 @@ export class ProfileCertificateEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(record, body); Object.assign(record, body);
@ -153,8 +161,10 @@ export class ProfileCertificateEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.certificateRepo.save(record), this.certificateRepo.save(record, { data: req }),
this.certificateHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.certificateHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/certificate") @Route("api/v1/org/profile-temp/certificate")
@Tags("ProfileEmployeeCertificate") @Tags("ProfileEmployeeCertificate")
@Security("bearerAuth") @Security("bearerAuth")
@ -87,7 +88,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const before = null;
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
@ -109,9 +110,11 @@ export class ProfileCertificateEmployeeTempController extends Controller {
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.certificateRepo.save(data); await this.certificateRepo.save(data, { data: req });
setLogDataDiff( req , {before, after: data});
history.profileCertificateId = data.id; history.profileCertificateId = data.id;
await this.certificateHistoryRepo.save(history); await this.certificateHistoryRepo.save(history, { data: req });
setLogDataDiff( req , {before, after: history});
return new HttpSuccess(); return new HttpSuccess();
} }
@ -126,7 +129,8 @@ export class ProfileCertificateEmployeeTempController extends Controller {
const record = await this.certificateRepo.findOneBy({ id: certificateId }); const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const before_null = null;
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
Object.assign(record, body); Object.assign(record, body);
@ -144,8 +148,10 @@ export class ProfileCertificateEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.certificateRepo.save(record), this.certificateRepo.save(record, { data: req }),
this.certificateHistoryRepo.save(history), setLogDataDiff( req , {before, after: record}),
this.certificateHistoryRepo.save(history, { data: req }),
setLogDataDiff( req , {before: before_null, after: history}),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileChangeName"; } from "../entities/ProfileChangeName";
import { updateName } from "../keycloak"; import { updateName } from "../keycloak";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/changeName") @Route("api/v1/org/profile/changeName")
@Tags("ProfileChangeName") @Tags("ProfileChangeName")
@Security("bearerAuth") @Security("bearerAuth")
@ -83,7 +84,7 @@ export class ProfileChangeNameController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileChangeName(); const data = new ProfileChangeName();
const meta = { const meta = {
@ -101,12 +102,13 @@ export class ProfileChangeNameController extends Controller {
await this.changeNameRepository.save(data); await this.changeNameRepository.save(data);
history.profileChangeNameId = data.id; history.profileChangeNameId = data.id;
await this.changeNameHistoryRepository.save(history); await this.changeNameHistoryRepository.save(history, { data: req });
setLogDataDiff( req, { before, after: history })
profile.firstName = body.firstName ?? profile.firstName; profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName; profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix; profile.prefix = body.prefix ?? profile.prefix;
await this.profileRepository.save(profile); await this.profileRepository.save(profile, { data:req });
setLogDataDiff(req, { before, after: profile });
if (profile != null && profile.keycloak != null) { if (profile != null && profile.keycloak != null) {
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
@ -127,7 +129,8 @@ export class ProfileChangeNameController extends Controller {
const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const before_null = null;
const history = new ProfileChangeNameHistory(); const history = new ProfileChangeNameHistory();
Object.assign(record, body); Object.assign(record, body);
@ -145,8 +148,10 @@ export class ProfileChangeNameController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.changeNameRepository.save(record), this.changeNameRepository.save(record, { data: req }),
this.changeNameHistoryRepository.save(history), setLogDataDiff( req , {before, after: record}),
this.changeNameHistoryRepository.save(history, { data: req }),
setLogDataDiff( req , {before: before_null, after: history}),
]); ]);
const chkLastRecord = await this.changeNameRepository.findOne({ const chkLastRecord = await this.changeNameRepository.findOne({
@ -160,12 +165,13 @@ export class ProfileChangeNameController extends Controller {
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const profile = await this.profileRepository.findOneBy({ id: record.profileId }); const profile = await this.profileRepository.findOneBy({ id: record.profileId });
const before_profile = structuredClone(profile);
if (profile && chkLastRecord.id === record.id) { if (profile && chkLastRecord.id === record.id) {
profile.firstName = body.firstName ?? profile.firstName; profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName; profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix; profile.prefix = body.prefix ?? profile.prefix;
await this.profileRepository.save(profile); await this.profileRepository.save(profile, { data: req });
setLogDataDiff( req , {before: before_profile, after: profile});
} }
// ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07 // ปิดไว้ก่อนเพราะ error ต้องใช้ keycloak ที่มีสิทธิ์ในการ update //update 17/07

View file

@ -25,6 +25,7 @@ import {
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { updateName } from "../keycloak"; import { updateName } from "../keycloak";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/changeName") @Route("api/v1/org/profile-employee/changeName")
@Tags("ProfileChangeNameEmployee") @Tags("ProfileChangeNameEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -87,7 +88,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileChangeName(); const data = new ProfileChangeName();
const meta = { const meta = {
@ -103,14 +104,17 @@ export class ProfileChangeNameEmployeeController extends Controller {
const history = new ProfileChangeNameHistory(); const history = new ProfileChangeNameHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.changeNameRepository.save(data); await this.changeNameRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileChangeNameId = data.id; history.profileChangeNameId = data.id;
await this.changeNameHistoryRepository.save(history); await this.changeNameHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
profile.firstName = body.firstName ?? profile.firstName; profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName; profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix; profile.prefix = body.prefix ?? profile.prefix;
await this.profileEmployeeRepo.save(profile); await this.profileEmployeeRepo.save(profile, { data: req });
setLogDataDiff(req, { before, after: profile });
if (profile != null && profile.keycloak != null) { if (profile != null && profile.keycloak != null) {
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);

View file

@ -25,6 +25,7 @@ import {
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { updateName } from "../keycloak"; import { updateName } from "../keycloak";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/changeName") @Route("api/v1/org/profile-temp/changeName")
@Tags("ProfileChangeNameEmployee") @Tags("ProfileChangeNameEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -81,7 +82,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileChangeName(); const data = new ProfileChangeName();
const meta = { const meta = {
@ -97,14 +98,17 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
const history = new ProfileChangeNameHistory(); const history = new ProfileChangeNameHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.changeNameRepository.save(data); await this.changeNameRepository.save(data, { data: req });
setLogDataDiff( req , {before, after: data});
history.profileChangeNameId = data.id; history.profileChangeNameId = data.id;
await this.changeNameHistoryRepository.save(history); await this.changeNameHistoryRepository.save(history, { data: req });
setLogDataDiff( req , {before, after: history});
profile.firstName = body.firstName ?? profile.firstName; profile.firstName = body.firstName ?? profile.firstName;
profile.lastName = body.lastName ?? profile.lastName; profile.lastName = body.lastName ?? profile.lastName;
profile.prefix = body.prefix ?? profile.prefix; profile.prefix = body.prefix ?? profile.prefix;
await this.profileEmployeeRepo.save(profile); await this.profileEmployeeRepo.save(profile, {data: req});
setLogDataDiff( req, {before, after: profile});
if (profile != null && profile.keycloak != null) { if (profile != null && profile.keycloak != null) {
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName); const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
@ -126,7 +130,8 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileChangeNameHistory(); const history = new ProfileChangeNameHistory();
Object.assign(record, body); Object.assign(record, body);
@ -144,8 +149,10 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.changeNameRepository.save(record), this.changeNameRepository.save(record, { data: req }),
this.changeNameHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.changeNameHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
const chkLastRecord = await this.changeNameRepository.findOne({ const chkLastRecord = await this.changeNameRepository.findOne({

View file

@ -25,6 +25,7 @@ import {
} from "../entities/ProfileChildren"; } from "../entities/ProfileChildren";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/children") @Route("api/v1/org/profile/family/children")
@Tags("ProfileChildren") @Tags("ProfileChildren")
@Security("bearerAuth") @Security("bearerAuth")
@ -76,7 +77,7 @@ export class ProfileChildrenController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileChildren(); const data = new ProfileChildren();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -93,9 +94,11 @@ export class ProfileChildrenController extends Controller {
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.childrenRepository.save(data); await this.childrenRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileChildrenId = data.id; history.profileChildrenId = data.id;
await this.childrenHistoryRepository.save(history); await this.childrenHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -109,7 +112,8 @@ export class ProfileChildrenController extends Controller {
const record = await this.childrenRepository.findOneBy({ id: childrenId }); const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });
@ -126,8 +130,10 @@ export class ProfileChildrenController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.childrenRepository.save(record), this.childrenRepository.save(record, { data: req }),
this.childrenHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.childrenHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/family/children") @Route("api/v1/org/profile-employee/family/children")
@Tags("ProfileChildren") @Tags("ProfileChildren")
@Security("bearerAuth") @Security("bearerAuth")
@ -83,7 +84,7 @@ export class ProfileChildrenEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileChildren(); const data = new ProfileChildren();
const meta = { const meta = {
@ -101,10 +102,11 @@ export class ProfileChildrenEmployeeController extends Controller {
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.childrenRepository.save(data); await this.childrenRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileChildrenId = data.id; history.profileChildrenId = data.id;
await this.childrenHistoryRepository.save(history); await this.childrenHistoryRepository.save(history, { data: req });
setLogDataDiff( req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -121,7 +123,8 @@ export class ProfileChildrenEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });
@ -139,8 +142,10 @@ export class ProfileChildrenEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.childrenRepository.save(record), this.childrenRepository.save(record, { data: req }),
this.childrenHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.childrenHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/family/children") @Route("api/v1/org/profile-temp/family/children")
@Tags("ProfileChildren") @Tags("ProfileChildren")
@Security("bearerAuth") @Security("bearerAuth")
@ -77,7 +78,7 @@ export class ProfileChildrenEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileChildren(); const data = new ProfileChildren();
const meta = { const meta = {
@ -94,9 +95,11 @@ export class ProfileChildrenEmployeeTempController extends Controller {
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.childrenRepository.save(data); await this.childrenRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileChildrenId = data.id; history.profileChildrenId = data.id;
await this.childrenHistoryRepository.save(history); await this.childrenHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -110,7 +113,8 @@ export class ProfileChildrenEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.childrenRepository.findOneBy({ id: childrenId }); const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });
@ -128,8 +132,10 @@ export class ProfileChildrenEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.childrenRepository.save(record), this.childrenRepository.save(record, { data: req }),
this.childrenHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.childrenHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
UpdateProfileDiscipline, UpdateProfileDiscipline,
} from "../entities/ProfileDiscipline"; } from "../entities/ProfileDiscipline";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/discipline") @Route("api/v1/org/profile/discipline")
@Tags("ProfileDiscipline") @Tags("ProfileDiscipline")
@Security("bearerAuth") @Security("bearerAuth")
@ -66,7 +67,10 @@ export class ProfileDisciplineController extends Controller {
} }
@Get("admin/history/{disciplineId}") @Get("admin/history/{disciplineId}")
public async disciplineAdminHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { public async disciplineAdminHistory(
@Path() disciplineId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const _record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
@ -102,7 +106,7 @@ export class ProfileDisciplineController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileDiscipline(); const data = new ProfileDiscipline();
const meta = { const meta = {
@ -118,9 +122,11 @@ export class ProfileDisciplineController extends Controller {
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.disciplineRepository.save(data); await this.disciplineRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDisciplineId = data.id; history.profileDisciplineId = data.id;
await this.disciplineHistoryRepository.save(history); await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -134,7 +140,8 @@ export class ProfileDisciplineController extends Controller {
const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const before_null = null;
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(record, body); Object.assign(record, body);
@ -152,8 +159,10 @@ export class ProfileDisciplineController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.disciplineRepository.save(record), this.disciplineRepository.save(record, { data: req }),
this.disciplineHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.disciplineHistoryRepository.save(history, { data: req }),
setLogDataDiff(req, { before, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
} from "../entities/ProfileDiscipline"; } from "../entities/ProfileDiscipline";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/discipline") @Route("api/v1/org/profile-employee/discipline")
@Tags("ProfileDisciplineEmployee") @Tags("ProfileDisciplineEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -66,7 +67,10 @@ export class ProfileDisciplineEmployeeController extends Controller {
} }
@Get("admin/history/{disciplineId}") @Get("admin/history/{disciplineId}")
public async disciplineAdminHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { public async disciplineAdminHistory(
@Path() disciplineId: string,
@Request() req: RequestWithUser,
) {
const _record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const _record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet( await new permission().PermissionOrgUserGet(
@ -105,7 +109,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileDiscipline(); const data = new ProfileDiscipline();
const meta = { const meta = {
@ -121,10 +125,11 @@ export class ProfileDisciplineEmployeeController extends Controller {
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.disciplineRepository.save(data); await this.disciplineRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDisciplineId = data.id; history.profileDisciplineId = data.id;
await this.disciplineHistoryRepository.save(history); await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -141,7 +146,8 @@ export class ProfileDisciplineEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(record, body); Object.assign(record, body);
@ -159,8 +165,10 @@ export class ProfileDisciplineEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.disciplineRepository.save(record), this.disciplineRepository.save(record, { data: req }),
this.disciplineHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.disciplineHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
} from "../entities/ProfileDiscipline"; } from "../entities/ProfileDiscipline";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/discipline") @Route("api/v1/org/profile-temp/discipline")
@Tags("ProfileDisciplineEmployee") @Tags("ProfileDisciplineEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -66,7 +67,10 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
} }
@Get("admin/history/{disciplineId}") @Get("admin/history/{disciplineId}")
public async disciplineAdminHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) { public async disciplineAdminHistory(
@Path() disciplineId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionGet(req, "SYS_REGISTRY_TEMP");
const record = await this.disciplineHistoryRepository.find({ const record = await this.disciplineHistoryRepository.find({
where: { profileDisciplineId: disciplineId }, where: { profileDisciplineId: disciplineId },
@ -99,7 +103,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileDiscipline(); const data = new ProfileDiscipline();
const meta = { const meta = {
@ -115,9 +119,11 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.disciplineRepository.save(data); await this.disciplineRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDisciplineId = data.id; history.profileDisciplineId = data.id;
await this.disciplineHistoryRepository.save(history); await this.disciplineHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -132,7 +138,8 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
Object.assign(record, body); Object.assign(record, body);
@ -150,8 +157,10 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.disciplineRepository.save(record), this.disciplineRepository.save(record, { data: req }),
this.disciplineHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.disciplineHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/duty") @Route("api/v1/org/profile/duty")
@Tags("ProfileDuty") @Tags("ProfileDuty")
@Security("bearerAuth") @Security("bearerAuth")
@ -65,7 +66,7 @@ export class ProfileDutyController extends Controller {
} }
@Get("history/{dutyId}") @Get("history/{dutyId}")
public async dutyHistory(@Path() dutyId: string,) { public async dutyHistory(@Path() dutyId: string) {
const record = await this.dutyHistoryRepository.find({ const record = await this.dutyHistoryRepository.find({
where: { profileDutyId: dutyId }, where: { profileDutyId: dutyId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -84,7 +85,7 @@ export class ProfileDutyController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileDuty(); const data = new ProfileDuty();
const meta = { const meta = {
@ -100,10 +101,11 @@ export class ProfileDutyController extends Controller {
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.dutyRepository.save(data); await this.dutyRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDutyId = data.id; history.profileDutyId = data.id;
await this.dutyHistoryRepository.save(history); await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -116,7 +118,8 @@ export class ProfileDutyController extends Controller {
const record = await this.dutyRepository.findOneBy({ id: dutyId }); const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(record, body); Object.assign(record, body);
@ -133,7 +136,12 @@ export class ProfileDutyController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]); await Promise.all([
this.dutyRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.dutyHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/duty") @Route("api/v1/org/profile-employee/duty")
@Tags("ProfileEmployeeDuty") @Tags("ProfileEmployeeDuty")
@Security("bearerAuth") @Security("bearerAuth")
@ -88,7 +89,7 @@ export class ProfileDutyEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileDuty(); const data = new ProfileDuty();
const meta = { const meta = {
@ -104,9 +105,11 @@ export class ProfileDutyEmployeeController extends Controller {
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.dutyRepository.save(data); await this.dutyRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDutyId = data.id; history.profileDutyId = data.id;
await this.dutyHistoryRepository.save(history); await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -124,7 +127,8 @@ export class ProfileDutyEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const before_null = null;
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(record, body); Object.assign(record, body);
@ -141,7 +145,12 @@ export class ProfileDutyEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]); await Promise.all([
this.dutyRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.dutyHistoryRepository.save(history, { data: req }),
setLogDataDiff(req, { before, after: history }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty"; import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/duty") @Route("api/v1/org/profile-temp/duty")
@Tags("ProfileEmployeeDuty") @Tags("ProfileEmployeeDuty")
@Security("bearerAuth") @Security("bearerAuth")
@ -82,7 +83,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileDuty(); const data = new ProfileDuty();
const meta = { const meta = {
@ -98,9 +99,11 @@ export class ProfileDutyEmployeeTempController extends Controller {
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.dutyRepository.save(data); await this.dutyRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileDutyId = data.id; history.profileDutyId = data.id;
await this.dutyHistoryRepository.save(history); await this.dutyHistoryRepository.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -115,7 +118,8 @@ export class ProfileDutyEmployeeTempController extends Controller {
const record = await this.dutyRepository.findOneBy({ id: dutyId }); const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
Object.assign(record, body); Object.assign(record, body);
@ -132,7 +136,12 @@ export class ProfileDutyEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.dutyRepository.save(record), this.dutyHistoryRepository.save(history)]); await Promise.all([
this.dutyRepository.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.dutyHistoryRepository.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -26,6 +26,7 @@ import { Profile } from "../entities/Profile";
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory"; import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/educations") @Route("api/v1/org/profile/educations")
@Tags("ProfileEducations") @Tags("ProfileEducations")
@Security("bearerAuth") @Security("bearerAuth")
@ -85,9 +86,7 @@ export class ProfileEducationsController extends Controller {
} }
@Get("history/{educationId}") @Get("history/{educationId}")
public async getProfileEducationHistory( public async getProfileEducationHistory(@Path() educationId: string) {
@Path() educationId: string,
) {
const record = await this.profileEducationHistoryRepo.find({ const record = await this.profileEducationHistoryRepo.find({
where: { where: {
profileEducationId: educationId, profileEducationId: educationId,
@ -114,7 +113,7 @@ export class ProfileEducationsController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileEducation(); const data = new ProfileEducation();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -129,9 +128,11 @@ export class ProfileEducationsController extends Controller {
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileEducationRepo.save(data); await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id; history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history); await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -145,7 +146,8 @@ export class ProfileEducationsController extends Controller {
const record = await this.profileEducationRepo.findOneBy({ id: educationId }); const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(record, body); Object.assign(record, body);
@ -163,8 +165,10 @@ export class ProfileEducationsController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileEducationRepo.save(record), this.profileEducationRepo.save(record, { data: req }),
this.profileEducationHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileEducationHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/educations") @Route("api/v1/org/profile-employee/educations")
@Tags("ProfileEducationsEmployee") @Tags("ProfileEducationsEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -91,9 +92,7 @@ export class ProfileEducationsEmployeeController extends Controller {
} }
@Get("history/{educationId}") @Get("history/{educationId}")
public async getProfileEducationHistory( public async getProfileEducationHistory(@Path() educationId: string) {
@Path() educationId: string,
) {
const record = await this.profileEducationHistoryRepo.find({ const record = await this.profileEducationHistoryRepo.find({
where: { where: {
profileEducationId: educationId, profileEducationId: educationId,
@ -120,7 +119,7 @@ export class ProfileEducationsEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileEducation(); const data = new ProfileEducation();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -135,9 +134,11 @@ export class ProfileEducationsEmployeeController extends Controller {
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileEducationRepo.save(data); await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id; history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history); await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -155,7 +156,8 @@ export class ProfileEducationsEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const before_null = null;
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(record, body); Object.assign(record, body);
@ -173,8 +175,10 @@ export class ProfileEducationsEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileEducationRepo.save(record), this.profileEducationRepo.save(record, { data: req }),
this.profileEducationHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileEducationHistoryRepo.save(history, { data: req }),
setLogDataDiff(req, { before, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
import { AppDataSource } from "../database/data-source"; import { AppDataSource } from "../database/data-source";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/educations") @Route("api/v1/org/profile-temp/educations")
@Tags("ProfileEducationsEmployee") @Tags("ProfileEducationsEmployee")
@Security("bearerAuth") @Security("bearerAuth")
@ -83,9 +84,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
} }
@Get("history/{educationId}") @Get("history/{educationId}")
public async getProfileEducationHistory( public async getProfileEducationHistory(@Path() educationId: string) {
@Path() educationId: string,
) {
const record = await this.profileEducationHistoryRepo.find({ const record = await this.profileEducationHistoryRepo.find({
where: { where: {
profileEducationId: educationId, profileEducationId: educationId,
@ -112,7 +111,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileEducation(); const data = new ProfileEducation();
const meta = { const meta = {
createdUserId: req.user.sub, createdUserId: req.user.sub,
@ -127,10 +126,11 @@ export class ProfileEducationsEmployeeTempController extends Controller {
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.profileEducationRepo.save(data); await this.profileEducationRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileEducationId = data.id; history.profileEducationId = data.id;
await this.profileEducationHistoryRepo.save(history); await this.profileEducationHistoryRepo.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -143,7 +143,8 @@ export class ProfileEducationsEmployeeTempController extends Controller {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const record = await this.profileEducationRepo.findOneBy({ id: educationId }); const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
// const before_null = null;
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
Object.assign(record, body); Object.assign(record, body);
@ -161,8 +162,10 @@ export class ProfileEducationsEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.profileEducationRepo.save(record), this.profileEducationRepo.save(record, { data: req }),
this.profileEducationHistoryRepo.save(history), setLogDataDiff(req, { before, after: record }),
this.profileEducationHistoryRepo.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/couple") @Route("api/v1/org/profile/family/couple")
@Tags("ProfileFamilyCouple") @Tags("ProfileFamilyCouple")
@Security("bearerAuth") @Security("bearerAuth")
@ -165,6 +166,7 @@ export class ProfileFamilyCoupleController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.createdUserId = req.user.sub; familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name; familyCouple.createdFullName = req.user.name;
@ -177,11 +179,13 @@ export class ProfileFamilyCoupleController extends Controller {
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
await this.profileRepo.save(profile); await this.profileRepo.save(profile, { data: req });
await this.ProfileFamilyCouple.save(familyCouple); setLogDataDiff(req, { before, after: profile });
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
setLogDataDiff(req, { before, after: familyCouple });
history.profileFamilyCoupleId = familyCouple.id; history.profileFamilyCoupleId = familyCouple.id;
await this.ProfileFamilyCoupleHistory.save(history); await this.ProfileFamilyCoupleHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyCouple.id); return new HttpSuccess(familyCouple.id);
} }
@ -194,7 +198,8 @@ export class ProfileFamilyCoupleController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId }); const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyCouple);
// const before_null = null;
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(familyCouple, body); Object.assign(familyCouple, body);
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
@ -212,8 +217,10 @@ export class ProfileFamilyCoupleController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyCouple.save(familyCouple), this.ProfileFamilyCouple.save(familyCouple, { data: req }),
this.ProfileFamilyCoupleHistory.save(history), setLogDataDiff(req, { before, after: familyCouple }),
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/family/couple") @Route("api/v1/org/profile-employee/family/couple")
@Tags("ProfileEmployeeFamilyCouple") @Tags("ProfileEmployeeFamilyCouple")
@Security("bearerAuth") @Security("bearerAuth")
@ -168,7 +169,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.createdUserId = req.user.sub; familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name; familyCouple.createdFullName = req.user.name;
@ -181,10 +182,13 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
await this.profileRepo.save(profile); await this.profileRepo.save(profile, { data: req });
await this.ProfileFamilyCouple.save(familyCouple); setLogDataDiff(req, { before, after: profile });
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
setLogDataDiff(req, { before, after: familyCouple });
history.profileFamilyCoupleId = familyCouple.id; history.profileFamilyCoupleId = familyCouple.id;
await this.ProfileFamilyCoupleHistory.save(history); await this.ProfileFamilyCoupleHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyCouple.id); return new HttpSuccess(familyCouple.id);
} }
@ -200,7 +204,8 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyCouple);
// const before_null = null;
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(familyCouple, body); Object.assign(familyCouple, body);
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
@ -218,8 +223,10 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyCouple.save(familyCouple), this.ProfileFamilyCouple.save(familyCouple, { data: req }),
this.ProfileFamilyCoupleHistory.save(history), setLogDataDiff(req, { before, after: familyCouple }),
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory"; import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/family/couple") @Route("api/v1/org/profile-temp/family/couple")
@Tags("ProfileEmployeeFamilyCouple") @Tags("ProfileEmployeeFamilyCouple")
@Security("bearerAuth") @Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
@Body() body: CreateProfileEmployeeFamilyCouple, @Body() body: CreateProfileEmployeeFamilyCouple,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP"); await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
const before = null;
const familyCouple = Object.assign(new ProfileFamilyCouple(), body); const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) { if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -182,10 +184,13 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
await this.profileRepo.save(profile); await this.profileRepo.save(profile, { data: req });
await this.ProfileFamilyCouple.save(familyCouple); setLogDataDiff(req, { before, after: profile });
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
setLogDataDiff(req, { before, after: familyCouple });
history.profileFamilyCoupleId = familyCouple.id; history.profileFamilyCoupleId = familyCouple.id;
await this.ProfileFamilyCoupleHistory.save(history); await this.ProfileFamilyCoupleHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyCouple.id); return new HttpSuccess(familyCouple.id);
} }
@ -201,7 +206,8 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyCouple);
// const before_null = null;
const history = new ProfileFamilyCoupleHistory(); const history = new ProfileFamilyCoupleHistory();
Object.assign(familyCouple, body); Object.assign(familyCouple, body);
Object.assign(history, { ...familyCouple, id: undefined }); Object.assign(history, { ...familyCouple, id: undefined });
@ -219,8 +225,10 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyCouple.save(familyCouple), this.ProfileFamilyCouple.save(familyCouple, { data: req }),
this.ProfileFamilyCoupleHistory.save(history), setLogDataDiff(req, { before, after: familyCouple }),
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/father") @Route("api/v1/org/profile/family/father")
@Tags("ProfileFamilyFather") @Tags("ProfileFamilyFather")
@Security("bearerAuth") @Security("bearerAuth")
@ -158,6 +159,7 @@ export class ProfileFamilyFatherController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub; familyFather.createdUserId = req.user.sub;
@ -170,10 +172,11 @@ export class ProfileFamilyFatherController extends Controller {
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
await this.ProfileFamilyFather.save(familyFather); await this.ProfileFamilyFather.save(familyFather, { data: req });
setLogDataDiff(req, { before, after: familyFather });
history.profileFamilyFatherId = familyFather.id; history.profileFamilyFatherId = familyFather.id;
await this.ProfileFamilyFatherHistory.save(history); await this.ProfileFamilyFatherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyFather.id); return new HttpSuccess(familyFather.id);
} }
@ -186,7 +189,8 @@ export class ProfileFamilyFatherController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId }); const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId });
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyFather);
// const before_null = null;
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(familyFather, body); Object.assign(familyFather, body);
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
@ -204,8 +208,10 @@ export class ProfileFamilyFatherController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyFather.save(familyFather), this.ProfileFamilyFather.save(familyFather, { data: req }),
this.ProfileFamilyFatherHistory.save(history), setLogDataDiff(req, { before, after: familyFather }),
this.ProfileFamilyFatherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/family/father") @Route("api/v1/org/profile-employee/family/father")
@Tags("ProfileEmployeeFamilyFather") @Tags("ProfileEmployeeFamilyFather")
@Security("bearerAuth") @Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub; familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name; familyFather.createdFullName = req.user.name;
@ -172,9 +174,11 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
await this.ProfileFamilyFather.save(familyFather); await this.ProfileFamilyFather.save(familyFather, { data: req });
setLogDataDiff(req, { before, after: familyFather });
history.profileFamilyFatherId = familyFather.id; history.profileFamilyFatherId = familyFather.id;
await this.ProfileFamilyFatherHistory.save(history); await this.ProfileFamilyFatherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyFather.id); return new HttpSuccess(familyFather.id);
} }
@ -190,7 +194,8 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyFather);
// const before_null = null;
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(familyFather, body); Object.assign(familyFather, body);
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
@ -208,8 +213,10 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyFather.save(familyFather), this.ProfileFamilyFather.save(familyFather, { data: req }),
this.ProfileFamilyFatherHistory.save(history), setLogDataDiff(req, { before, after: familyFather }),
this.ProfileFamilyFatherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory"; import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/family/father") @Route("api/v1/org/profile-temp/family/father")
@Tags("ProfileEmployeeFamilyFather") @Tags("ProfileEmployeeFamilyFather")
@Security("bearerAuth") @Security("bearerAuth")
@ -162,6 +163,7 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub; familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name; familyFather.createdFullName = req.user.name;
@ -173,9 +175,11 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
await this.ProfileFamilyFather.save(familyFather); await this.ProfileFamilyFather.save(familyFather, { data: req });
setLogDataDiff(req, { before, after: familyFather });
history.profileFamilyFatherId = familyFather.id; history.profileFamilyFatherId = familyFather.id;
await this.ProfileFamilyFatherHistory.save(history); await this.ProfileFamilyFatherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyFather.id); return new HttpSuccess(familyFather.id);
} }
@ -195,7 +199,8 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
const history = new ProfileFamilyFatherHistory(); const history = new ProfileFamilyFatherHistory();
Object.assign(familyFather, body); Object.assign(familyFather, body);
Object.assign(history, { ...familyFather, id: undefined }); Object.assign(history, { ...familyFather, id: undefined });
const before = structuredClone(familyFather);
// const before_null = null;
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
history.profileFamilyFatherId = familyFather.id; history.profileFamilyFatherId = familyFather.id;
familyFather.lastUpdateUserId = req.user.sub; familyFather.lastUpdateUserId = req.user.sub;
@ -209,8 +214,10 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyFather.save(familyFather), this.ProfileFamilyFather.save(familyFather, { data: req }),
this.ProfileFamilyFatherHistory.save(history), setLogDataDiff(req, { before, after: familyFather }),
this.ProfileFamilyFatherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/family/mother") @Route("api/v1/org/profile/family/mother")
@Tags("ProfileFamilyMother") @Tags("ProfileFamilyMother")
@Security("bearerAuth") @Security("bearerAuth")
@ -158,6 +159,7 @@ export class ProfileFamilyMotherController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub; familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name; familyMother.createdFullName = req.user.name;
@ -169,9 +171,11 @@ export class ProfileFamilyMotherController extends Controller {
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
await this.ProfileFamilyMother.save(familyMother); await this.ProfileFamilyMother.save(familyMother, { data: req });
setLogDataDiff(req, { before, after: familyMother });
history.profileFamilyMotherId = familyMother.id; history.profileFamilyMotherId = familyMother.id;
await this.ProfileFamilyMotherHistory.save(history); await this.ProfileFamilyMotherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyMother.id); return new HttpSuccess(familyMother.id);
} }
@ -185,7 +189,8 @@ export class ProfileFamilyMotherController extends Controller {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId }); const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyMother);
// const before_null = null;
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(familyMother, body); Object.assign(familyMother, body);
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
@ -203,8 +208,10 @@ export class ProfileFamilyMotherController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyMother.save(familyMother), this.ProfileFamilyMother.save(familyMother, { data: req }),
this.ProfileFamilyMotherHistory.save(history), setLogDataDiff(req, { before, after: familyMother }),
this.ProfileFamilyMotherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/family/mother") @Route("api/v1/org/profile-employee/family/mother")
@Tags("ProfileEmployeeFamilyMother") @Tags("ProfileEmployeeFamilyMother")
@Security("bearerAuth") @Security("bearerAuth")
@ -161,6 +162,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub; familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name; familyMother.createdFullName = req.user.name;
@ -172,10 +174,11 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
await this.ProfileFamilyMother.save(familyMother); await this.ProfileFamilyMother.save(familyMother, { data: req });
setLogDataDiff(req, { before, after: familyMother });
history.profileFamilyMotherId = familyMother.id; history.profileFamilyMotherId = familyMother.id;
await this.ProfileFamilyMotherHistory.save(history); await this.ProfileFamilyMotherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyMother.id); return new HttpSuccess(familyMother.id);
} }
@ -194,7 +197,8 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(familyMother, body); Object.assign(familyMother, body);
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
const before = structuredClone(familyMother);
// const before_null = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
history.profileFamilyMotherId = familyMother.id; history.profileFamilyMotherId = familyMother.id;
familyMother.lastUpdateUserId = req.user.sub; familyMother.lastUpdateUserId = req.user.sub;
@ -208,8 +212,10 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyMother.save(familyMother), this.ProfileFamilyMother.save(familyMother, { data: req }),
this.ProfileFamilyMotherHistory.save(history), setLogDataDiff(req, { before, after: familyMother }),
this.ProfileFamilyMotherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory"; import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
import Extension from "../interfaces/extension"; import Extension from "../interfaces/extension";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/family/mother") @Route("api/v1/org/profile-temp/family/mother")
@Tags("ProfileEmployeeFamilyMother") @Tags("ProfileEmployeeFamilyMother")
@Security("bearerAuth") @Security("bearerAuth")
@ -162,6 +163,7 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub; familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name; familyMother.createdFullName = req.user.name;
@ -173,10 +175,11 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
await this.ProfileFamilyMother.save(familyMother); await this.ProfileFamilyMother.save(familyMother, { data: req });
setLogDataDiff(req, { before, after: familyMother });
history.profileFamilyMotherId = familyMother.id; history.profileFamilyMotherId = familyMother.id;
await this.ProfileFamilyMotherHistory.save(history); await this.ProfileFamilyMotherHistory.save(history, { data: req });
//setLogDataDiff(req, { before, after: history });
return new HttpSuccess(familyMother.id); return new HttpSuccess(familyMother.id);
} }
@ -191,7 +194,8 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(familyMother);
// const before_null = null;
const history = new ProfileFamilyMotherHistory(); const history = new ProfileFamilyMotherHistory();
Object.assign(familyMother, body); Object.assign(familyMother, body);
Object.assign(history, { ...familyMother, id: undefined }); Object.assign(history, { ...familyMother, id: undefined });
@ -209,8 +213,10 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.ProfileFamilyMother.save(familyMother), this.ProfileFamilyMother.save(familyMother, { data: req }),
this.ProfileFamilyMotherHistory.save(history), setLogDataDiff(req, { before, after: familyMother }),
this.ProfileFamilyMotherHistory.save(history, { data: req }),
// setLogDataDiff(req, { before: before_null, after: history }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -8,7 +8,7 @@ import { Profile } from "../entities/Profile";
import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileGovernment"; import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileGovernment";
import { Position } from "../entities/Position"; import { Position } from "../entities/Position";
import { PosMaster } from "../entities/PosMaster"; import { PosMaster } from "../entities/PosMaster";
import { calculateAge, calculateRetireDate } from "../interfaces/utils"; import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org/profile/government") @Route("api/v1/org/profile/government")
@ -385,7 +385,7 @@ export class ProfileGovernmentHistoryController extends Controller {
}); });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileGovernment(); const history = new ProfileGovernment();
Object.assign(record, body); Object.assign(record, body);
@ -402,7 +402,11 @@ export class ProfileGovernmentHistoryController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.profileRepo.save(record), this.govRepo.save(history)]); await Promise.all([
this.profileRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.govRepo.save(history, { data:req })
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,7 +25,7 @@ import {
} from "../entities/ProfileGovernment"; } from "../entities/ProfileGovernment";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { calculateAge, calculateRetireDate } from "../interfaces/utils"; import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org/profile-employee/government") @Route("api/v1/org/profile-employee/government")
@ -368,6 +368,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
}); });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileGovernment(); const history = new ProfileGovernment();
Object.assign(record, body); Object.assign(record, body);
@ -384,7 +385,10 @@ export class ProfileGovernmentEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(history)]); await Promise.all([
this.profileEmployeeRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.govRepo.save(history, { data: req })]);
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -25,7 +25,7 @@ import {
} from "../entities/ProfileGovernment"; } from "../entities/ProfileGovernment";
import { EmployeePosition } from "../entities/EmployeePosition"; import { EmployeePosition } from "../entities/EmployeePosition";
import { EmployeePosMaster } from "../entities/EmployeePosMaster"; import { EmployeePosMaster } from "../entities/EmployeePosMaster";
import { calculateAge, calculateRetireDate } from "../interfaces/utils"; import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { OrgRevision } from "../entities/OrgRevision"; import { OrgRevision } from "../entities/OrgRevision";
@Route("api/v1/org/profile-temp/government") @Route("api/v1/org/profile-temp/government")
@ -369,6 +369,7 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
}); });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileGovernment(); const history = new ProfileGovernment();
Object.assign(record, body); Object.assign(record, body);
@ -385,7 +386,11 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.profileEmployeeRepo.save(record), this.govRepo.save(history)]); await Promise.all([
this.profileEmployeeRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.govRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }
} }

View file

@ -20,6 +20,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/honor") @Route("api/v1/org/profile/honor")
@Tags("ProfileHonor") @Tags("ProfileHonor")
@Security("bearerAuth") @Security("bearerAuth")
@ -111,7 +112,7 @@ export class ProfileHonorController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileHonor(); const data = new ProfileHonor();
const meta = { const meta = {
@ -127,9 +128,10 @@ export class ProfileHonorController extends Controller {
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.honorRepo.save(data); await this.honorRepo.save(data, {data: req});
setLogDataDiff(req, { before, after: data });
history.profileHonorId = data.id; history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history); await this.honorHistoryRepo.save(history, {data: req});
return new HttpSuccess(); return new HttpSuccess();
} }
@ -148,7 +150,7 @@ export class ProfileHonorController extends Controller {
Object.assign(record, body); Object.assign(record, body);
Object.assign(history, { ...record, id: undefined }); Object.assign(history, { ...record, id: undefined });
const before = structuredClone(record);
history.profileHonorId = honorId; history.profileHonorId = honorId;
record.lastUpdateUserId = req.user.sub; record.lastUpdateUserId = req.user.sub;
record.lastUpdateFullName = req.user.name; record.lastUpdateFullName = req.user.name;
@ -160,7 +162,11 @@ export class ProfileHonorController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]); await Promise.all([
this.honorRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.honorHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -24,6 +24,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/honor") @Route("api/v1/org/profile-employee/honor")
@Tags("ProfileEmployeeHonor") @Tags("ProfileEmployeeHonor")
@Security("bearerAuth") @Security("bearerAuth")
@ -119,7 +120,7 @@ export class ProfileHonorEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileHonor(); const data = new ProfileHonor();
const meta = { const meta = {
@ -135,9 +136,10 @@ export class ProfileHonorEmployeeController extends Controller {
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.honorRepo.save(data); await this.honorRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileHonorId = data.id; history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history); await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -155,7 +157,7 @@ export class ProfileHonorEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
Object.assign(record, body); Object.assign(record, body);
@ -172,7 +174,11 @@ export class ProfileHonorEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]); await Promise.all([
this.honorRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.honorHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -24,6 +24,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/honor") @Route("api/v1/org/profile-temp/honor")
@Tags("ProfileEmployeeHonor") @Tags("ProfileEmployeeHonor")
@Security("bearerAuth") @Security("bearerAuth")
@ -112,7 +113,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileHonor(); const data = new ProfileHonor();
const meta = { const meta = {
@ -128,9 +129,10 @@ export class ProfileHonorEmployeeTempController extends Controller {
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.honorRepo.save(data); await this.honorRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileHonorId = data.id; history.profileHonorId = data.id;
await this.honorHistoryRepo.save(history); await this.honorHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -145,7 +147,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
const record = await this.honorRepo.findOneBy({ id: honorId }); const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
Object.assign(record, body); Object.assign(record, body);
@ -162,7 +164,11 @@ export class ProfileHonorEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.honorRepo.save(record), this.honorHistoryRepo.save(history)]); await Promise.all([
this.honorRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.honorHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { Insignia } from "../entities/Insignia"; import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/insignia") @Route("api/v1/org/profile/insignia")
@Tags("ProfileInsignia") @Tags("ProfileInsignia")
@Security("bearerAuth") @Security("bearerAuth")
@ -124,7 +125,7 @@ export class ProfileInsigniaController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = null;
const data = new ProfileInsignia(); const data = new ProfileInsignia();
const meta = { const meta = {
@ -140,9 +141,10 @@ export class ProfileInsigniaController extends Controller {
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.insigniaRepo.save(data); await this.insigniaRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data } );
history.profileInsigniaId = data.id; history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history); await this.insigniaHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -163,7 +165,7 @@ export class ProfileInsigniaController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = structuredClone(record);
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(record, body); Object.assign(record, body);
@ -180,7 +182,11 @@ export class ProfileInsigniaController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]); await Promise.all([
this.insigniaRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.insigniaHistoryRepo.save(history, { data: req })
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Insignia } from "../entities/Insignia"; import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/insignia") @Route("api/v1/org/profile-employee/insignia")
@Tags("ProfileEmployeeInsignia") @Tags("ProfileEmployeeInsignia")
@Security("bearerAuth") @Security("bearerAuth")
@ -128,7 +129,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = null;
const data = new ProfileInsignia(); const data = new ProfileInsignia();
const meta = { const meta = {
@ -144,9 +145,10 @@ export class ProfileInsigniaEmployeeController extends Controller {
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.insigniaRepo.save(data); await this.insigniaRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data } )
history.profileInsigniaId = data.id; history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history); await this.insigniaHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -171,7 +173,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = structuredClone(record);
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(record, body); Object.assign(record, body);
@ -188,7 +190,11 @@ export class ProfileInsigniaEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]); await Promise.all([
this.insigniaRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.insigniaHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { Insignia } from "../entities/Insignia"; import { Insignia } from "../entities/Insignia";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/insignia") @Route("api/v1/org/profile-temp/insignia")
@Tags("ProfileEmployeeInsignia") @Tags("ProfileEmployeeInsignia")
@Security("bearerAuth") @Security("bearerAuth")
@ -122,7 +123,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = null;
const data = new ProfileInsignia(); const data = new ProfileInsignia();
const meta = { const meta = {
@ -138,9 +139,10 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.insigniaRepo.save(data); await this.insigniaRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileInsigniaId = data.id; history.profileInsigniaId = data.id;
await this.insigniaHistoryRepo.save(history); await this.insigniaHistoryRepo.save(history, { data:req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -162,7 +164,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
if (!insignia) { if (!insignia) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
} }
const before = structuredClone(record);
const history = new ProfileInsigniaHistory(); const history = new ProfileInsigniaHistory();
Object.assign(record, body); Object.assign(record, body);
@ -179,7 +181,11 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.insigniaRepo.save(record), this.insigniaHistoryRepo.save(history)]); await Promise.all([
this.insigniaRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.insigniaHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { LeaveType } from "../entities/LeaveType"; import { LeaveType } from "../entities/LeaveType";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/leave") @Route("api/v1/org/profile/leave")
@Tags("ProfileLeave") @Tags("ProfileLeave")
@Security("bearerAuth") @Security("bearerAuth")
@ -188,7 +189,7 @@ export class ProfileLeaveController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = null;
const data = new ProfileLeave(); const data = new ProfileLeave();
const meta = { const meta = {
@ -204,9 +205,10 @@ export class ProfileLeaveController extends Controller {
const history = new ProfileLeaveHistory(); const history = new ProfileLeaveHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.leaveRepo.save(data); await this.leaveRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data });
history.profileLeaveId = data.id; history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history); await this.leaveHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -227,7 +229,7 @@ export class ProfileLeaveController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = structuredClone(record);
const history = new ProfileLeaveHistory(); const history = new ProfileLeaveHistory();
Object.assign(record, body); Object.assign(record, body);
@ -244,7 +246,11 @@ export class ProfileLeaveController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]); await Promise.all([
this.leaveRepo.save(record, { data: req }),
setLogDataDiff( req, { before, after: record }),
this.leaveHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { LeaveType } from "../entities/LeaveType"; import { LeaveType } from "../entities/LeaveType";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/leave") @Route("api/v1/org/profile-employee/leave")
@Tags("ProfileLeave") @Tags("ProfileLeave")
@Security("bearerAuth") @Security("bearerAuth")
@ -116,7 +117,7 @@ export class ProfileLeaveEmployeeController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = null;
const data = new ProfileLeave(); const data = new ProfileLeave();
const meta = { const meta = {
@ -132,9 +133,10 @@ export class ProfileLeaveEmployeeController extends Controller {
const history = new ProfileLeaveHistory(); const history = new ProfileLeaveHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.leaveRepo.save(data); await this.leaveRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data } )
history.profileLeaveId = data.id; history.profileLeaveId = data.id;
await this.leaveHistoryRepo.save(history); await this.leaveHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -159,7 +161,7 @@ export class ProfileLeaveEmployeeController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = structuredClone(record);
const history = new ProfileLeaveHistory(); const history = new ProfileLeaveHistory();
Object.assign(record, body); Object.assign(record, body);
@ -176,7 +178,11 @@ export class ProfileLeaveEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]); await Promise.all([
this.leaveRepo.save(record, { data: req }),
setLogDataDiff( req, { before, after: record } ),
this.leaveHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { LeaveType } from "../entities/LeaveType"; import { LeaveType } from "../entities/LeaveType";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/leave") @Route("api/v1/org/profile-temp/leave")
@Tags("ProfileLeave") @Tags("ProfileLeave")
@Security("bearerAuth") @Security("bearerAuth")
@ -109,7 +110,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = null;
const data = new ProfileLeave(); const data = new ProfileLeave();
const meta = { const meta = {
@ -149,7 +150,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
if (!leaveType) { if (!leaveType) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
} }
const before = structuredClone(record);
const history = new ProfileLeaveHistory(); const history = new ProfileLeaveHistory();
Object.assign(record, body); Object.assign(record, body);
@ -166,7 +167,11 @@ export class ProfileLeaveEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.leaveRepo.save(record), this.leaveHistoryRepo.save(history)]); await Promise.all([
this.leaveRepo.save(record),
setLogDataDiff( req, { before, after: record} ),
this.leaveHistoryRepo.save(history)
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid"; import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/nopaid") @Route("api/v1/org/profile/nopaid")
@Tags("ProfileNopaid") @Tags("ProfileNopaid")
@Security("bearerAuth") @Security("bearerAuth")
@ -75,7 +76,7 @@ export class ProfileNopaidController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileNopaid(); const data = new ProfileNopaid();
const meta = { const meta = {
@ -91,9 +92,10 @@ export class ProfileNopaidController extends Controller {
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.nopaidRepository.save(data); await this.nopaidRepository.save(data, { data: req });
setLogDataDiff( req, { before, after: data } )
history.profileNopaidId = data.id; history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history); await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -107,7 +109,7 @@ export class ProfileNopaidController extends Controller {
const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(record, body); Object.assign(record, body);
@ -125,8 +127,9 @@ export class ProfileNopaidController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.nopaidRepository.save(record), this.nopaidRepository.save(record, { data: req }),
this.nopaidHistoryRepository.save(history), setLogDataDiff( req, { before, after: record } ),
this.nopaidHistoryRepository.save(history, { data: req }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
UpdateProfileNopaid, UpdateProfileNopaid,
} from "../entities/ProfileNopaid"; } from "../entities/ProfileNopaid";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/nopaid") @Route("api/v1/org/profile-employee/nopaid")
@Tags("ProfileNopaid") @Tags("ProfileNopaid")
@Security("bearerAuth") @Security("bearerAuth")
@ -79,7 +80,7 @@ export class ProfileNopaidEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileNopaid(); const data = new ProfileNopaid();
const meta = { const meta = {
@ -95,9 +96,10 @@ export class ProfileNopaidEmployeeController extends Controller {
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.nopaidRepository.save(data); await this.nopaidRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileNopaidId = data.id; history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history); await this.nopaidHistoryRepository.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -116,6 +118,7 @@ export class ProfileNopaidEmployeeController extends Controller {
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(record, body); Object.assign(record, body);
@ -133,8 +136,9 @@ export class ProfileNopaidEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.nopaidRepository.save(record), this.nopaidRepository.save(record, { data: req }),
this.nopaidHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.nopaidHistoryRepository.save(history, { data: req }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
UpdateProfileNopaid, UpdateProfileNopaid,
} from "../entities/ProfileNopaid"; } from "../entities/ProfileNopaid";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/nopaid") @Route("api/v1/org/profile-temp/nopaid")
@Tags("ProfileNopaid") @Tags("ProfileNopaid")
@Security("bearerAuth") @Security("bearerAuth")
@ -80,7 +81,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileNopaid(); const data = new ProfileNopaid();
const meta = { const meta = {
@ -96,9 +97,10 @@ export class ProfileNopaidEmployeeTempController extends Controller {
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.nopaidRepository.save(data); await this.nopaidRepository.save(data, {data: req});
setLogDataDiff( req, { before, after: data})
history.profileNopaidId = data.id; history.profileNopaidId = data.id;
await this.nopaidHistoryRepository.save(history); await this.nopaidHistoryRepository.save(history, {data: req});
return new HttpSuccess(); return new HttpSuccess();
} }
@ -113,7 +115,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
Object.assign(record, body); Object.assign(record, body);
@ -131,8 +133,9 @@ export class ProfileNopaidEmployeeTempController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.nopaidRepository.save(record), this.nopaidRepository.save(record, { data: req }),
this.nopaidHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.nopaidHistoryRepository.save(history, { data: req }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -21,6 +21,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther"; import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/other") @Route("api/v1/org/profile/other")
@Tags("ProfileOther") @Tags("ProfileOther")
@Security("bearerAuth") @Security("bearerAuth")
@ -56,7 +57,6 @@ export class ProfileOtherController extends Controller {
public async otherAdminHistory(@Path() otherId: string, @Request() req: RequestWithUser) { public async otherAdminHistory(@Path() otherId: string, @Request() req: RequestWithUser) {
const _record = await this.otherRepository.findOneBy({ id: otherId }); const _record = await this.otherRepository.findOneBy({ id: otherId });
console.log(">>>>", _record);
if (_record) { if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId); await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
} }
@ -87,7 +87,7 @@ export class ProfileOtherController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileOther(); const data = new ProfileOther();
const meta = { const meta = {
@ -103,9 +103,10 @@ export class ProfileOtherController extends Controller {
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.otherRepository.save(data); await this.otherRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileOtherId = data.id; history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history); await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -119,7 +120,7 @@ export class ProfileOtherController extends Controller {
const record = await this.otherRepository.findOneBy({ id: otherId }); const record = await this.otherRepository.findOneBy({ id: otherId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
Object.assign(record, body); Object.assign(record, body);
@ -137,8 +138,9 @@ export class ProfileOtherController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.otherRepository.save(record), this.otherRepository.save(record, { data: req }),
this.otherHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.otherHistoryRepository.save(history, { data: req }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -24,6 +24,7 @@ import {
UpdateProfileOther, UpdateProfileOther,
} from "../entities/ProfileOther"; } from "../entities/ProfileOther";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/other") @Route("api/v1/org/profile-employee/other")
@Tags("ProfileOther") @Tags("ProfileOther")
@Security("bearerAuth") @Security("bearerAuth")
@ -92,7 +93,7 @@ export class ProfileOtherEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileOther(); const data = new ProfileOther();
const meta = { const meta = {
@ -108,9 +109,10 @@ export class ProfileOtherEmployeeController extends Controller {
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.otherRepository.save(data); await this.otherRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileOtherId = data.id; history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history); await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -128,7 +130,7 @@ export class ProfileOtherEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
Object.assign(record, body); Object.assign(record, body);
@ -146,8 +148,9 @@ export class ProfileOtherEmployeeController extends Controller {
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([ await Promise.all([
this.otherRepository.save(record), this.otherRepository.save(record, { data: req }),
this.otherHistoryRepository.save(history), setLogDataDiff(req, { before, after: record }),
this.otherHistoryRepository.save(history, { data: req }),
]); ]);
return new HttpSuccess(); return new HttpSuccess();

View file

@ -25,6 +25,7 @@ import {
UpdateProfileOther, UpdateProfileOther,
} from "../entities/ProfileOther"; } from "../entities/ProfileOther";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/other") @Route("api/v1/org/profile-temp/other")
@Tags("ProfileOther") @Tags("ProfileOther")
@Security("bearerAuth") @Security("bearerAuth")
@ -87,7 +88,7 @@ export class ProfileOtherEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileOther(); const data = new ProfileOther();
const meta = { const meta = {
@ -103,9 +104,10 @@ export class ProfileOtherEmployeeTempController extends Controller {
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.otherRepository.save(data); await this.otherRepository.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileOtherId = data.id; history.profileOtherId = data.id;
await this.otherHistoryRepository.save(history); await this.otherHistoryRepository.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -22,6 +22,7 @@ import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import { LessThan, MoreThan } from "typeorm"; import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/salary") @Route("api/v1/org/profile/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -105,7 +106,7 @@ export class ProfileSalaryController extends Controller {
where: { profileId: body.profileId }, where: { profileId: body.profileId },
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
@ -122,9 +123,10 @@ export class ProfileSalaryController extends Controller {
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data); await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id; history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -138,7 +140,7 @@ export class ProfileSalaryController extends Controller {
const record = await this.salaryRepo.findOneBy({ id: salaryId }); const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(record, body); Object.assign(record, body);
@ -155,7 +157,11 @@ export class ProfileSalaryController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]); await Promise.all([
this.salaryRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.salaryHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { LessThan, MoreThan } from "typeorm"; import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/salary") @Route("api/v1/org/profile-employee/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -115,7 +116,7 @@ export class ProfileSalaryEmployeeController extends Controller {
where: { profileEmployeeId: body.profileEmployeeId }, where: { profileEmployeeId: body.profileEmployeeId },
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
@ -132,9 +133,10 @@ export class ProfileSalaryEmployeeController extends Controller {
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data); await this.salaryRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileSalaryId = data.id; history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -152,7 +154,7 @@ export class ProfileSalaryEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(record, body); Object.assign(record, body);
@ -169,7 +171,11 @@ export class ProfileSalaryEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]); await Promise.all([
this.salaryRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.salaryHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import { LessThan, MoreThan } from "typeorm"; import { LessThan, MoreThan } from "typeorm";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/salary") @Route("api/v1/org/profile-temp/salary")
@Tags("ProfileSalary") @Tags("ProfileSalary")
@Security("bearerAuth") @Security("bearerAuth")
@ -109,7 +110,7 @@ export class ProfileSalaryEmployeeTempController extends Controller {
where: { profileEmployeeId: body.profileEmployeeId }, where: { profileEmployeeId: body.profileEmployeeId },
order: { order: "DESC" }, order: { order: "DESC" },
}); });
const before = null;
const data = new ProfileSalary(); const data = new ProfileSalary();
const meta = { const meta = {
@ -126,9 +127,10 @@ export class ProfileSalaryEmployeeTempController extends Controller {
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.salaryRepo.save(data); await this.salaryRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data });
history.profileSalaryId = data.id; history.profileSalaryId = data.id;
await this.salaryHistoryRepo.save(history); await this.salaryHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -143,7 +145,7 @@ export class ProfileSalaryEmployeeTempController extends Controller {
const record = await this.salaryRepo.findOneBy({ id: salaryId }); const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
Object.assign(record, body); Object.assign(record, body);
@ -160,7 +162,11 @@ export class ProfileSalaryEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.salaryRepo.save(record), this.salaryHistoryRepo.save(history)]); await Promise.all([
this.salaryRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.salaryHistoryRepo.save(history, { data: req })
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -24,6 +24,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { Profile } from "../entities/Profile"; import { Profile } from "../entities/Profile";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile/training") @Route("api/v1/org/profile/training")
@Tags("ProfileTraining") @Tags("ProfileTraining")
@Security("bearerAuth") @Security("bearerAuth")
@ -92,7 +93,7 @@ export class ProfileTrainingController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
const before = null;
const data = new ProfileTraining(); const data = new ProfileTraining();
const meta = { const meta = {
@ -108,9 +109,10 @@ export class ProfileTrainingController extends Controller {
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.trainingRepo.save(data); await this.trainingRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data} )
history.profileTrainingId = data.id; history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history); await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -124,7 +126,7 @@ export class ProfileTrainingController extends Controller {
const record = await this.trainingRepo.findOneBy({ id: trainingId }); const record = await this.trainingRepo.findOneBy({ id: trainingId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
const before = structuredClone(record);
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(record, body); Object.assign(record, body);
@ -141,7 +143,11 @@ export class ProfileTrainingController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]); await Promise.all([
this.trainingRepo.save(record, { data: req }),
setLogDataDiff( req, { before, after: record} ),
this.trainingHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-employee/training") @Route("api/v1/org/profile-employee/training")
@Tags("ProfileEmployeeTraining") @Tags("ProfileEmployeeTraining")
@Security("bearerAuth") @Security("bearerAuth")
@ -101,7 +102,7 @@ export class ProfileTrainingEmployeeController extends Controller {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
const before = null;
const data = new ProfileTraining(); const data = new ProfileTraining();
const meta = { const meta = {
@ -117,9 +118,10 @@ export class ProfileTrainingEmployeeController extends Controller {
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.trainingRepo.save(data); await this.trainingRepo.save(data, { data: req });
setLogDataDiff( req, { before, after: data} )
history.profileTrainingId = data.id; history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history); await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -137,7 +139,7 @@ export class ProfileTrainingEmployeeController extends Controller {
"SYS_REGISTRY_EMP", "SYS_REGISTRY_EMP",
record.profileEmployeeId, record.profileEmployeeId,
); );
const before = structuredClone(record);
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(record, body); Object.assign(record, body);
@ -154,7 +156,11 @@ export class ProfileTrainingEmployeeController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]); await Promise.all([
this.trainingRepo.save(record, { data: req }),
setLogDataDiff( req, { before, after: record} ),
this.trainingHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -25,6 +25,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
import { RequestWithUser } from "../middlewares/user"; import { RequestWithUser } from "../middlewares/user";
import { ProfileEmployee } from "../entities/ProfileEmployee"; import { ProfileEmployee } from "../entities/ProfileEmployee";
import permission from "../interfaces/permission"; import permission from "../interfaces/permission";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/profile-temp/training") @Route("api/v1/org/profile-temp/training")
@Tags("ProfileEmployeeTraining") @Tags("ProfileEmployeeTraining")
@Security("bearerAuth") @Security("bearerAuth")
@ -94,7 +95,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const before = null;
const data = new ProfileTraining(); const data = new ProfileTraining();
const meta = { const meta = {
@ -110,9 +111,10 @@ export class ProfileTrainingEmployeeTempController extends Controller {
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(history, { ...data, id: undefined }); Object.assign(history, { ...data, id: undefined });
await this.trainingRepo.save(data); await this.trainingRepo.save(data, { data: req });
setLogDataDiff(req, { before, after: data });
history.profileTrainingId = data.id; history.profileTrainingId = data.id;
await this.trainingHistoryRepo.save(history); await this.trainingHistoryRepo.save(history, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -127,7 +129,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
const record = await this.trainingRepo.findOneBy({ id: trainingId }); const record = await this.trainingRepo.findOneBy({ id: trainingId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const before = structuredClone(record);
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
Object.assign(record, body); Object.assign(record, body);
@ -144,7 +146,11 @@ export class ProfileTrainingEmployeeTempController extends Controller {
history.createdAt = new Date(); history.createdAt = new Date();
history.lastUpdatedAt = new Date(); history.lastUpdatedAt = new Date();
await Promise.all([this.trainingRepo.save(record), this.trainingHistoryRepo.save(history)]); await Promise.all([
this.trainingRepo.save(record, { data: req }),
setLogDataDiff(req, { before, after: record }),
this.trainingHistoryRepo.save(history, { data: req }),
]);
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { Province, CreateProvince, UpdateProvince } from "../entities/Province"; import { Province, CreateProvince, UpdateProvince } from "../entities/Province";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/metadata/province") @Route("api/v1/org/metadata/province")
@Tags("Province") @Tags("Province")
@ -77,7 +79,7 @@ export class ProvinceController extends Controller {
async Post( async Post(
@Body() @Body()
requestBody: CreateProvince, requestBody: CreateProvince,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _province = Object.assign(new Province(), requestBody); const _province = Object.assign(new Province(), requestBody);
if (!_province) { if (!_province) {
@ -91,14 +93,15 @@ export class ProvinceController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_province.createdUserId = request.user.sub; _province.createdUserId = request.user.sub;
_province.createdFullName = request.user.name; _province.createdFullName = request.user.name;
_province.lastUpdateUserId = request.user.sub; _province.lastUpdateUserId = request.user.sub;
_province.lastUpdateFullName = request.user.name; _province.lastUpdateFullName = request.user.name;
_province.createdAt = new Date(); _province.createdAt = new Date();
_province.lastUpdatedAt = 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(); return new HttpSuccess();
} }
@ -114,7 +117,7 @@ export class ProvinceController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateProvince, requestBody: UpdateProvince,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _province = await this.provinceRepository.findOne({ where: { id: id } }); const _province = await this.provinceRepository.findOne({ where: { id: id } });
if (!_province) { if (!_province) {
@ -126,12 +129,13 @@ export class ProvinceController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(_province);
_province.lastUpdateUserId = request.user.sub; _province.lastUpdateUserId = request.user.sub;
_province.lastUpdateFullName = request.user.name; _province.lastUpdateFullName = request.user.name;
_province.lastUpdatedAt = new Date(); _province.lastUpdatedAt = new Date();
this.provinceRepository.merge(_province, requestBody); 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(); return new HttpSuccess();
} }

View file

@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { CreateRank, Rank } from "../entities/Rank"; import { CreateRank, Rank } from "../entities/Rank";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { setLogDataDiff } from "../interfaces/utils";
import { RequestWithUser } from "../middlewares/user";
@Route("api/v1/org/metadata/rank") @Route("api/v1/org/metadata/rank")
@Tags("Rank") @Tags("Rank")
@Security("bearerAuth") @Security("bearerAuth")
@ -40,7 +42,7 @@ export class RankController extends Controller {
async createRank( async createRank(
@Body() @Body()
requestBody: CreateRank, requestBody: CreateRank,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const checkName = await this.rankRepository.findOne({ const checkName = await this.rankRepository.findOne({
where: { name: requestBody.name }, where: { name: requestBody.name },
@ -50,6 +52,7 @@ export class RankController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
const rank = Object.assign(new Rank(), requestBody); const rank = Object.assign(new Rank(), requestBody);
rank.createdUserId = request.user.sub; rank.createdUserId = request.user.sub;
rank.createdFullName = request.user.name; rank.createdFullName = request.user.name;
@ -57,7 +60,8 @@ export class RankController extends Controller {
rank.lastUpdateFullName = request.user.name; rank.lastUpdateFullName = request.user.name;
rank.createdAt = new Date(); rank.createdAt = new Date();
rank.lastUpdatedAt = new Date(); rank.lastUpdatedAt = new Date();
await this.rankRepository.save(rank); await this.rankRepository.save(rank, { data: request });
setLogDataDiff( request, { before, after: rank} )
return new HttpSuccess(); return new HttpSuccess();
} }
@ -73,7 +77,7 @@ export class RankController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreateRank, requestBody: CreateRank,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const rank = await this.rankRepository.findOne({ where: { id: id } }); const rank = await this.rankRepository.findOne({ where: { id: id } });
if (!rank) { if (!rank) {
@ -87,12 +91,13 @@ export class RankController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(rank);
rank.lastUpdateUserId = request.user.sub; rank.lastUpdateUserId = request.user.sub;
rank.lastUpdateFullName = request.user.name; rank.lastUpdateFullName = request.user.name;
rank.lastUpdatedAt = new Date(); rank.lastUpdatedAt = new Date();
this.rankRepository.merge(rank, requestBody); this.rankRepository.merge(rank, requestBody);
await this.rankRepository.save(rank); await this.rankRepository.save(rank, { data: request });
setLogDataDiff(request, { before, after: rank });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -104,14 +109,14 @@ export class RankController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async deleteRank(@Path() id: string) { async deleteRank(@Path() id: string, @Request() req: RequestWithUser) {
const delRank = await this.rankRepository.findOne({ const delRank = await this.rankRepository.findOne({
where: { id }, where: { id },
}); });
if (!delRank) { if (!delRank) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
} }
await this.rankRepository.delete({ id: id }); await this.rankRepository.remove(delRank, { data: req });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -19,6 +19,9 @@ import HttpStatusCode from "../interfaces/http-status";
import HttpError from "../interfaces/http-error"; import HttpError from "../interfaces/http-error";
import { CreateRelationship, Relationship } from "../entities/Relationship"; import { CreateRelationship, Relationship } from "../entities/Relationship";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
import { request } from "axios";
@Route("api/v1/org/metadata/relationship") @Route("api/v1/org/metadata/relationship")
@Tags("Relationship") @Tags("Relationship")
@Security("bearerAuth") @Security("bearerAuth")
@ -40,7 +43,7 @@ export class RelationshipController extends Controller {
async createRelationship( async createRelationship(
@Body() @Body()
requestBody: CreateRelationship, requestBody: CreateRelationship,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const checkName = await this.relationshipRepository.findOne({ const checkName = await this.relationshipRepository.findOne({
where: { name: requestBody.name }, where: { name: requestBody.name },
@ -49,7 +52,7 @@ export class RelationshipController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
const relationship = Object.assign(new Relationship(), requestBody); const relationship = Object.assign(new Relationship(), requestBody);
relationship.createdUserId = request.user.sub; relationship.createdUserId = request.user.sub;
relationship.createdFullName = request.user.name; relationship.createdFullName = request.user.name;
@ -57,7 +60,8 @@ export class RelationshipController extends Controller {
relationship.lastUpdateFullName = request.user.name; relationship.lastUpdateFullName = request.user.name;
relationship.createdAt = new Date(); relationship.createdAt = new Date();
relationship.lastUpdatedAt = new Date(); relationship.lastUpdatedAt = new Date();
await this.relationshipRepository.save(relationship); await this.relationshipRepository.save(relationship, { data: request });
setLogDataDiff( request, { before, after: relationship });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -73,7 +77,7 @@ export class RelationshipController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: CreateRelationship, requestBody: CreateRelationship,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const relationship = await this.relationshipRepository.findOne({ where: { id: id } }); const relationship = await this.relationshipRepository.findOne({ where: { id: id } });
if (!relationship) { if (!relationship) {
@ -88,11 +92,13 @@ export class RelationshipController extends Controller {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = structuredClone(relationship);
relationship.lastUpdateUserId = request.user.sub; relationship.lastUpdateUserId = request.user.sub;
relationship.lastUpdateFullName = request.user.name; relationship.lastUpdateFullName = request.user.name;
relationship.lastUpdatedAt = new Date(); relationship.lastUpdatedAt = new Date();
this.relationshipRepository.merge(relationship, requestBody); this.relationshipRepository.merge(relationship, requestBody);
await this.relationshipRepository.save(relationship); await this.relationshipRepository.save(relationship, { data: request });
setLogDataDiff( request, { before, after: relationship } )
return new HttpSuccess(); return new HttpSuccess();
} }
@ -104,14 +110,14 @@ export class RelationshipController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Delete("{id}") @Delete("{id}")
async deleteRelationship(@Path() id: string) { async deleteRelationship(@Path() id: string, @Request() request: RequestWithUser) {
const delRelationship = await this.relationshipRepository.findOne({ const delRelationship = await this.relationshipRepository.findOne({
where: { id }, where: { id },
}); });
if (!delRelationship) { if (!delRelationship) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพนี้"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพนี้");
} }
await this.relationshipRepository.delete({ id: id }); await this.relationshipRepository.remove(delRelationship, { data: request });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

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

View file

@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error";
import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict"; import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict";
import { District } from "../entities/District"; import { District } from "../entities/District";
import { Not } from "typeorm"; import { Not } from "typeorm";
import { RequestWithUser } from "../middlewares/user";
import { setLogDataDiff } from "../interfaces/utils";
@Route("api/v1/org/metadata/subDistrict") @Route("api/v1/org/metadata/subDistrict")
@Tags("SubDistrict") @Tags("SubDistrict")
@ -78,7 +80,7 @@ export class SubDistrictController extends Controller {
async Post( async Post(
@Body() @Body()
requestBody: CreateSubDistrict, requestBody: CreateSubDistrict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _subDistrict = Object.assign(new SubDistrict(), requestBody); const _subDistrict = Object.assign(new SubDistrict(), requestBody);
if (!_subDistrict) { if (!_subDistrict) {
@ -102,14 +104,15 @@ export class SubDistrictController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_subDistrict.createdUserId = request.user.sub; _subDistrict.createdUserId = request.user.sub;
_subDistrict.createdFullName = request.user.name; _subDistrict.createdFullName = request.user.name;
_subDistrict.lastUpdateUserId = request.user.sub; _subDistrict.lastUpdateUserId = request.user.sub;
_subDistrict.lastUpdateFullName = request.user.name; _subDistrict.lastUpdateFullName = request.user.name;
_subDistrict.createdAt = new Date(); _subDistrict.createdAt = new Date();
_subDistrict.lastUpdatedAt = new Date(); _subDistrict.lastUpdatedAt = new Date();
await this.subDistrictRepository.save(_subDistrict); await this.subDistrictRepository.save(_subDistrict, { data: request });
setLogDataDiff(request, { before, after: _subDistrict });
return new HttpSuccess(); return new HttpSuccess();
} }
@ -125,7 +128,7 @@ export class SubDistrictController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: UpdateSubDistrict, requestBody: UpdateSubDistrict,
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } }); const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
if (!_subDistrict) { if (!_subDistrict) {
@ -149,12 +152,13 @@ export class SubDistrictController extends Controller {
if (checkName) { if (checkName) {
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว"); throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
} }
const before = null;
_subDistrict.lastUpdateUserId = request.user.sub; _subDistrict.lastUpdateUserId = request.user.sub;
_subDistrict.lastUpdateFullName = request.user.name; _subDistrict.lastUpdateFullName = request.user.name;
_subDistrict.lastUpdatedAt = new Date(); _subDistrict.lastUpdatedAt = new Date();
this.subDistrictRepository.merge(_subDistrict, requestBody); this.subDistrictRepository.merge(_subDistrict, requestBody);
await this.subDistrictRepository.save(_subDistrict); await this.subDistrictRepository.save(_subDistrict, { data: request });
setLogDataDiff(request, { before, after: _subDistrict });
return new HttpSuccess(); return new HttpSuccess();
} }

View file

@ -1,6 +1,36 @@
import "dotenv/config"; import "dotenv/config";
import "reflect-metadata"; import "reflect-metadata";
import { DataSource } from "typeorm"; import { DataSource, Logger, QueryRunner } from "typeorm";
import { RequestWithUser } from "../middlewares/user";
import { addLogSequence } from "../interfaces/utils";
export class MyCustomLogger implements Logger {
log(level: "log" | "info" | "warn", message: any, queryRunner?: QueryRunner) { }
logQuery(query: string, parameters?: any[], queryRunner?: QueryRunner): void {
const req = queryRunner?.data as RequestWithUser;
if (req?.app?.locals.logData?.sequence) {
addLogSequence(req, {
action: "database",
status: "success",
description: "Query Data.",
query: [
"Query: " + query + (parameters ? " - Parameters:" + JSON.stringify(parameters) : ""),
],
});
}
}
logMigration(message: string, queryRunner?: QueryRunner) {}
logQueryError(
error: string | Error,
query: string,
parameters?: any[],
queryRunner?: QueryRunner,
) {}
logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: QueryRunner) {}
logSchemaBuild(message: string, queryRunner?: QueryRunner) {}
}
export const AppDataSource = new DataSource({ export const AppDataSource = new DataSource({
type: "mysql", type: "mysql",
@ -21,6 +51,7 @@ export const AppDataSource = new DataSource({
? ["src/migration/**/*.ts"] ? ["src/migration/**/*.ts"]
: ["dist/migration/**/*{.ts,.js}"], : ["dist/migration/**/*{.ts,.js}"],
subscribers: [], subscribers: [],
logger: new MyCustomLogger(),
}); });
// export default database; // export default database;

View file

@ -1,5 +1,6 @@
import { Path } from "tsoa"; import { Path } from "tsoa";
import axios from "axios"; import axios from "axios";
import { addLogSequence } from "./utils";
class CallAPI { class CallAPI {
//Get //Get
@ -14,8 +15,28 @@ class CallAPI {
api_key: process.env.API_KEY, api_key: process.env.API_KEY,
}, },
}); });
addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "GET",
url: url,
response: JSON.stringify(response.data.result),
},
});
return response.data.result; return response.data.result;
} catch (error) { } catch (error) {
addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "GET",
url: url,
response: JSON.stringify(error),
},
});
throw error; throw error;
} }
} }
@ -31,8 +52,30 @@ class CallAPI {
api_key: process.env.API_KEY, api_key: process.env.API_KEY,
}, },
}); });
addLogSequence(request, {
action: "request",
status: "success",
description: "connected",
request: {
method: "POST",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(response.data.result),
},
});
return response.data.result; return response.data.result;
} catch (error) { } catch (error) {
addLogSequence(request, {
action: "request",
status: "error",
description: "unconnected",
request: {
method: "POST",
url: url,
payload: JSON.stringify(sendData),
response: JSON.stringify(error),
},
});
console.log(error); console.log(error);
throw error; throw error;
} }

View file

@ -57,6 +57,14 @@ export async function expressAuthentication(
break; break;
} }
if (!request.app.locals.logData) {
request.app.locals.logData = {};
}
request.app.locals.logData.userId = payload.sub;
request.app.locals.logData.userName = payload.name;
request.app.locals.logData.user = payload.preferred_username;
return payload; return payload;
} }

View file

@ -4,6 +4,12 @@ import HttpStatus from "../interfaces/http-status";
import { ValidateError } from "tsoa"; import { ValidateError } from "tsoa";
function error(error: Error, _req: Request, res: Response, _next: NextFunction) { function error(error: Error, _req: Request, res: Response, _next: NextFunction) {
const logData = _req.app.locals.logData.sequence?.at(-1);
if (logData) {
logData.status = "error";
logData.description = error.message;
}
if (error instanceof HttpError) { if (error instanceof HttpError) {
return res.status(error.status).json({ return res.status(error.status).json({
status: error.status, status: error.status,

View file

@ -41,9 +41,9 @@ async function logMiddleware(req: Request, res: Response, next: NextFunction) {
let system = "org"; let system = "org";
if (req.url.startsWith("/api/v1/org/metadata/")) system="metadata"; if (req.url.startsWith("/api/v1/org/metadata/")) system="metadata";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin"; if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin"; if (req.url.startsWith("/api/v1/org/profile/")) system = "profile";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin"; // if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin"; // if (req.url.startsWith("/api/v1/org/auth/authRoleAttr/")) system = "admin";
const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4; const level = LOG_LEVEL_MAP[process.env.LOG_LEVEL ?? "debug"] || 4;