ผูก log เมนูทะเบียนประวัติ
This commit is contained in:
parent
5643cc67c4
commit
6539804937
76 changed files with 909 additions and 431 deletions
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateBloodGroup, BloodGroup } from "../entities/BloodGroup";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
@Route("api/v1/org/metadata/bloodGroup")
|
||||
@Tags("BloodGroup")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +42,7 @@ export class BloodGroupController extends Controller {
|
|||
async createBloodGroup(
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.bloodGroupRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -49,7 +51,7 @@ export class BloodGroupController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const bloodGroup = Object.assign(new BloodGroup(), requestBody);
|
||||
bloodGroup.createdUserId = request.user.sub;
|
||||
bloodGroup.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +59,8 @@ export class BloodGroupController extends Controller {
|
|||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
bloodGroup.lastUpdatedAt = new Date();
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
await this.bloodGroupRepository.save(bloodGroup, { data: request });
|
||||
setLogDataDiff(request, { before, after: bloodGroup });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ export class BloodGroupController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateBloodGroup,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const bloodGroup = await this.bloodGroupRepository.findOne({ where: { id: id } });
|
||||
if (!bloodGroup) {
|
||||
|
|
@ -87,12 +90,13 @@ export class BloodGroupController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(bloodGroup);
|
||||
bloodGroup.lastUpdateUserId = request.user.sub;
|
||||
bloodGroup.lastUpdateFullName = request.user.name;
|
||||
bloodGroup.lastUpdatedAt = new Date();
|
||||
this.bloodGroupRepository.merge(bloodGroup, requestBody);
|
||||
await this.bloodGroupRepository.save(bloodGroup);
|
||||
await this.bloodGroupRepository.save(bloodGroup, { data: request });
|
||||
setLogDataDiff(request, { before, after: bloodGroup });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -104,7 +108,7 @@ export class BloodGroupController extends Controller {
|
|||
* @param {string} id Id กลุ่มเลือด
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteBloodGroup(@Path() id: string) {
|
||||
async deleteBloodGroup(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delBloodGroup = await this.bloodGroupRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
|
|
@ -112,7 +116,7 @@ export class BloodGroupController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลกรุ๊ปเลือดนี้");
|
||||
}
|
||||
|
||||
await this.bloodGroupRepository.delete({ id: id });
|
||||
await this.bloodGroupRepository.remove(delBloodGroup,{ data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error";
|
|||
import { District, CreateDistrict, UpdateDistrict } from "../entities/District";
|
||||
import { Province } from "../entities/Province";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
@Route("api/v1/org/metadata/district")
|
||||
@Tags("District")
|
||||
|
|
@ -79,7 +81,7 @@ export class DistrictController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _district = Object.assign(new District(), requestBody);
|
||||
if (!_district) {
|
||||
|
|
@ -100,14 +102,15 @@ export class DistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_district.createdUserId = request.user.sub;
|
||||
_district.createdFullName = request.user.name;
|
||||
_district.createdAt = new Date();
|
||||
_district.lastUpdateUserId = request.user.sub;
|
||||
_district.lastUpdateFullName = request.user.name;
|
||||
_district.lastUpdatedAt = new Date();
|
||||
await this.districtRepository.save(_district);
|
||||
await this.districtRepository.save(_district, { data: request});
|
||||
setLogDataDiff(request, { before, after: _district });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -123,7 +126,7 @@ export class DistrictController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _district = await this.districtRepository.findOne({ where: { id: id } });
|
||||
if (!_district) {
|
||||
|
|
@ -143,12 +146,13 @@ export class DistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(_district);
|
||||
_district.lastUpdateUserId = request.user.sub;
|
||||
_district.lastUpdateFullName = request.user.name;
|
||||
_district.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateEducationLevel, EducationLevel } from "../entities/EducationLevel";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/metadata/educationLevel")
|
||||
@Tags("EducationLevel")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +42,7 @@ export class EducationLevelController extends Controller {
|
|||
async createEducationLevel(
|
||||
@Body()
|
||||
requestBody: CreateEducationLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.educationLevelRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -49,7 +51,7 @@ export class EducationLevelController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const educationLevel = Object.assign(new EducationLevel(), requestBody);
|
||||
educationLevel.createdUserId = request.user.sub;
|
||||
educationLevel.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +59,8 @@ export class EducationLevelController extends Controller {
|
|||
educationLevel.lastUpdateUserId = request.user.sub;
|
||||
educationLevel.lastUpdateFullName = request.user.name;
|
||||
educationLevel.lastUpdatedAt = new Date();
|
||||
await this.educationLevelRepository.save(educationLevel);
|
||||
await this.educationLevelRepository.save(educationLevel, { data: request });
|
||||
setLogDataDiff( request, { before, after: educationLevel } );
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ export class EducationLevelController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateEducationLevel,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const educationLevel = await this.educationLevelRepository.findOne({ where: { id: id } });
|
||||
if (!educationLevel) {
|
||||
|
|
@ -87,12 +90,13 @@ export class EducationLevelController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(educationLevel);
|
||||
educationLevel.lastUpdateUserId = request.user.sub;
|
||||
educationLevel.lastUpdateFullName = request.user.name;
|
||||
educationLevel.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -104,14 +108,14 @@ export class EducationLevelController extends Controller {
|
|||
* @param {string} id Id ระดับการศึกษา
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteEducationLevel(@Path() id: string) {
|
||||
async deleteEducationLevel(@Path() id: string , @Request() request: RequestWithUser) {
|
||||
const delEducationLevel = await this.educationLevelRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delEducationLevel) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลระดับการศึกษานี้");
|
||||
}
|
||||
await this.educationLevelRepository.delete({ id: id });
|
||||
await this.educationLevelRepository.remove(delEducationLevel,{ data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { Gender, CreateGender, UpdateGender } from "../entities/Gender";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
@Route("api/v1/org/metadata/gender")
|
||||
@Tags("Gender")
|
||||
|
|
@ -79,7 +81,7 @@ export class GenderController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateGender,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _gender = Object.assign(new Gender(), requestBody);
|
||||
if (!_gender) {
|
||||
|
|
@ -93,14 +95,15 @@ export class GenderController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_gender.createdUserId = request.user.sub;
|
||||
_gender.createdFullName = request.user.name;
|
||||
_gender.lastUpdateUserId = request.user.sub;
|
||||
_gender.lastUpdateFullName = request.user.name;
|
||||
_gender.createdAt = 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();
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +119,7 @@ export class GenderController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateGender,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _gender = await this.genderRepository.findOne({ where: { id: id } });
|
||||
if (!_gender) {
|
||||
|
|
@ -128,12 +131,13 @@ export class GenderController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(_gender);
|
||||
_gender.lastUpdateUserId = request.user.sub;
|
||||
_gender.lastUpdateFullName = request.user.name;
|
||||
_gender.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -145,14 +149,14 @@ export class GenderController extends Controller {
|
|||
* @param {string} id Id เพศ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const _delGender = await this.genderRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!_delGender) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลเพศนี้");
|
||||
}
|
||||
await this.genderRepository.delete(_delGender.id);
|
||||
await this.genderRepository.remove(_delGender, {data: request});
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { Prefixe, CreatePrefixe, UpdatePrefixe } from "../entities/Prefixe";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { request } from "axios";
|
||||
|
||||
@Route("api/v1/org/metadata/prefix")
|
||||
@Tags("Prefix")
|
||||
|
|
@ -78,7 +81,7 @@ export class PrefixController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreatePrefixe,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _prefix = Object.assign(new Prefixe(), requestBody);
|
||||
if (!_prefix) {
|
||||
|
|
@ -93,13 +96,15 @@ export class PrefixController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_prefix.createdUserId = request.user.sub;
|
||||
_prefix.createdFullName = request.user.name;
|
||||
_prefix.lastUpdateUserId = request.user.sub;
|
||||
_prefix.lastUpdateFullName = request.user.name;
|
||||
_prefix.createdAt = new Date();
|
||||
_prefix.lastUpdatedAt = new Date();
|
||||
await this.prefixRepository.save(_prefix);
|
||||
await this.prefixRepository.save(_prefix, { data: request });
|
||||
setLogDataDiff( request, { before, after: _prefix} )
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -115,7 +120,7 @@ export class PrefixController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdatePrefixe,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _prefix = await this.prefixRepository.findOne({ where: { id: id } });
|
||||
if (!_prefix) {
|
||||
|
|
@ -128,11 +133,13 @@ export class PrefixController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(_prefix);
|
||||
_prefix.lastUpdateUserId = request.user.sub;
|
||||
_prefix.lastUpdateFullName = request.user.name;
|
||||
_prefix.lastUpdatedAt = new Date();
|
||||
this.prefixRepository.merge(_prefix, requestBody);
|
||||
await this.prefixRepository.save(_prefix);
|
||||
await this.prefixRepository.save(_prefix, { data: request });
|
||||
setLogDataDiff(request, { before, after: _prefix });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -144,14 +151,14 @@ export class PrefixController extends Controller {
|
|||
* @param {string} id Id คำนำหน้า
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async Delete(@Path() id: string) {
|
||||
async Delete(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const _delPrefix = await this.prefixRepository.findOne({
|
||||
where: { id: id },
|
||||
});
|
||||
if (!_delPrefix) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลคำนำหน้าชื่อนี้");
|
||||
}
|
||||
await this.prefixRepository.delete(_delPrefix.id);
|
||||
await this.prefixRepository.remove(_delPrefix,{ data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import HttpError from "../interfaces/http-error";
|
|||
import HttpStatus from "../interfaces/http-status";
|
||||
import HttpSuccess from "../interfaces/http-success";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/ability")
|
||||
@Tags("ProfileAbility")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -66,10 +67,10 @@ export class ProfileAbilityController extends Controller {
|
|||
@Path() abilityId: string,
|
||||
@Request() req: RequestWithUser,
|
||||
) {
|
||||
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
}
|
||||
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
}
|
||||
|
||||
const record = await this.profileAbilityHistoryRepo.find({
|
||||
where: { profileAbilityId: abilityId },
|
||||
|
|
@ -83,9 +84,7 @@ export class ProfileAbilityController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{abilityId}")
|
||||
public async getProfileAbilityHistory(
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
public async getProfileAbilityHistory(@Path() abilityId: string) {
|
||||
const record = await this.profileAbilityHistoryRepo.find({
|
||||
where: { profileAbilityId: abilityId },
|
||||
order: { createdAt: "DESC" },
|
||||
|
|
@ -111,7 +110,7 @@ export class ProfileAbilityController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAbility();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -126,10 +125,11 @@ export class ProfileAbilityController extends Controller {
|
|||
const history = new ProfileAbilityHistory();
|
||||
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;
|
||||
await this.profileAbilityHistoryRepo.save(history);
|
||||
|
||||
await this.profileAbilityHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -144,7 +144,8 @@ export class ProfileAbilityController extends Controller {
|
|||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
||||
|
|
@ -160,8 +161,10 @@ export class ProfileAbilityController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
this.profileAbilityRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAbilityHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/ability")
|
||||
@Tags("ProfileAbilityEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -88,9 +89,7 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{abilityId}")
|
||||
public async getProfileAbilityHistory(
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
public async getProfileAbilityHistory(@Path() abilityId: string) {
|
||||
const record = await this.profileAbilityHistoryRepo.find({
|
||||
where: { profileAbilityId: abilityId },
|
||||
order: { createdAt: "DESC" },
|
||||
|
|
@ -115,7 +114,7 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAbility();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -130,9 +129,11 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
const history = new ProfileAbilityHistory();
|
||||
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;
|
||||
await this.profileAbilityHistoryRepo.save(history);
|
||||
await this.profileAbilityHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -150,7 +151,8 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -168,8 +170,10 @@ export class ProfileAbilityEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
this.profileAbilityRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAbilityHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import HttpStatus from "../interfaces/http-status";
|
|||
import HttpSuccess from "../interfaces/http-success";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/ability")
|
||||
@Tags("ProfileAbilityEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -84,9 +85,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{abilityId}")
|
||||
public async getProfileAbilityHistory(
|
||||
@Path() abilityId: string,
|
||||
) {
|
||||
public async getProfileAbilityHistory(@Path() abilityId: string) {
|
||||
const record = await this.profileAbilityHistoryRepo.find({
|
||||
where: { profileAbilityId: abilityId },
|
||||
order: { createdAt: "DESC" },
|
||||
|
|
@ -111,7 +110,7 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAbility();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -126,9 +125,11 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
const history = new ProfileAbilityHistory();
|
||||
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;
|
||||
await this.profileAbilityHistoryRepo.save(history);
|
||||
await this.profileAbilityHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -142,7 +143,8 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAbilityHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -160,8 +162,10 @@ export class ProfileAbilityEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAbilityRepo.save(record),
|
||||
this.profileAbilityHistoryRepo.save(history),
|
||||
this.profileAbilityRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAbilityHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile, ProfileAddressHistory, UpdateProfileAddress } from "../entities/Profile";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/address")
|
||||
@Tags("ProfileAddress")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -169,7 +170,8 @@ export class ProfileAddressController extends Controller {
|
|||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const record = await this.profileRepo.findOneBy({ id: profileId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -187,8 +189,10 @@ export class ProfileAddressController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileRepo.save(record),
|
||||
this.profileAddressHistoryRepo.save(history),
|
||||
this.profileRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAddressHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { ProfileAddressHistory } from "../entities/Profile";
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/address")
|
||||
@Tags("ProfileAddressEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -173,7 +174,8 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.id);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -191,8 +193,10 @@ export class ProfileAddressEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileEmployeeRepo.save(record),
|
||||
this.profileAddressHistoryRepo.save(history),
|
||||
this.profileEmployeeRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAddressHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import { ProfileAddressHistory } from "../entities/Profile";
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import { ProfileEmployee, UpdateProfileAddressEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/address")
|
||||
@Tags("ProfileAddressEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -173,7 +174,8 @@ export class ProfileAddressEmployeeTempController extends Controller {
|
|||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAddressHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -191,8 +193,10 @@ export class ProfileAddressEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileEmployeeRepo.save(record),
|
||||
this.profileAddressHistoryRepo.save(history),
|
||||
this.profileEmployeeRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAddressHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/assessments")
|
||||
@Tags("ProfileAssessments")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -123,7 +124,7 @@ export class ProfileAssessmentsController extends Controller {
|
|||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
}
|
||||
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAssessment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -137,9 +138,11 @@ export class ProfileAssessmentsController extends Controller {
|
|||
const history = new ProfileAssessmentHistory();
|
||||
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;
|
||||
await this.profileAssessmentsHistoryRepository.save(history);
|
||||
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
|
||||
setLogDataDiff( req, { before, after: history } );
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -153,7 +156,8 @@ export class ProfileAssessmentsController extends Controller {
|
|||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -171,8 +175,10 @@ export class ProfileAssessmentsController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
this.profileAssessmentsRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
|
||||
setLogDataDiff(req, { before, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/assessments")
|
||||
@Tags("ProfileEmployeeAssessments")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -120,7 +121,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAssessment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -134,9 +135,11 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
const history = new ProfileAssessmentHistory();
|
||||
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;
|
||||
await this.profileAssessmentsHistoryRepository.save(history);
|
||||
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
|
||||
setLogDataDiff( req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -155,6 +158,8 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -172,8 +177,10 @@ export class ProfileAssessmentsEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
this.profileAssessmentsRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileAssessmentHistory } from "../entities/ProfileAssessmentHistory";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/assessments")
|
||||
@Tags("ProfileEmployeeAssessments")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -88,9 +89,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{assessmentId}")
|
||||
public async getProfileAssessmentsHistory(
|
||||
@Path() assessmentId: string,
|
||||
) {
|
||||
public async getProfileAssessmentsHistory(@Path() assessmentId: string) {
|
||||
const record = await this.profileAssessmentsHistoryRepository.find({
|
||||
where: {
|
||||
profileAssessmentId: assessmentId,
|
||||
|
|
@ -119,7 +118,7 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileAssessment();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -133,9 +132,11 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
const history = new ProfileAssessmentHistory();
|
||||
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;
|
||||
await this.profileAssessmentsHistoryRepository.save(history);
|
||||
await this.profileAssessmentsHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -149,7 +150,8 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileAssessmentHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -167,8 +169,10 @@ export class ProfileAssessmentsEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileAssessmentsRepository.save(record),
|
||||
this.profileAssessmentsHistoryRepository.save(history),
|
||||
this.profileAssessmentsRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileAssessmentsHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/certificate")
|
||||
@Tags("ProfileCertificate")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -56,7 +57,10 @@ export class ProfileCertificateController extends Controller {
|
|||
}
|
||||
|
||||
@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 });
|
||||
if (_record) {
|
||||
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 ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileCertificate();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -112,9 +116,11 @@ export class ProfileCertificateController extends Controller {
|
|||
const history = new ProfileCertificateHistory();
|
||||
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;
|
||||
await this.certificateHistoryRepo.save(history);
|
||||
await this.certificateHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -128,7 +134,8 @@ export class ProfileCertificateController extends Controller {
|
|||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -146,8 +153,10 @@ export class ProfileCertificateController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
this.certificateRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.certificateHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/certificate")
|
||||
@Tags("ProfileEmployeeCertificate")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -56,7 +57,10 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@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 });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(
|
||||
|
|
@ -73,7 +77,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
});
|
||||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
|
||||
@Get("history/{certificateId}")
|
||||
public async certificateHistory(@Path() certificateId: string) {
|
||||
const record = await this.certificateHistoryRepo.find({
|
||||
|
|
@ -100,6 +104,7 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileCertificate();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -115,9 +120,11 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
const history = new ProfileCertificateHistory();
|
||||
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;
|
||||
await this.certificateHistoryRepo.save(history);
|
||||
await this.certificateHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -135,7 +142,8 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -153,8 +161,10 @@ export class ProfileCertificateEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
this.certificateRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.certificateHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileCertificateHistory } from "../entities/ProfileCertificateHistory
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/certificate")
|
||||
@Tags("ProfileEmployeeCertificate")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -87,7 +88,7 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
if (!body.profileEmployeeId) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
|
||||
|
||||
if (!profile) {
|
||||
|
|
@ -109,9 +110,11 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
const history = new ProfileCertificateHistory();
|
||||
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;
|
||||
await this.certificateHistoryRepo.save(history);
|
||||
await this.certificateHistoryRepo.save(history, { data: req });
|
||||
setLogDataDiff( req , {before, after: history});
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -126,7 +129,8 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
const record = await this.certificateRepo.findOneBy({ id: certificateId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileCertificateHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -144,10 +148,12 @@ export class ProfileCertificateEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.certificateRepo.save(record),
|
||||
this.certificateHistoryRepo.save(history),
|
||||
this.certificateRepo.save(record, { data: req }),
|
||||
setLogDataDiff( req , {before, after: record}),
|
||||
this.certificateHistoryRepo.save(history, { data: req }),
|
||||
setLogDataDiff( req , {before: before_null, after: history}),
|
||||
]);
|
||||
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
} from "../entities/ProfileChangeName";
|
||||
import { updateName } from "../keycloak";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/changeName")
|
||||
@Tags("ProfileChangeName")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -83,7 +84,7 @@ export class ProfileChangeNameController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChangeName();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -101,12 +102,13 @@ export class ProfileChangeNameController extends Controller {
|
|||
|
||||
await this.changeNameRepository.save(data);
|
||||
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.lastName = body.lastName ?? profile.lastName;
|
||||
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) {
|
||||
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 });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -145,8 +148,10 @@ export class ProfileChangeNameController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
this.changeNameRepository.save(record, { data: req }),
|
||||
setLogDataDiff( req , {before, after: record}),
|
||||
this.changeNameHistoryRepository.save(history, { data: req }),
|
||||
setLogDataDiff( req , {before: before_null, after: history}),
|
||||
]);
|
||||
|
||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||
|
|
@ -158,14 +163,15 @@ export class ProfileChangeNameController extends Controller {
|
|||
},
|
||||
});
|
||||
if (!chkLastRecord) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
|
||||
const profile = await this.profileRepository.findOneBy({ id: record.profileId });
|
||||
|
||||
const before_profile = structuredClone(profile);
|
||||
if (profile && chkLastRecord.id === record.id) {
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
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
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { updateName } from "../keycloak";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/changeName")
|
||||
@Tags("ProfileChangeNameEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -87,7 +88,7 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChangeName();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -103,14 +104,17 @@ export class ProfileChangeNameEmployeeController extends Controller {
|
|||
const history = new ProfileChangeNameHistory();
|
||||
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;
|
||||
await this.changeNameHistoryRepository.save(history);
|
||||
await this.changeNameHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
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) {
|
||||
const result = await updateName(profile.keycloak, profile.firstName, profile.lastName);
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { updateName } from "../keycloak";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/changeName")
|
||||
@Tags("ProfileChangeNameEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -81,7 +82,7 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChangeName();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -97,14 +98,17 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
const history = new ProfileChangeNameHistory();
|
||||
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;
|
||||
await this.changeNameHistoryRepository.save(history);
|
||||
await this.changeNameHistoryRepository.save(history, { data: req });
|
||||
setLogDataDiff( req , {before, after: history});
|
||||
|
||||
profile.firstName = body.firstName ?? profile.firstName;
|
||||
profile.lastName = body.lastName ?? profile.lastName;
|
||||
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) {
|
||||
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 });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileChangeNameHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -144,8 +149,10 @@ export class ProfileChangeNameEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.changeNameRepository.save(record),
|
||||
this.changeNameHistoryRepository.save(history),
|
||||
this.changeNameRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.changeNameHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
const chkLastRecord = await this.changeNameRepository.findOne({
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
} from "../entities/ProfileChildren";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -76,7 +77,7 @@ export class ProfileChildrenController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChildren();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -93,9 +94,11 @@ export class ProfileChildrenController extends Controller {
|
|||
const history = new ProfileChildrenHistory();
|
||||
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;
|
||||
await this.childrenHistoryRepository.save(history);
|
||||
await this.childrenHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -109,7 +112,8 @@ export class ProfileChildrenController extends Controller {
|
|||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
|
@ -126,8 +130,10 @@ export class ProfileChildrenController extends Controller {
|
|||
history.createdAt = new Date();
|
||||
history.lastUpdatedAt = new Date();
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
this.childrenRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.childrenHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -83,7 +84,7 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -101,10 +102,11 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
const history = new ProfileChildrenHistory();
|
||||
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;
|
||||
await this.childrenHistoryRepository.save(history);
|
||||
|
||||
await this.childrenHistoryRepository.save(history, { data: req });
|
||||
setLogDataDiff( req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -121,7 +123,8 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
|
@ -139,8 +142,10 @@ export class ProfileChildrenEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
this.childrenRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.childrenHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/family/children")
|
||||
@Tags("ProfileChildren")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -77,7 +78,7 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileChildren();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -94,9 +95,11 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
const history = new ProfileChildrenHistory();
|
||||
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;
|
||||
await this.childrenHistoryRepository.save(history);
|
||||
await this.childrenHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -110,7 +113,8 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.childrenRepository.findOneBy({ id: childrenId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileChildrenHistory();
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
|
@ -128,8 +132,10 @@ export class ProfileChildrenEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.childrenRepository.save(record),
|
||||
this.childrenHistoryRepository.save(history),
|
||||
this.childrenRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.childrenHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
UpdateProfileDiscipline,
|
||||
} from "../entities/ProfileDiscipline";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/discipline")
|
||||
@Tags("ProfileDiscipline")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -66,7 +67,10 @@ export class ProfileDisciplineController extends Controller {
|
|||
}
|
||||
|
||||
@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 });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_OFFICER", _record.profileId);
|
||||
|
|
@ -87,7 +91,7 @@ export class ProfileDisciplineController extends Controller {
|
|||
return new HttpSuccess(record);
|
||||
}
|
||||
|
||||
@Post()
|
||||
@Post()
|
||||
public async newDiscipline(
|
||||
@Request() req: RequestWithUser,
|
||||
@Body() body: CreateProfileDiscipline,
|
||||
|
|
@ -102,7 +106,7 @@ export class ProfileDisciplineController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDiscipline();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -118,9 +122,11 @@ export class ProfileDisciplineController extends Controller {
|
|||
const history = new ProfileDisciplineHistory();
|
||||
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;
|
||||
await this.disciplineHistoryRepository.save(history);
|
||||
await this.disciplineHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -134,7 +140,8 @@ export class ProfileDisciplineController extends Controller {
|
|||
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -152,8 +159,10 @@ export class ProfileDisciplineController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
this.disciplineRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.disciplineHistoryRepository.save(history, { data: req }),
|
||||
setLogDataDiff(req, { before, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
} from "../entities/ProfileDiscipline";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/discipline")
|
||||
@Tags("ProfileDisciplineEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -66,7 +67,10 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@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 });
|
||||
if (_record) {
|
||||
await new permission().PermissionOrgUserGet(
|
||||
|
|
@ -105,7 +109,7 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDiscipline();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -121,10 +125,11 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
const history = new ProfileDisciplineHistory();
|
||||
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;
|
||||
await this.disciplineHistoryRepository.save(history);
|
||||
|
||||
await this.disciplineHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -141,7 +146,8 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -159,8 +165,10 @@ export class ProfileDisciplineEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
this.disciplineRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.disciplineHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
} from "../entities/ProfileDiscipline";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/discipline")
|
||||
@Tags("ProfileDisciplineEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -66,7 +67,10 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
}
|
||||
|
||||
@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");
|
||||
const record = await this.disciplineHistoryRepository.find({
|
||||
where: { profileDisciplineId: disciplineId },
|
||||
|
|
@ -99,7 +103,7 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDiscipline();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -115,9 +119,11 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
const history = new ProfileDisciplineHistory();
|
||||
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;
|
||||
await this.disciplineHistoryRepository.save(history);
|
||||
await this.disciplineHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -132,7 +138,8 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileDisciplineHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -150,8 +157,10 @@ export class ProfileDisciplineEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.disciplineRepository.save(record),
|
||||
this.disciplineHistoryRepository.save(history),
|
||||
this.disciplineRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.disciplineHistoryRepository.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { CreateProfileDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/duty")
|
||||
@Tags("ProfileDuty")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -65,7 +66,7 @@ export class ProfileDutyController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{dutyId}")
|
||||
public async dutyHistory(@Path() dutyId: string,) {
|
||||
public async dutyHistory(@Path() dutyId: string) {
|
||||
const record = await this.dutyHistoryRepository.find({
|
||||
where: { profileDutyId: dutyId },
|
||||
order: { createdAt: "DESC" },
|
||||
|
|
@ -84,7 +85,7 @@ export class ProfileDutyController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDuty();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -100,10 +101,11 @@ export class ProfileDutyController extends Controller {
|
|||
const history = new ProfileDutyHistory();
|
||||
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;
|
||||
await this.dutyHistoryRepository.save(history);
|
||||
|
||||
await this.dutyHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +118,8 @@ export class ProfileDutyController extends Controller {
|
|||
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -133,7 +136,12 @@ export class ProfileDutyController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/duty")
|
||||
@Tags("ProfileEmployeeDuty")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -88,7 +89,7 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDuty();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -104,9 +105,11 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
const history = new ProfileDutyHistory();
|
||||
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;
|
||||
await this.dutyHistoryRepository.save(history);
|
||||
await this.dutyHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -124,7 +127,8 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -141,7 +145,12 @@ export class ProfileDutyEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { CreateProfileEmployeeDuty, ProfileDuty, UpdateProfileDuty } from "../entities/ProfileDuty";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/duty")
|
||||
@Tags("ProfileEmployeeDuty")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -82,7 +83,7 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileDuty();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -98,9 +99,11 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
const history = new ProfileDutyHistory();
|
||||
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;
|
||||
await this.dutyHistoryRepository.save(history);
|
||||
await this.dutyHistoryRepository.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -115,7 +118,8 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
const record = await this.dutyRepository.findOneBy({ id: dutyId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileDutyHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -132,7 +136,12 @@ export class ProfileDutyEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import { Profile } from "../entities/Profile";
|
|||
import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
||||
import { AppDataSource } from "../database/data-source";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/educations")
|
||||
@Tags("ProfileEducations")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -85,9 +86,7 @@ export class ProfileEducationsController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{educationId}")
|
||||
public async getProfileEducationHistory(
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
public async getProfileEducationHistory(@Path() educationId: string) {
|
||||
const record = await this.profileEducationHistoryRepo.find({
|
||||
where: {
|
||||
profileEducationId: educationId,
|
||||
|
|
@ -114,7 +113,7 @@ export class ProfileEducationsController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileEducation();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -129,9 +128,11 @@ export class ProfileEducationsController extends Controller {
|
|||
const history = new ProfileEducationHistory();
|
||||
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;
|
||||
await this.profileEducationHistoryRepo.save(history);
|
||||
await this.profileEducationHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -145,7 +146,8 @@ export class ProfileEducationsController extends Controller {
|
|||
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -163,8 +165,10 @@ export class ProfileEducationsController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
this.profileEducationRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileEducationHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/educations")
|
||||
@Tags("ProfileEducationsEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -91,9 +92,7 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{educationId}")
|
||||
public async getProfileEducationHistory(
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
public async getProfileEducationHistory(@Path() educationId: string) {
|
||||
const record = await this.profileEducationHistoryRepo.find({
|
||||
where: {
|
||||
profileEducationId: educationId,
|
||||
|
|
@ -120,7 +119,7 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileEducation();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -135,9 +134,11 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
const history = new ProfileEducationHistory();
|
||||
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;
|
||||
await this.profileEducationHistoryRepo.save(history);
|
||||
await this.profileEducationHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -155,7 +156,8 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const before_null = null;
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -173,8 +175,10 @@ export class ProfileEducationsEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
this.profileEducationRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileEducationHistoryRepo.save(history, { data: req }),
|
||||
setLogDataDiff(req, { before, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileEducationHistory } from "../entities/ProfileEducationHistory";
|
|||
import { AppDataSource } from "../database/data-source";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/educations")
|
||||
@Tags("ProfileEducationsEmployee")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -83,9 +84,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
}
|
||||
|
||||
@Get("history/{educationId}")
|
||||
public async getProfileEducationHistory(
|
||||
@Path() educationId: string,
|
||||
) {
|
||||
public async getProfileEducationHistory(@Path() educationId: string) {
|
||||
const record = await this.profileEducationHistoryRepo.find({
|
||||
where: {
|
||||
profileEducationId: educationId,
|
||||
|
|
@ -112,7 +111,7 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileEducation();
|
||||
const meta = {
|
||||
createdUserId: req.user.sub,
|
||||
|
|
@ -127,10 +126,11 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
const history = new ProfileEducationHistory();
|
||||
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;
|
||||
await this.profileEducationHistoryRepo.save(history);
|
||||
|
||||
await this.profileEducationHistoryRepo.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -143,7 +143,8 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const record = await this.profileEducationRepo.findOneBy({ id: educationId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
// const before_null = null;
|
||||
const history = new ProfileEducationHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -161,8 +162,10 @@ export class ProfileEducationsEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.profileEducationRepo.save(record),
|
||||
this.profileEducationHistoryRepo.save(history),
|
||||
this.profileEducationRepo.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.profileEducationHistoryRepo.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/family/couple")
|
||||
@Tags("ProfileFamilyCouple")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -165,6 +166,7 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
const before = null;
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
familyCouple.createdUserId = req.user.sub;
|
||||
familyCouple.createdFullName = req.user.name;
|
||||
|
|
@ -177,11 +179,13 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
await this.profileRepo.save(profile);
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
await this.profileRepo.save(profile, { data: req });
|
||||
setLogDataDiff(req, { before, after: profile });
|
||||
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
|
||||
setLogDataDiff(req, { before, after: familyCouple });
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +198,8 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ profileId: profileId });
|
||||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyCouple);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(familyCouple, body);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
|
@ -212,8 +217,10 @@ export class ProfileFamilyCoupleController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
this.ProfileFamilyCouple.save(familyCouple, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyCouple }),
|
||||
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/family/couple")
|
||||
@Tags("ProfileEmployeeFamilyCouple")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -168,7 +169,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
|
||||
familyCouple.createdUserId = req.user.sub;
|
||||
familyCouple.createdFullName = req.user.name;
|
||||
|
|
@ -181,10 +182,13 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
await this.profileRepo.save(profile);
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
await this.profileRepo.save(profile, { data: req });
|
||||
setLogDataDiff(req, { before, after: profile });
|
||||
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
|
||||
setLogDataDiff(req, { before, after: familyCouple });
|
||||
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);
|
||||
}
|
||||
|
|
@ -200,7 +204,8 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyCouple);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(familyCouple, body);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
|
@ -218,8 +223,10 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
this.ProfileFamilyCouple.save(familyCouple, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyCouple }),
|
||||
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyCoupleHistory } from "../entities/ProfileFamilyCoupleHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/family/couple")
|
||||
@Tags("ProfileEmployeeFamilyCouple")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -161,6 +162,7 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
@Body() body: CreateProfileEmployeeFamilyCouple,
|
||||
) {
|
||||
await new permission().PermissionUpdate(req, "SYS_REGISTRY_TEMP");
|
||||
const before = null;
|
||||
const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
|
||||
if (!familyCouple) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
|
@ -182,10 +184,13 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
||||
await this.profileRepo.save(profile);
|
||||
await this.ProfileFamilyCouple.save(familyCouple);
|
||||
await this.profileRepo.save(profile, { data: req });
|
||||
setLogDataDiff(req, { before, after: profile });
|
||||
await this.ProfileFamilyCouple.save(familyCouple, { data: req });
|
||||
setLogDataDiff(req, { before, after: familyCouple });
|
||||
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);
|
||||
}
|
||||
|
|
@ -201,7 +206,8 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
if (!familyCouple) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyCouple);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyCoupleHistory();
|
||||
Object.assign(familyCouple, body);
|
||||
Object.assign(history, { ...familyCouple, id: undefined });
|
||||
|
|
@ -219,8 +225,10 @@ export class ProfileFamilyCoupleEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyCouple.save(familyCouple),
|
||||
this.ProfileFamilyCoupleHistory.save(history),
|
||||
this.ProfileFamilyCouple.save(familyCouple, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyCouple }),
|
||||
this.ProfileFamilyCoupleHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/family/father")
|
||||
@Tags("ProfileFamilyFather")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -158,6 +159,7 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const before = null;
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
familyFather.createdUserId = req.user.sub;
|
||||
|
|
@ -170,10 +172,11 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
const history = new ProfileFamilyFatherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
|
||||
await this.ProfileFamilyFatherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +189,8 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const familyFather = await this.ProfileFamilyFather.findOneBy({ profileId: profileId });
|
||||
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyFather);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(familyFather, body);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
|
@ -204,8 +208,10 @@ export class ProfileFamilyFatherController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
this.ProfileFamilyFather.save(familyFather, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyFather }),
|
||||
this.ProfileFamilyFatherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/family/father")
|
||||
@Tags("ProfileEmployeeFamilyFather")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -161,6 +162,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
const before = null;
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
familyFather.createdUserId = req.user.sub;
|
||||
familyFather.createdFullName = req.user.name;
|
||||
|
|
@ -172,9 +174,11 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
const history = new ProfileFamilyFatherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
await this.ProfileFamilyFatherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
|
@ -190,7 +194,8 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
if (!familyFather) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyFather);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(familyFather, body);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
|
@ -208,8 +213,10 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
this.ProfileFamilyFather.save(familyFather, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyFather }),
|
||||
this.ProfileFamilyFatherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyFatherHistory } from "../entities/ProfileFamilyFatherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/family/father")
|
||||
@Tags("ProfileEmployeeFamilyFather")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -162,6 +163,7 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const before = null;
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
familyFather.createdUserId = req.user.sub;
|
||||
familyFather.createdFullName = req.user.name;
|
||||
|
|
@ -173,9 +175,11 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
const history = new ProfileFamilyFatherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyFatherHistory.save(history);
|
||||
await this.ProfileFamilyFatherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess(familyFather.id);
|
||||
}
|
||||
|
|
@ -195,7 +199,8 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
const history = new ProfileFamilyFatherHistory();
|
||||
Object.assign(familyFather, body);
|
||||
Object.assign(history, { ...familyFather, id: undefined });
|
||||
|
||||
const before = structuredClone(familyFather);
|
||||
// const before_null = null;
|
||||
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
|
||||
history.profileFamilyFatherId = familyFather.id;
|
||||
familyFather.lastUpdateUserId = req.user.sub;
|
||||
|
|
@ -209,8 +214,10 @@ export class ProfileFamilyFatherEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyFather.save(familyFather),
|
||||
this.ProfileFamilyFatherHistory.save(history),
|
||||
this.ProfileFamilyFather.save(familyFather, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyFather }),
|
||||
this.ProfileFamilyFatherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/family/mother")
|
||||
@Tags("ProfileFamilyMother")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -158,6 +159,7 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
const before = null;
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
familyMother.createdUserId = req.user.sub;
|
||||
familyMother.createdFullName = req.user.name;
|
||||
|
|
@ -169,9 +171,11 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
const history = new ProfileFamilyMotherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
await this.ProfileFamilyMotherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
|
@ -185,7 +189,8 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profileId);
|
||||
const familyMother = await this.ProfileFamilyMother.findOneBy({ profileId: profileId });
|
||||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyMother);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(familyMother, body);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
|
@ -203,8 +208,10 @@ export class ProfileFamilyMotherController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
this.ProfileFamilyMother.save(familyMother, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyMother }),
|
||||
this.ProfileFamilyMotherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/family/mother")
|
||||
@Tags("ProfileEmployeeFamilyMother")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -161,6 +162,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
const before = null;
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
familyMother.createdUserId = req.user.sub;
|
||||
familyMother.createdFullName = req.user.name;
|
||||
|
|
@ -172,10 +174,11 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
const history = new ProfileFamilyMotherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
|
||||
await this.ProfileFamilyMotherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +197,8 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(familyMother, body);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
||||
const before = structuredClone(familyMother);
|
||||
// const before_null = null;
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
history.profileFamilyMotherId = familyMother.id;
|
||||
familyMother.lastUpdateUserId = req.user.sub;
|
||||
|
|
@ -208,8 +212,10 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
this.ProfileFamilyMother.save(familyMother, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyMother }),
|
||||
this.ProfileFamilyMotherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
import { ProfileFamilyMotherHistory } from "../entities/ProfileFamilyMotherHistory";
|
||||
import Extension from "../interfaces/extension";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/family/mother")
|
||||
@Tags("ProfileEmployeeFamilyMother")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -162,6 +163,7 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
const before = null;
|
||||
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
|
||||
familyMother.createdUserId = req.user.sub;
|
||||
familyMother.createdFullName = req.user.name;
|
||||
|
|
@ -173,10 +175,11 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
const history = new ProfileFamilyMotherHistory();
|
||||
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;
|
||||
await this.ProfileFamilyMotherHistory.save(history);
|
||||
|
||||
await this.ProfileFamilyMotherHistory.save(history, { data: req });
|
||||
//setLogDataDiff(req, { before, after: history });
|
||||
return new HttpSuccess(familyMother.id);
|
||||
}
|
||||
|
||||
|
|
@ -191,7 +194,8 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
profileEmployeeId: profileEmployeeId,
|
||||
});
|
||||
if (!familyMother) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(familyMother);
|
||||
// const before_null = null;
|
||||
const history = new ProfileFamilyMotherHistory();
|
||||
Object.assign(familyMother, body);
|
||||
Object.assign(history, { ...familyMother, id: undefined });
|
||||
|
|
@ -209,8 +213,10 @@ export class ProfileFamilyMotherEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.ProfileFamilyMother.save(familyMother),
|
||||
this.ProfileFamilyMotherHistory.save(history),
|
||||
this.ProfileFamilyMother.save(familyMother, { data: req }),
|
||||
setLogDataDiff(req, { before, after: familyMother }),
|
||||
this.ProfileFamilyMotherHistory.save(history, { data: req }),
|
||||
// setLogDataDiff(req, { before: before_null, after: history }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import { Profile } from "../entities/Profile";
|
|||
import { ProfileGovernment, UpdateProfileGovernment } from "../entities/ProfileGovernment";
|
||||
import { Position } from "../entities/Position";
|
||||
import { PosMaster } from "../entities/PosMaster";
|
||||
import { calculateAge, calculateRetireDate } from "../interfaces/utils";
|
||||
import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import permission from "../interfaces/permission";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
@Route("api/v1/org/profile/government")
|
||||
|
|
@ -385,7 +385,7 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -402,7 +402,11 @@ export class ProfileGovernmentHistoryController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
} from "../entities/ProfileGovernment";
|
||||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { calculateAge, calculateRetireDate } from "../interfaces/utils";
|
||||
import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import permission from "../interfaces/permission";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
@Route("api/v1/org/profile-employee/government")
|
||||
|
|
@ -368,6 +368,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -384,7 +385,10 @@ export class ProfileGovernmentEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import {
|
|||
} from "../entities/ProfileGovernment";
|
||||
import { EmployeePosition } from "../entities/EmployeePosition";
|
||||
import { EmployeePosMaster } from "../entities/EmployeePosMaster";
|
||||
import { calculateAge, calculateRetireDate } from "../interfaces/utils";
|
||||
import { calculateAge, calculateRetireDate, setLogDataDiff } from "../interfaces/utils";
|
||||
import permission from "../interfaces/permission";
|
||||
import { OrgRevision } from "../entities/OrgRevision";
|
||||
@Route("api/v1/org/profile-temp/government")
|
||||
|
|
@ -369,6 +369,7 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
|
|||
});
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileGovernment();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -385,7 +386,11 @@ export class ProfileGovernmentEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/honor")
|
||||
@Tags("ProfileHonor")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -111,7 +112,7 @@ export class ProfileHonorController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileHonor();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -127,9 +128,10 @@ export class ProfileHonorController extends Controller {
|
|||
const history = new ProfileHonorHistory();
|
||||
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;
|
||||
await this.honorHistoryRepo.save(history);
|
||||
await this.honorHistoryRepo.save(history, {data: req});
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -148,7 +150,7 @@ export class ProfileHonorController extends Controller {
|
|||
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
||||
const before = structuredClone(record);
|
||||
history.profileHonorId = honorId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
|
@ -160,7 +162,11 @@ export class ProfileHonorController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/honor")
|
||||
@Tags("ProfileEmployeeHonor")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -119,7 +120,7 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileHonor();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -135,9 +136,10 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
const history = new ProfileHonorHistory();
|
||||
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;
|
||||
await this.honorHistoryRepo.save(history);
|
||||
await this.honorHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -155,7 +157,7 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -172,7 +174,11 @@ export class ProfileHonorEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileHonorHistory } from "../entities/ProfileHonorHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/honor")
|
||||
@Tags("ProfileEmployeeHonor")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -112,7 +113,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileHonor();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -128,9 +129,10 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
const history = new ProfileHonorHistory();
|
||||
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;
|
||||
await this.honorHistoryRepo.save(history);
|
||||
await this.honorHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -145,7 +147,7 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
const record = await this.honorRepo.findOneBy({ id: honorId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileHonorHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -162,7 +164,11 @@ export class ProfileHonorEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { Insignia } from "../entities/Insignia";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/insignia")
|
||||
@Tags("ProfileInsignia")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -124,7 +125,7 @@ export class ProfileInsigniaController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileInsignia();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -140,9 +141,10 @@ export class ProfileInsigniaController extends Controller {
|
|||
const history = new ProfileInsigniaHistory();
|
||||
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;
|
||||
await this.insigniaHistoryRepo.save(history);
|
||||
await this.insigniaHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -163,7 +165,7 @@ export class ProfileInsigniaController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -180,7 +182,11 @@ export class ProfileInsigniaController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { Insignia } from "../entities/Insignia";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/insignia")
|
||||
@Tags("ProfileEmployeeInsignia")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -128,7 +129,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileInsignia();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -144,9 +145,10 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
const history = new ProfileInsigniaHistory();
|
||||
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;
|
||||
await this.insigniaHistoryRepo.save(history);
|
||||
await this.insigniaHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -171,7 +173,7 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -188,7 +190,11 @@ export class ProfileInsigniaEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { Insignia } from "../entities/Insignia";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/insignia")
|
||||
@Tags("ProfileEmployeeInsignia")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -122,7 +123,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileInsignia();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -138,9 +139,10 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
const history = new ProfileInsigniaHistory();
|
||||
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;
|
||||
await this.insigniaHistoryRepo.save(history);
|
||||
await this.insigniaHistoryRepo.save(history, { data:req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -162,7 +164,7 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
if (!insignia) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลเครื่องราชฯ นี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileInsigniaHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -179,7 +181,11 @@ export class ProfileInsigniaEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { LeaveType } from "../entities/LeaveType";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/leave")
|
||||
@Tags("ProfileLeave")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -188,7 +189,7 @@ export class ProfileLeaveController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileLeave();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -204,9 +205,10 @@ export class ProfileLeaveController extends Controller {
|
|||
const history = new ProfileLeaveHistory();
|
||||
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;
|
||||
await this.leaveHistoryRepo.save(history);
|
||||
await this.leaveHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -227,7 +229,7 @@ export class ProfileLeaveController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -244,7 +246,11 @@ export class ProfileLeaveController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { LeaveType } from "../entities/LeaveType";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/leave")
|
||||
@Tags("ProfileLeave")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -116,7 +117,7 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileLeave();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -132,9 +133,10 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
const history = new ProfileLeaveHistory();
|
||||
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;
|
||||
await this.leaveHistoryRepo.save(history);
|
||||
await this.leaveHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -159,7 +161,7 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -176,7 +178,11 @@ export class ProfileLeaveEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { LeaveType } from "../entities/LeaveType";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/leave")
|
||||
@Tags("ProfileLeave")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -109,7 +110,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileLeave();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -149,7 +150,7 @@ export class ProfileLeaveEmployeeTempController extends Controller {
|
|||
if (!leaveType) {
|
||||
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลประเภทลานี้");
|
||||
}
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileLeaveHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -166,7 +167,11 @@ export class ProfileLeaveEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { CreateProfileNopaid, ProfileNopaid, UpdateProfileNopaid } from "../entities/ProfileNopaid";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/nopaid")
|
||||
@Tags("ProfileNopaid")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -75,7 +76,7 @@ export class ProfileNopaidController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileNopaid();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -91,9 +92,10 @@ export class ProfileNopaidController extends Controller {
|
|||
const history = new ProfileNopaidHistory();
|
||||
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;
|
||||
await this.nopaidHistoryRepository.save(history);
|
||||
await this.nopaidHistoryRepository.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -107,7 +109,7 @@ export class ProfileNopaidController extends Controller {
|
|||
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -125,8 +127,9 @@ export class ProfileNopaidController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
this.nopaidRepository.save(record, { data: req }),
|
||||
setLogDataDiff( req, { before, after: record } ),
|
||||
this.nopaidHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
UpdateProfileNopaid,
|
||||
} from "../entities/ProfileNopaid";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/nopaid")
|
||||
@Tags("ProfileNopaid")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -79,7 +80,7 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileNopaid();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -95,9 +96,10 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
const history = new ProfileNopaidHistory();
|
||||
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;
|
||||
await this.nopaidHistoryRepository.save(history);
|
||||
await this.nopaidHistoryRepository.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -116,6 +118,7 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -133,8 +136,9 @@ export class ProfileNopaidEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
this.nopaidRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.nopaidHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
UpdateProfileNopaid,
|
||||
} from "../entities/ProfileNopaid";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/nopaid")
|
||||
@Tags("ProfileNopaid")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -80,7 +81,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileNopaid();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -96,9 +97,10 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
const history = new ProfileNopaidHistory();
|
||||
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;
|
||||
await this.nopaidHistoryRepository.save(history);
|
||||
await this.nopaidHistoryRepository.save(history, {data: req});
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -113,7 +115,7 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileNopaidHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -131,8 +133,9 @@ export class ProfileNopaidEmployeeTempController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.nopaidRepository.save(record),
|
||||
this.nopaidHistoryRepository.save(history),
|
||||
this.nopaidRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.nopaidHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { CreateProfileOther, ProfileOther, UpdateProfileOther } from "../entities/ProfileOther";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/other")
|
||||
@Tags("ProfileOther")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -56,7 +57,6 @@ export class ProfileOtherController extends Controller {
|
|||
public async otherAdminHistory(@Path() otherId: string, @Request() req: RequestWithUser) {
|
||||
|
||||
const _record = await this.otherRepository.findOneBy({ id: otherId });
|
||||
console.log(">>>>", _record);
|
||||
if (_record) {
|
||||
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 ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileOther();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -103,9 +103,10 @@ export class ProfileOtherController extends Controller {
|
|||
const history = new ProfileOtherHistory();
|
||||
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;
|
||||
await this.otherHistoryRepository.save(history);
|
||||
await this.otherHistoryRepository.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -119,7 +120,7 @@ export class ProfileOtherController extends Controller {
|
|||
const record = await this.otherRepository.findOneBy({ id: otherId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -137,8 +138,9 @@ export class ProfileOtherController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
this.otherHistoryRepository.save(history),
|
||||
this.otherRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.otherHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import {
|
|||
UpdateProfileOther,
|
||||
} from "../entities/ProfileOther";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/other")
|
||||
@Tags("ProfileOther")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -92,7 +93,7 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileOther();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -108,9 +109,10 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
const history = new ProfileOtherHistory();
|
||||
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;
|
||||
await this.otherHistoryRepository.save(history);
|
||||
await this.otherHistoryRepository.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -128,7 +130,7 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileOtherHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -146,8 +148,9 @@ export class ProfileOtherEmployeeController extends Controller {
|
|||
history.lastUpdatedAt = new Date();
|
||||
|
||||
await Promise.all([
|
||||
this.otherRepository.save(record),
|
||||
this.otherHistoryRepository.save(history),
|
||||
this.otherRepository.save(record, { data: req }),
|
||||
setLogDataDiff(req, { before, after: record }),
|
||||
this.otherHistoryRepository.save(history, { data: req }),
|
||||
]);
|
||||
|
||||
return new HttpSuccess();
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import {
|
|||
UpdateProfileOther,
|
||||
} from "../entities/ProfileOther";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/other")
|
||||
@Tags("ProfileOther")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -87,7 +88,7 @@ export class ProfileOtherEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileOther();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -103,9 +104,10 @@ export class ProfileOtherEmployeeTempController extends Controller {
|
|||
const history = new ProfileOtherHistory();
|
||||
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;
|
||||
await this.otherHistoryRepository.save(history);
|
||||
await this.otherHistoryRepository.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { Profile } from "../entities/Profile";
|
||||
import { LessThan, MoreThan } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/salary")
|
||||
@Tags("ProfileSalary")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -105,7 +106,7 @@ export class ProfileSalaryController extends Controller {
|
|||
where: { profileId: body.profileId },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileSalary();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -122,9 +123,10 @@ export class ProfileSalaryController extends Controller {
|
|||
const history = new ProfileSalaryHistory();
|
||||
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;
|
||||
await this.salaryHistoryRepo.save(history);
|
||||
await this.salaryHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -138,7 +140,7 @@ export class ProfileSalaryController extends Controller {
|
|||
const record = await this.salaryRepo.findOneBy({ id: salaryId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -155,7 +157,11 @@ export class ProfileSalaryController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { LessThan, MoreThan } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/salary")
|
||||
@Tags("ProfileSalary")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -115,7 +116,7 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
where: { profileEmployeeId: body.profileEmployeeId },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileSalary();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -132,9 +133,10 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
const history = new ProfileSalaryHistory();
|
||||
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;
|
||||
await this.salaryHistoryRepo.save(history);
|
||||
await this.salaryHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -152,7 +154,7 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -169,7 +171,11 @@ export class ProfileSalaryEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { RequestWithUser } from "../middlewares/user";
|
|||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import { LessThan, MoreThan } from "typeorm";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/salary")
|
||||
@Tags("ProfileSalary")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -109,7 +110,7 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
where: { profileEmployeeId: body.profileEmployeeId },
|
||||
order: { order: "DESC" },
|
||||
});
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileSalary();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -126,9 +127,10 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
const history = new ProfileSalaryHistory();
|
||||
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;
|
||||
await this.salaryHistoryRepo.save(history);
|
||||
await this.salaryHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -143,7 +145,7 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
const record = await this.salaryRepo.findOneBy({ id: salaryId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileSalaryHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -160,7 +162,11 @@ export class ProfileSalaryEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { Profile } from "../entities/Profile";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile/training")
|
||||
@Tags("ProfileTraining")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -92,7 +93,7 @@ export class ProfileTrainingController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileTraining();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -108,9 +109,10 @@ export class ProfileTrainingController extends Controller {
|
|||
const history = new ProfileTrainingHistory();
|
||||
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;
|
||||
await this.trainingHistoryRepo.save(history);
|
||||
await this.trainingHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -124,7 +126,7 @@ export class ProfileTrainingController extends Controller {
|
|||
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_OFFICER", record.profileId);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -141,7 +143,11 @@ export class ProfileTrainingController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-employee/training")
|
||||
@Tags("ProfileEmployeeTraining")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -101,7 +102,7 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profile.id);
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileTraining();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -117,9 +118,10 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
const history = new ProfileTrainingHistory();
|
||||
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;
|
||||
await this.trainingHistoryRepo.save(history);
|
||||
await this.trainingHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -137,12 +139,12 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
"SYS_REGISTRY_EMP",
|
||||
record.profileEmployeeId,
|
||||
);
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
Object.assign(history, { ...record, id: undefined });
|
||||
|
||||
|
||||
history.profileTrainingId = trainingId;
|
||||
record.lastUpdateUserId = req.user.sub;
|
||||
record.lastUpdateFullName = req.user.name;
|
||||
|
|
@ -154,7 +156,11 @@ export class ProfileTrainingEmployeeController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import { ProfileTrainingHistory } from "../entities/ProfileTrainingHistory";
|
|||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { ProfileEmployee } from "../entities/ProfileEmployee";
|
||||
import permission from "../interfaces/permission";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
@Route("api/v1/org/profile-temp/training")
|
||||
@Tags("ProfileEmployeeTraining")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -94,7 +95,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
if (!profile) {
|
||||
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const data = new ProfileTraining();
|
||||
|
||||
const meta = {
|
||||
|
|
@ -110,9 +111,10 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
const history = new ProfileTrainingHistory();
|
||||
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;
|
||||
await this.trainingHistoryRepo.save(history);
|
||||
await this.trainingHistoryRepo.save(history, { data: req });
|
||||
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
|
@ -127,7 +129,7 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
const record = await this.trainingRepo.findOneBy({ id: trainingId });
|
||||
|
||||
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
|
||||
|
||||
const before = structuredClone(record);
|
||||
const history = new ProfileTrainingHistory();
|
||||
|
||||
Object.assign(record, body);
|
||||
|
|
@ -144,7 +146,11 @@ export class ProfileTrainingEmployeeTempController extends Controller {
|
|||
history.createdAt = 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();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { Province, CreateProvince, UpdateProvince } from "../entities/Province";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
|
||||
@Route("api/v1/org/metadata/province")
|
||||
@Tags("Province")
|
||||
|
|
@ -77,7 +79,7 @@ export class ProvinceController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateProvince,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _province = Object.assign(new Province(), requestBody);
|
||||
if (!_province) {
|
||||
|
|
@ -91,14 +93,15 @@ export class ProvinceController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_province.createdUserId = request.user.sub;
|
||||
_province.createdFullName = request.user.name;
|
||||
_province.lastUpdateUserId = request.user.sub;
|
||||
_province.lastUpdateFullName = request.user.name;
|
||||
_province.createdAt = 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();
|
||||
}
|
||||
|
||||
|
|
@ -114,7 +117,7 @@ export class ProvinceController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateProvince,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _province = await this.provinceRepository.findOne({ where: { id: id } });
|
||||
if (!_province) {
|
||||
|
|
@ -126,12 +129,13 @@ export class ProvinceController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(_province);
|
||||
_province.lastUpdateUserId = request.user.sub;
|
||||
_province.lastUpdateFullName = request.user.name;
|
||||
_province.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateRank, Rank } from "../entities/Rank";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
@Route("api/v1/org/metadata/rank")
|
||||
@Tags("Rank")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +42,7 @@ export class RankController extends Controller {
|
|||
async createRank(
|
||||
@Body()
|
||||
requestBody: CreateRank,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.rankRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -50,6 +52,7 @@ export class RankController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const rank = Object.assign(new Rank(), requestBody);
|
||||
rank.createdUserId = request.user.sub;
|
||||
rank.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +60,8 @@ export class RankController extends Controller {
|
|||
rank.lastUpdateFullName = request.user.name;
|
||||
rank.createdAt = 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();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +77,7 @@ export class RankController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateRank,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const rank = await this.rankRepository.findOne({ where: { id: id } });
|
||||
if (!rank) {
|
||||
|
|
@ -87,12 +91,13 @@ export class RankController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(rank);
|
||||
rank.lastUpdateUserId = request.user.sub;
|
||||
rank.lastUpdateFullName = request.user.name;
|
||||
rank.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -104,14 +109,14 @@ export class RankController extends Controller {
|
|||
* @param {string} id Id ยศ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteRank(@Path() id: string) {
|
||||
async deleteRank(@Path() id: string, @Request() req: RequestWithUser) {
|
||||
const delRank = await this.rankRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delRank) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลตำแหน่งนี้");
|
||||
}
|
||||
await this.rankRepository.delete({ id: id });
|
||||
await this.rankRepository.remove(delRank, { data: req });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,9 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateRelationship, Relationship } from "../entities/Relationship";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { request } from "axios";
|
||||
@Route("api/v1/org/metadata/relationship")
|
||||
@Tags("Relationship")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +43,7 @@ export class RelationshipController extends Controller {
|
|||
async createRelationship(
|
||||
@Body()
|
||||
requestBody: CreateRelationship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.relationshipRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -49,7 +52,7 @@ export class RelationshipController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const relationship = Object.assign(new Relationship(), requestBody);
|
||||
relationship.createdUserId = request.user.sub;
|
||||
relationship.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +60,8 @@ export class RelationshipController extends Controller {
|
|||
relationship.lastUpdateFullName = request.user.name;
|
||||
relationship.createdAt = 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();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +77,7 @@ export class RelationshipController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateRelationship,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const relationship = await this.relationshipRepository.findOne({ where: { id: id } });
|
||||
if (!relationship) {
|
||||
|
|
@ -88,11 +92,13 @@ export class RelationshipController extends Controller {
|
|||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(relationship);
|
||||
relationship.lastUpdateUserId = request.user.sub;
|
||||
relationship.lastUpdateFullName = request.user.name;
|
||||
relationship.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -104,14 +110,14 @@ export class RelationshipController extends Controller {
|
|||
* @param {string} id Id สถานภาพ
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteRelationship(@Path() id: string) {
|
||||
async deleteRelationship(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delRelationship = await this.relationshipRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delRelationship) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลสถานภาพนี้");
|
||||
}
|
||||
await this.relationshipRepository.delete({ id: id });
|
||||
await this.relationshipRepository.remove(delRelationship, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ import HttpStatusCode from "../interfaces/http-status";
|
|||
import HttpError from "../interfaces/http-error";
|
||||
import { CreateReligion, Religion } from "../entities/Religion";
|
||||
import { Not } from "typeorm";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
@Route("api/v1/org/metadata/religion")
|
||||
@Tags("Religion")
|
||||
@Security("bearerAuth")
|
||||
|
|
@ -40,7 +42,7 @@ export class ReligionController extends Controller {
|
|||
async createReligion(
|
||||
@Body()
|
||||
requestBody: CreateReligion,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const checkName = await this.religionRepository.findOne({
|
||||
where: { name: requestBody.name },
|
||||
|
|
@ -49,7 +51,7 @@ export class ReligionController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
const religion = Object.assign(new Religion(), requestBody);
|
||||
religion.createdUserId = request.user.sub;
|
||||
religion.createdFullName = request.user.name;
|
||||
|
|
@ -57,7 +59,8 @@ export class ReligionController extends Controller {
|
|||
religion.lastUpdateFullName = request.user.name;
|
||||
religion.createdAt = new Date();
|
||||
religion.lastUpdatedAt = new Date();
|
||||
await this.religionRepository.save(religion);
|
||||
await this.religionRepository.save(religion, { data: request });
|
||||
setLogDataDiff(request, { before, after: religion });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +76,7 @@ export class ReligionController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: CreateReligion,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const religion = await this.religionRepository.findOne({ where: { id: id } });
|
||||
if (!religion) {
|
||||
|
|
@ -87,12 +90,13 @@ export class ReligionController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = structuredClone(religion);
|
||||
religion.lastUpdateUserId = request.user.sub;
|
||||
religion.lastUpdateFullName = request.user.name;
|
||||
religion.lastUpdatedAt = new Date();
|
||||
this.religionRepository.merge(religion, requestBody);
|
||||
await this.religionRepository.save(religion);
|
||||
await this.religionRepository.save(religion, { data: request });
|
||||
setLogDataDiff(request, { before, after: religion });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
@ -104,14 +108,14 @@ export class ReligionController extends Controller {
|
|||
* @param {string} id Id ศาสนา
|
||||
*/
|
||||
@Delete("{id}")
|
||||
async deleteReligion(@Path() id: string) {
|
||||
async deleteReligion(@Path() id: string, @Request() request: RequestWithUser) {
|
||||
const delReligion = await this.religionRepository.findOne({
|
||||
where: { id },
|
||||
});
|
||||
if (!delReligion) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ไม่พบข้อมูลศาสนานี้");
|
||||
}
|
||||
await this.religionRepository.delete({ id: id });
|
||||
await this.religionRepository.remove(delReligion, { data: request });
|
||||
return new HttpSuccess();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ import HttpError from "../interfaces/http-error";
|
|||
import { SubDistrict, CreateSubDistrict, UpdateSubDistrict } from "../entities/SubDistrict";
|
||||
import { District } from "../entities/District";
|
||||
import { Not } from "typeorm";
|
||||
import { RequestWithUser } from "../middlewares/user";
|
||||
import { setLogDataDiff } from "../interfaces/utils";
|
||||
|
||||
@Route("api/v1/org/metadata/subDistrict")
|
||||
@Tags("SubDistrict")
|
||||
|
|
@ -78,7 +80,7 @@ export class SubDistrictController extends Controller {
|
|||
async Post(
|
||||
@Body()
|
||||
requestBody: CreateSubDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _subDistrict = Object.assign(new SubDistrict(), requestBody);
|
||||
if (!_subDistrict) {
|
||||
|
|
@ -102,14 +104,15 @@ export class SubDistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_subDistrict.createdUserId = request.user.sub;
|
||||
_subDistrict.createdFullName = request.user.name;
|
||||
_subDistrict.lastUpdateUserId = request.user.sub;
|
||||
_subDistrict.lastUpdateFullName = request.user.name;
|
||||
_subDistrict.createdAt = 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();
|
||||
}
|
||||
|
||||
|
|
@ -125,7 +128,7 @@ export class SubDistrictController extends Controller {
|
|||
@Path() id: string,
|
||||
@Body()
|
||||
requestBody: UpdateSubDistrict,
|
||||
@Request() request: { user: Record<string, any> },
|
||||
@Request() request: RequestWithUser,
|
||||
) {
|
||||
const _subDistrict = await this.subDistrictRepository.findOne({ where: { id: id } });
|
||||
if (!_subDistrict) {
|
||||
|
|
@ -149,12 +152,13 @@ export class SubDistrictController extends Controller {
|
|||
if (checkName) {
|
||||
throw new HttpError(HttpStatusCode.NOT_FOUND, "ชื่อนี้มีอยู่ในระบบแล้ว");
|
||||
}
|
||||
|
||||
const before = null;
|
||||
_subDistrict.lastUpdateUserId = request.user.sub;
|
||||
_subDistrict.lastUpdateFullName = request.user.name;
|
||||
_subDistrict.lastUpdatedAt = new Date();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue