แก้ create เป็น update เมนูทะเบียนประวัติ

This commit is contained in:
AdisakKanthawilang 2024-08-27 12:11:31 +07:00
parent fde5f8d90a
commit f281ea0bc2
61 changed files with 193 additions and 147 deletions

View file

@ -258,7 +258,7 @@ export class ProfileEmployeeController extends Controller {
relations: ["currentSubDistrict", "currentDistrict", "currentProvince"],
where: { id: id },
});
if(profiles){
if (profiles) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profiles.id);
}
const profileOc = await this.profileRepo.findOne({
@ -580,7 +580,7 @@ export class ProfileEmployeeController extends Controller {
*
*/
@Post()
async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { //ตส
async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { //ไม่แน่ใจEMP
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR,
@ -633,7 +633,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string,
@Body() body: UpdateProfileEmployee,
) {
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id)
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id);
const exists =
!!body.citizenId &&
(await this.profileRepo.findOne({
@ -1058,7 +1058,7 @@ export class ProfileEmployeeController extends Controller {
*/
@Get("{id}")
async detailProfile(@Path() id: string, @Request() req: RequestWithUser) {
// await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id);//ตส
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id); //ไม่แน่ใจEMP
const profile = await this.profileRepo.findOne({
relations: {
posLevel: true,
@ -2077,7 +2077,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string,
@Body() body: UpdatePositionTempProfileEmployee,
) {
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id)
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id);
if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null;
@ -2211,7 +2211,7 @@ export class ProfileEmployeeController extends Controller {
@Body()
requestBody: { citizenId: string },
) {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", id)
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", id);
const profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId },
});
@ -2657,8 +2657,9 @@ export class ProfileEmployeeController extends Controller {
* @summary
*
*/
@Get("profileid/retire/{year}") //ตส
async getProfileByRetireYear(@Path() year: number) {
@Get("profileid/retire/{year}")
async getProfileByRetireYear(@Path() year: number, @Request() req: RequestWithUser) {
// await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", id);//ไม่แน่ใจEMP
const profiles = await this.profileRepo
.createQueryBuilder("profileEmployee")
.leftJoinAndSelect("profileEmployee.posLevel", "posLevel")
@ -2861,7 +2862,7 @@ export class ProfileEmployeeController extends Controller {
where: { id: id },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserCreate(request, "SYS_REGISTRY_EMP", profile.id)
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", profile.id);
profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason;
@ -2892,8 +2893,7 @@ export class ProfileEmployeeController extends Controller {
@Path() profileEmployeeId: string,
@Body() body: UpdateInformationProfileEmployee,
) {
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", profileEmployeeId)
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", profileEmployeeId);
const profileEmp = await this.profileRepo.findOneBy({ id: profileEmployeeId });
if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
@ -2922,7 +2922,7 @@ export class ProfileEmployeeController extends Controller {
*/
@Get("information/{profileEmployeeId}")
async getInformationById(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId)
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profileInformation = await this.profileRepo.findOne({
where: { id: profileEmployeeId },
});
@ -2953,7 +2953,7 @@ export class ProfileEmployeeController extends Controller {
*/
@Get("information/history/{profileEmployeeId}")
async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId)
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profileInformation = await this.profileRepo.find({
relations: {
information_histories: true,
@ -2994,8 +2994,11 @@ export class ProfileEmployeeController extends Controller {
* @param {string} profileEmployeeId profileEmployeeId
*/
@Get("employment/{profileEmployeeId}")
async ProfileEmployeeEmployment(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId)
async ProfileEmployeeEmployment(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const employment = await this.employmentRepository.find({
where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" },
@ -3021,7 +3024,11 @@ export class ProfileEmployeeController extends Controller {
where: { id: id },
});
if (employment) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
await new permission().PermissionOrgUserGet(
req,
"SYS_REGISTRY_EMP",
employment.profileEmployeeId,
);
}
return new HttpSuccess(employment);
}
@ -3039,7 +3046,11 @@ export class ProfileEmployeeController extends Controller {
where: { id: id },
});
if (employment) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
await new permission().PermissionOrgUserList(
req,
"SYS_REGISTRY_EMP",
employment.profileEmployeeId,
);
}
const employmentHistory = await this.employmentHistoryRepository.find({
where: { profileEmployeeEmploymentId: id },
@ -3065,7 +3076,7 @@ export class ProfileEmployeeController extends Controller {
where: { id: profileEmployeeId },
});
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserList(request, "SYS_REGISTRY_EMP", profile.id)
await new permission().PermissionOrgUserList(request, "SYS_REGISTRY_EMP", profile.id);
const employment = new ProfileEmployeeEmployment();
// const history = new ProfileEmployeeEmploymentHistory();
@ -3101,7 +3112,11 @@ export class ProfileEmployeeController extends Controller {
where: { id: id },
});
if (employment) {
await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
await new permission().PermissionOrgUserDelete(
request,
"SYS_REGISTRY_EMP",
employment.profileEmployeeId,
);
}
await this.employmentHistoryRepository.delete({
profileEmployeeEmploymentId: id,
@ -3127,10 +3142,13 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string,
@Body() body: UpdateEmploymentProfileEmployee,
) {
const employment = await this.employmentRepository.findOneBy({ id });
if (!employment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
await new permission().PermissionOrgUserUpdate(
request,
"SYS_REGISTRY_EMP",
employment.profileEmployeeId,
);
const history = new ProfileEmployeeEmploymentHistory();
Object.assign(history, { ...employment, id: undefined });
@ -3412,10 +3430,7 @@ export class ProfileEmployeeController extends Controller {
*
*/
@Get("profileid/position/{id}")
async getProfileByProfileid(
@Request() request: RequestWithUser,
@Path() id: string,
) {
async getProfileByProfileid(@Request() request: RequestWithUser, @Path() id: string) {
const profile = await this.profileRepo.findOne({
where: { id: id },
relations: ["posLevel", "posType", "current_holders", "current_holders.orgRoot"],