From 828dd2a37d831393f04fd7fb94979742c6661fb1 Mon Sep 17 00:00:00 2001 From: JoolsoftAdmin Date: Fri, 9 Aug 2024 17:31:33 +0700 Subject: [PATCH] =?UTF-8?q?=E0=B9=81=E0=B8=81=E0=B9=89=E0=B8=AD=E0=B8=AD?= =?UTF-8?q?=E0=B8=81=E0=B8=84=E0=B8=B3=E0=B8=AA=E0=B8=B1=E0=B9=88=E0=B8=87?= =?UTF-8?q?=E0=B8=A7=E0=B8=B4=E0=B8=99=E0=B8=B1=E0=B8=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/controllers/ProfileController.ts | 115 +++++++++++++++++---------- 1 file changed, 71 insertions(+), 44 deletions(-) diff --git a/src/controllers/ProfileController.ts b/src/controllers/ProfileController.ts index 6f05547e..df343da9 100644 --- a/src/controllers/ProfileController.ts +++ b/src/controllers/ProfileController.ts @@ -1414,10 +1414,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([ - this.profileRepo.save(profile), - this.salaryRepository.save(profileSalary), - ]); + await Promise.all([this.salaryRepository.save(profileSalary)]); } return new HttpSuccess(); } @@ -1451,14 +1448,20 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const _profile = await this.profileRepo.findOne({ + where: { id: body.profileId }, + }); + if (!_profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } let dateLeave_: any = body.date; - await removeProfileInOrganize(profile.id,"OFFICER"); - profile.isLeave = true; - profile.leaveReason = + await removeProfileInOrganize(profile.id, "OFFICER"); + _profile.isLeave = true; + _profile.leaveReason = "คำสั่งให้ข้าราชการออกจากราชการเพราะผลการทดลองปฏิบัติหน้าที่ราชการต่ำกว่ามาตรฐานที่กำหนด"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + _profile.dateLeave = dateLeave_; + _profile.lastUpdateUserId = req.user.sub; + _profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1490,7 +1493,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -1524,13 +1527,19 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const _profile = await this.profileRepo.findOne({ + where: { id: body.profileId }, + }); + if (!_profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } let dateLeave_: any = body.date; - await removeProfileInOrganize(profile.id,"OFFICER"); - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + await removeProfileInOrganize(profile.id, "OFFICER"); + _profile.isLeave = true; + _profile.leaveReason = "ได้รับโทษทางวินัย ปลดออกจากราชการ"; + _profile.dateLeave = dateLeave_; + _profile.lastUpdateUserId = req.user.sub; + _profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1562,7 +1571,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -1596,13 +1605,19 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const _profile = await this.profileRepo.findOne({ + where: { id: body.profileId }, + }); + if (!_profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } let dateLeave_: any = body.date; - await removeProfileInOrganize(profile.id,"OFFICER"); - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + await removeProfileInOrganize(profile.id, "OFFICER"); + _profile.isLeave = true; + _profile.leaveReason = "ได้รับโทษทางวินัย ไล่ออกจากราชการ"; + _profile.dateLeave = dateLeave_; + _profile.lastUpdateUserId = req.user.sub; + _profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1645,7 +1660,7 @@ export class ProfileController extends Controller { // lastUpdateFullName: req.user.name, // }); await Promise.all([ - this.profileRepo.save(profile), + this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary), // this.profileDisciplineRepo.save(profileDiscipline) ]); @@ -1682,13 +1697,19 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const _profile = await this.profileRepo.findOne({ + where: { id: body.profileId }, + }); + if (!_profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } let dateLeave_: any = body.date; - await removeProfileInOrganize(profile.id,"OFFICER"); - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + await removeProfileInOrganize(profile.id, "OFFICER"); + _profile.isLeave = true; + _profile.leaveReason = "ได้รับโทษทางวินัย พักจากราชการ"; + _profile.dateLeave = dateLeave_; + _profile.lastUpdateUserId = req.user.sub; + _profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1720,7 +1741,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -1754,13 +1775,19 @@ export class ProfileController extends Controller { if (!profile) { throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); } + const _profile = await this.profileRepo.findOne({ + where: { id: body.profileId }, + }); + if (!_profile) { + throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์"); + } let dateLeave_: any = body.date; await removeProfileInOrganize(profile.id, "OFFICER"); - profile.isLeave = true; - profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; - profile.dateLeave = dateLeave_; - profile.lastUpdateUserId = req.user.sub; - profile.lastUpdateFullName = req.user.name; + _profile.isLeave = true; + _profile.leaveReason = "ได้รับโทษทางวินัย ให้ออกจากราชการไว้ก่อน"; + _profile.dateLeave = dateLeave_; + _profile.lastUpdateUserId = req.user.sub; + _profile.lastUpdateFullName = req.user.name; const profileSalary: ProfileSalary = Object.assign(new ProfileSalary(), { profileId: body.profileId, date: body.date, @@ -1792,7 +1819,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.profileRepo.save(_profile), this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -1863,7 +1890,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -1934,7 +1961,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -2005,7 +2032,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -2076,7 +2103,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -2147,7 +2174,7 @@ export class ProfileController extends Controller { lastUpdateUserId: req.user.sub, lastUpdateFullName: req.user.name, }); - await Promise.all([this.profileRepo.save(profile), this.salaryRepository.save(profileSalary)]); + await Promise.all([this.salaryRepository.save(profileSalary)]); return new HttpSuccess(); } @@ -2250,7 +2277,7 @@ export class ProfileController extends Controller { @Path() id: string, @Body() body: UpdateProfile, ) { - await new permission().PermissionUpdate(request,"SYS_REGISTRY"); + await new permission().PermissionUpdate(request, "SYS_REGISTRY"); const exists = !!body.citizenId && (await this.profileRepo.findOne({