role เมนู ลูกจ้างประจำ กทม.

This commit is contained in:
AdisakKanthawilang 2024-08-23 16:28:31 +07:00
parent 359d22beec
commit 7237c68cb8
23 changed files with 327 additions and 155 deletions

View file

@ -73,7 +73,8 @@ export class ProfileAbilityEmployeeController extends Controller {
}, },
], ],
}) })
public async detailProfileAbility(@Path() profileEmployeeId: string) { public async detailProfileAbility(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAbilityId = await this.profileAbilityRepo.findBy({ profileEmployeeId }); const getProfileAbilityId = await this.profileAbilityRepo.findBy({ profileEmployeeId });
if (!getProfileAbilityId) { if (!getProfileAbilityId) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -120,7 +121,15 @@ export class ProfileAbilityEmployeeController extends Controller {
}, },
], ],
}) })
public async getProfileAbilityHistory(@Path() abilityId: string) { public async getProfileAbilityHistory(@Path() abilityId: string, @Request() req: RequestWithUser) {
const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (_record) {
await new permission().PermissionOrgUserList(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
const record = await this.profileAbilityHistoryRepo.findBy({ const record = await this.profileAbilityHistoryRepo.findBy({
profileAbilityId: abilityId, profileAbilityId: abilityId,
}); });
@ -135,7 +144,6 @@ export class ProfileAbilityEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileAbilityEmployee, @Body() body: CreateProfileAbilityEmployee,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -144,6 +152,7 @@ export class ProfileAbilityEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileAbility(); const data = new ProfileAbility();
const meta = { const meta = {
@ -170,9 +179,9 @@ export class ProfileAbilityEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() abilityId: string, @Path() abilityId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.profileAbilityRepo.findOneBy({ id: abilityId }); const record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileAbilityHistory(); const history = new ProfileAbilityHistory();
@ -197,7 +206,14 @@ export class ProfileAbilityEmployeeController extends Controller {
@Delete("{abilityId}") @Delete("{abilityId}")
public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) { public async deleteProfileAbility(@Path() abilityId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.profileAbilityRepo.findOneBy({ id: abilityId });
if (_record) {
await new permission().PermissionOrgUserDelete(
req,
"SYS_REGISTRY_EMP",
_record.profileEmployeeId,
);
}
await this.profileAbilityHistoryRepo.delete({ await this.profileAbilityHistoryRepo.delete({
profileAbilityId: abilityId, profileAbilityId: abilityId,
}); });

View file

@ -69,7 +69,8 @@ export class ProfileAddressEmployeeController extends Controller {
* *
*/ */
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
public async detailProfileAddress(@Path() profileEmployeeId: string) { public async detailProfileAddress(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAddress = await this.profileEmployeeRepo.findOne({ const getProfileAddress = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
select: [ select: [
@ -140,7 +141,8 @@ export class ProfileAddressEmployeeController extends Controller {
* *
*/ */
@Get("history/{profileId}") @Get("history/{profileId}")
public async getProfileAddressHistory(@Path() profileId: string) { public async getProfileAddressHistory(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.profileAddressHistoryRepo.find({ const record = await this.profileAddressHistoryRepo.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
relations: { relations: {
@ -183,9 +185,9 @@ export class ProfileAddressEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() profileId: string, @Path() profileId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.profileEmployeeRepo.findOneBy({ id: profileId }); const record = await this.profileEmployeeRepo.findOneBy({ id: profileId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.id);
const history = new ProfileAddressHistory(); const history = new ProfileAddressHistory();

View file

@ -78,7 +78,8 @@ export class ProfileAssessmentsEmployeeController extends Controller {
}, },
], ],
}) })
public async detailProfileAssessments(@Path() profileEmployeeId: string) { public async detailProfileAssessments(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileAssessments = await this.profileAssessmentsRepository.findBy({ const getProfileAssessments = await this.profileAssessmentsRepository.findBy({
profileEmployeeId, profileEmployeeId,
}); });
@ -131,11 +132,14 @@ export class ProfileAssessmentsEmployeeController extends Controller {
}, },
], ],
}) })
public async getProfileAssessmentsHistory(@Path() assessmentId: string) { public async getProfileAssessmentsHistory(@Path() assessmentId: string, @Request() req: RequestWithUser) {
const _record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileId);
}
const record = await this.profileAssessmentsHistoryRepository.findBy({ const record = await this.profileAssessmentsHistoryRepository.findBy({
profileAssessmentId: assessmentId, profileAssessmentId: assessmentId,
}); });
if (!record) { if (!record) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
} }
@ -148,7 +152,6 @@ export class ProfileAssessmentsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAssessment, @Body() body: CreateProfileEmployeeAssessment,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -157,6 +160,7 @@ export class ProfileAssessmentsEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileAssessment(); const data = new ProfileAssessment();
const meta = { const meta = {
@ -182,9 +186,9 @@ export class ProfileAssessmentsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() assessmentId: string, @Path() assessmentId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId }); const record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileAssessmentHistory(); const history = new ProfileAssessmentHistory();
@ -212,7 +216,10 @@ export class ProfileAssessmentsEmployeeController extends Controller {
@Path() assessmentId: string, @Path() assessmentId: string,
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
) { ) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.profileAssessmentsRepository.findOneBy({ id: assessmentId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.profileAssessmentsHistoryRepository.delete({ await this.profileAssessmentsHistoryRepository.delete({
profileAssessmentId: assessmentId, profileAssessmentId: assessmentId,
}); });

View file

@ -15,7 +15,11 @@ export class ProfileAvatarEmployeeController extends Controller {
private avatarRepository = AppDataSource.getRepository(ProfileAvatar); private avatarRepository = AppDataSource.getRepository(ProfileAvatar);
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
public async getAvatarEmployee(@Path() profileEmployeeId: string) { public async getAvatarEmployee(
@Path() profileEmployeeId: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.avatarRepository.find({ const lists = await this.avatarRepository.find({
where: { profileEmployeeId }, where: { profileEmployeeId },
}); });
@ -23,7 +27,12 @@ export class ProfileAvatarEmployeeController extends Controller {
} }
@Get("select/{profileEmployeeId}/{id}") @Get("select/{profileEmployeeId}/{id}")
public async selectAvatarEmployee(@Path() profileEmployeeId: string, @Path() id: string) { public async selectAvatarEmployee(
@Path() profileEmployeeId: string,
@Path() id: string,
@Request() req: RequestWithUser,
) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const result = await this.avatarRepository.findOneBy({ id: id }); const result = await this.avatarRepository.findOneBy({ id: id });
if (!result) { if (!result) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -54,14 +63,13 @@ export class ProfileAvatarEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeAvatar, @Body() body: CreateProfileEmployeeAvatar,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
const profile = await this.profileRepository.findOne({ const profile = await this.profileRepository.findOne({
where: { id: body.profileEmployeeId }, where: { id: body.profileEmployeeId },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileAvatar(); const data = new ProfileAvatar();
@ -106,7 +114,10 @@ export class ProfileAvatarEmployeeController extends Controller {
@Delete("{avatarId}") @Delete("{avatarId}")
public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) { public async deleteAvatarEmployee(@Path() avatarId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.avatarRepository.findOneBy({ id: avatarId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const result = await this.avatarRepository.delete({ id: avatarId }); const result = await this.avatarRepository.delete({ id: avatarId });
if (result.affected == undefined || result.affected <= 0) { if (result.affected == undefined || result.affected <= 0) {

View file

@ -67,7 +67,8 @@ export class ProfileCertificateEmployeeController extends Controller {
}, },
], ],
}) })
public async getCertificate(@Path() profileEmployeeId: string) { public async getCertificate(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.certificateRepo.findBy({ profileEmployeeId }); const record = await this.certificateRepo.findBy({ profileEmployeeId });
return new HttpSuccess(record); return new HttpSuccess(record);
} }
@ -109,7 +110,11 @@ export class ProfileCertificateEmployeeController extends Controller {
}, },
], ],
}) })
public async certificateHistory(@Path() certificateId: string) { public async certificateHistory(@Path() certificateId: string, @Request() req: RequestWithUser) {
const _record = await this.certificateRepo.findOneBy({ id: certificateId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.certificateHistoryRepo.findBy({ const record = await this.certificateHistoryRepo.findBy({
profileCertificateId: certificateId, profileCertificateId: certificateId,
}); });
@ -121,16 +126,15 @@ export class ProfileCertificateEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeCertificate, @Body() body: CreateProfileEmployeeCertificate,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileCertificate(); const data = new ProfileCertificate();
@ -158,10 +162,9 @@ export class ProfileCertificateEmployeeController extends Controller {
@Body() body: UpdateProfileCertificate, @Body() body: UpdateProfileCertificate,
@Path() certificateId: string, @Path() certificateId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.certificateRepo.findOneBy({ id: certificateId }); const record = await this.certificateRepo.findOneBy({ id: certificateId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileCertificateHistory(); const history = new ProfileCertificateHistory();
@ -186,7 +189,10 @@ export class ProfileCertificateEmployeeController extends Controller {
@Delete("{certificateId}") @Delete("{certificateId}")
public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) { public async deleteCertificate(@Path() certificateId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.certificateRepo.findOneBy({ id: certificateId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.certificateHistoryRepo.delete({ await this.certificateHistoryRepo.delete({
profileCertificateId: certificateId, profileCertificateId: certificateId,
}); });

View file

@ -64,7 +64,8 @@ export class ProfileChangeNameEmployeeController extends Controller {
}, },
], ],
}) })
public async getChangeName(@Path() profileEmployeeId: string) { public async getChangeName(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.changeNameRepository.find({ const lists = await this.changeNameRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId },
select: ["id", "prefix", "firstName", "lastName", "status"], select: ["id", "prefix", "firstName", "lastName", "status"],
@ -98,7 +99,12 @@ export class ProfileChangeNameEmployeeController extends Controller {
}, },
], ],
}) })
public async changeNameHistory(@Path() changeNameId: string) { public async changeNameHistory(@Path() changeNameId: string, @Request() req: RequestWithUser) {
const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId,
);
}
const record = await this.changeNameHistoryRepository.find({ const record = await this.changeNameHistoryRepository.find({
where: { profileChangeNameId: changeNameId }, where: { profileChangeNameId: changeNameId },
select: [ select: [
@ -120,16 +126,15 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileChangeNameEmployee, @Body() body: CreateProfileChangeNameEmployee,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileChangeName(); const data = new ProfileChangeName();
@ -169,10 +174,9 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Body() body: UpdateProfileChangeName, @Body() body: UpdateProfileChangeName,
@Path() changeNameId: string, @Path() changeNameId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.changeNameRepository.findOneBy({ id: changeNameId }); const record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileChangeNameHistory(); const history = new ProfileChangeNameHistory();
@ -216,7 +220,10 @@ export class ProfileChangeNameEmployeeController extends Controller {
@Delete("{changeNameId}") @Delete("{changeNameId}")
public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) { public async deleteTraning(@Path() changeNameId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.changeNameRepository.findOneBy({ id: changeNameId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.changeNameHistoryRepository.delete({ await this.changeNameHistoryRepository.delete({
profileChangeNameId: changeNameId, profileChangeNameId: changeNameId,
}); });

View file

@ -49,7 +49,8 @@ export class ProfileChildrenEmployeeController extends Controller {
} }
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
public async getChildren(@Path() profileEmployeeId: string) { public async getChildren(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const lists = await this.childrenRepository.find({ const lists = await this.childrenRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId },
}); });
@ -57,7 +58,12 @@ export class ProfileChildrenEmployeeController extends Controller {
} }
@Get("history/{childrenId}") @Get("history/{childrenId}")
public async childrenHistory(@Path() childrenId: string) { public async childrenHistory(@Path() childrenId: string, @Request() req: RequestWithUser) {
const _record = await this.childrenRepository.findOneBy({ id: childrenId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId,
);
}
const record = await this.childrenHistoryRepository.find({ const record = await this.childrenHistoryRepository.find({
where: { profileChildrenId: childrenId }, where: { profileChildrenId: childrenId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -70,12 +76,11 @@ export class ProfileChildrenEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileChildrenEmployee, @Body() body: CreateProfileChildrenEmployee,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileChildren(); const data = new ProfileChildren();
@ -105,9 +110,9 @@ export class ProfileChildrenEmployeeController extends Controller {
@Body() body: UpdateProfileChildren, @Body() body: UpdateProfileChildren,
@Path() childrenId: string, @Path() childrenId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.childrenRepository.findOneBy({ id: childrenId }); const record = await this.childrenRepository.findOneBy({ id: childrenId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileChildrenHistory(); const history = new ProfileChildrenHistory();
Object.assign(record, body); Object.assign(record, body);
@ -132,7 +137,10 @@ export class ProfileChildrenEmployeeController extends Controller {
@Delete("{childrenId}") @Delete("{childrenId}")
public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) { public async deleteTraning(@Path() childrenId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.childrenRepository.findOneBy({ id: childrenId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.childrenHistoryRepository.delete({ await this.childrenHistoryRepository.delete({
profileChildrenId: childrenId, profileChildrenId: childrenId,
}); });

View file

@ -4849,7 +4849,7 @@ export class ProfileController extends Controller {
* @summary * @summary
* *
*/ */
@Get("profileid/retire/{year}") @Get("profileid/retire/{year}") //ตส
async getProfileByRetireYear(@Path() year: number) { async getProfileByRetireYear(@Path() year: number) {
const profiles = await this.profileRepo const profiles = await this.profileRepo
.createQueryBuilder("profile") .createQueryBuilder("profile")

View file

@ -72,7 +72,8 @@ export class ProfileDisciplineEmployeeController extends Controller {
}, },
], ],
}) })
public async getDiscipline(@Path() profileId: string) { public async getDiscipline(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.disciplineRepository.find({ const lists = await this.disciplineRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
select: [ select: [
@ -91,7 +92,11 @@ export class ProfileDisciplineEmployeeController extends Controller {
} }
@Get("history/{disciplineId}") @Get("history/{disciplineId}")
public async disciplineHistory(@Path() disciplineId: string) { public async disciplineHistory(@Path() disciplineId: string, @Request() req: RequestWithUser) {
const _record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.disciplineHistoryRepository.find({ const record = await this.disciplineHistoryRepository.find({
where: { profileDisciplineId: disciplineId }, where: { profileDisciplineId: disciplineId },
select: [ select: [
@ -115,16 +120,15 @@ export class ProfileDisciplineEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeDiscipline, @Body() body: CreateProfileEmployeeDiscipline,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileDiscipline(); const data = new ProfileDiscipline();
@ -152,10 +156,9 @@ export class ProfileDisciplineEmployeeController extends Controller {
@Body() body: UpdateProfileDiscipline, @Body() body: UpdateProfileDiscipline,
@Path() disciplineId: string, @Path() disciplineId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.disciplineRepository.findOneBy({ id: disciplineId }); const record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileDisciplineHistory(); const history = new ProfileDisciplineHistory();
@ -180,7 +183,10 @@ export class ProfileDisciplineEmployeeController extends Controller {
@Delete("{disciplineId}") @Delete("{disciplineId}")
public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) { public async deleteDiscipline(@Path() disciplineId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.disciplineRepository.findOneBy({ id: disciplineId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.disciplineHistoryRepository.delete({ await this.disciplineHistoryRepository.delete({
profileDisciplineId: disciplineId, profileDisciplineId: disciplineId,
}); });

View file

@ -51,7 +51,8 @@ export class ProfileDutyEmployeeController extends Controller {
} }
@Get("{profileId}") @Get("{profileId}")
public async getDuty(@Path() profileId: string) { public async getDuty(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.dutyRepository.find({ const lists = await this.dutyRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
select: [ select: [
@ -68,7 +69,11 @@ export class ProfileDutyEmployeeController extends Controller {
} }
@Get("history/{dutyId}") @Get("history/{dutyId}")
public async dutyHistory(@Path() dutyId: string) { public async dutyHistory(@Path() dutyId: string, @Request() req: RequestWithUser) {
const _record = await this.dutyRepository.findOneBy({ id: dutyId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.dutyHistoryRepository.find({ const record = await this.dutyHistoryRepository.find({
where: { profileDutyId: dutyId }, where: { profileDutyId: dutyId },
select: [ select: [
@ -89,16 +94,15 @@ export class ProfileDutyEmployeeController extends Controller {
@Post() @Post()
public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) { public async newDuty(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeDuty) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileDuty(); const data = new ProfileDuty();
@ -126,10 +130,9 @@ export class ProfileDutyEmployeeController extends Controller {
@Body() body: UpdateProfileDuty, @Body() body: UpdateProfileDuty,
@Path() dutyId: string, @Path() dutyId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.dutyRepository.findOneBy({ id: dutyId }); const record = await this.dutyRepository.findOneBy({ id: dutyId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileDutyHistory(); const history = new ProfileDutyHistory();
@ -151,7 +154,10 @@ export class ProfileDutyEmployeeController extends Controller {
@Delete("{dutyId}") @Delete("{dutyId}")
public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) { public async deleteDuty(@Path() dutyId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.dutyRepository.findOneBy({ id: dutyId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.dutyHistoryRepository.delete({ await this.dutyHistoryRepository.delete({
profileDutyId: dutyId, profileDutyId: dutyId,
}); });

View file

@ -91,7 +91,8 @@ export class ProfileEducationsEmployeeController extends Controller {
}, },
], ],
}) })
public async detailProfileEducation(@Path() profileEmployeeId: string) { public async detailProfileEducation(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const getProfileEducation = await this.profileEducationRepo.find({ const getProfileEducation = await this.profileEducationRepo.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId },
}); });
@ -168,7 +169,12 @@ export class ProfileEducationsEmployeeController extends Controller {
}, },
], ],
}) })
public async getProfileEducationHistory(@Path() educationId: string) { public async getProfileEducationHistory(@Path() educationId: string, @Request() req: RequestWithUser) {
const _record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.profileEducationHistoryRepo.findBy({ const record = await this.profileEducationHistoryRepo.findBy({
profileEducationId: educationId, profileEducationId: educationId,
}); });
@ -183,7 +189,6 @@ export class ProfileEducationsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEducationEmployee, @Body() body: CreateProfileEducationEmployee,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
@ -192,6 +197,7 @@ export class ProfileEducationsEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileEducation(); const data = new ProfileEducation();
const meta = { const meta = {
@ -218,9 +224,9 @@ export class ProfileEducationsEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Path() educationId: string, @Path() educationId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.profileEducationRepo.findOneBy({ id: educationId }); const record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId);
const history = new ProfileEducationHistory(); const history = new ProfileEducationHistory();
@ -248,7 +254,11 @@ export class ProfileEducationsEmployeeController extends Controller {
@Path() educationId: string, @Path() educationId: string,
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
) { ) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.profileEducationRepo.findOneBy({ id: educationId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.profileEducationHistoryRepo.delete({ await this.profileEducationHistoryRepo.delete({
profileEducationId: educationId, profileEducationId: educationId,
}); });

View file

@ -117,7 +117,7 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("kp7-short/{id}") @Get("kp7-short/{id}")
async kp7ShortById(@Path() id: string) { async kp7ShortById(@Path() id: string, @Request() req: RequestWithUser) {
const orgRevision = await this.orgRevisionRepo.findOne({ const orgRevision = await this.orgRevisionRepo.findOne({
where: { orgRevisionIsCurrent: true }, where: { orgRevisionIsCurrent: true },
}); });
@ -136,6 +136,7 @@ export class ProfileEmployeeController extends Controller {
where: { id: id }, where: { id: id },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profile.id);
const province = await this.provinceRepository.findOneBy({ const province = await this.provinceRepository.findOneBy({
id: profile.registrationProvinceId, id: profile.registrationProvinceId,
@ -240,7 +241,7 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("kk1/{id}") @Get("kk1/{id}")
public async getKk1Employee(@Path() id: string) { public async getKk1Employee(@Path() id: string, @Request() req: RequestWithUser) {
const profiles = await this.profileRepo.findOne({ const profiles = await this.profileRepo.findOne({
// select: [ // select: [
// "citizenId", // "citizenId",
@ -257,6 +258,9 @@ export class ProfileEmployeeController extends Controller {
relations: ["currentSubDistrict", "currentDistrict", "currentProvince"], relations: ["currentSubDistrict", "currentDistrict", "currentProvince"],
where: { id: id }, where: { id: id },
}); });
if(profiles){
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profiles.id);
}
const profileOc = await this.profileRepo.findOne({ const profileOc = await this.profileRepo.findOne({
relations: [ relations: [
"current_holders", "current_holders",
@ -576,8 +580,7 @@ export class ProfileEmployeeController extends Controller {
* *
*/ */
@Post() @Post()
async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { async createProfile(@Body() body: CreateProfileEmployee, @Request() request: RequestWithUser) { //ตส
await new permission().PermissionCreate(request, "SYS_REGISTRY_TEMP");
if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) { if (await this.profileRepo.findOneBy({ citizenId: body.citizenId })) {
throw new HttpError( throw new HttpError(
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
@ -630,7 +633,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateProfileEmployee, @Body() body: UpdateProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request, "SYS_REGISTRY_EMP"); await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id)
const exists = const exists =
!!body.citizenId && !!body.citizenId &&
(await this.profileRepo.findOne({ (await this.profileRepo.findOne({
@ -694,11 +697,11 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Delete("{id}") @Delete("{id}")
async deleteProfile(@Path() id: string, @Request() request: RequestWithUser) { async deleteProfile(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_REGISTRY_EMP");
const result = await this.profileRepo.findOne({ where: { id: id } }); const result = await this.profileRepo.findOne({ where: { id: id } });
if (!result) { if (!result) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
} }
await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", result.id);
await this.informationHistoryRepository.delete({ profileEmployeeId: id }); await this.informationHistoryRepository.delete({ profileEmployeeId: id });
await this.profileRepo.remove(result); await this.profileRepo.remove(result);
return new HttpSuccess(); return new HttpSuccess();
@ -1054,7 +1057,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("{id}") @Get("{id}")
async detailProfile(@Path() id: string) { async detailProfile(@Path() id: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
relations: { relations: {
posLevel: true, posLevel: true,
@ -1307,7 +1311,8 @@ export class ProfileEmployeeController extends Controller {
} }
@Get("history/{id}") @Get("history/{id}")
async getProfileHistory(@Path() id: string) { async getProfileHistory(@Path() id: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", id);
const profile = await this.profileHistoryRepo.find({ const profile = await this.profileHistoryRepo.find({
relations: { relations: {
posLevel: true, posLevel: true,
@ -2072,7 +2077,7 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdatePositionTempProfileEmployee, @Body() body: UpdatePositionTempProfileEmployee,
) { ) {
await new permission().PermissionCreate(request, "SYS_REGISTRY_TEMP"); await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", id)
if (body.posLevelId === "") body.posLevelId = null; if (body.posLevelId === "") body.posLevelId = null;
if (body.posTypeId === "") body.posTypeId = null; if (body.posTypeId === "") body.posTypeId = null;
@ -2202,9 +2207,11 @@ export class ProfileEmployeeController extends Controller {
@Put("citizenId/{id}") @Put("citizenId/{id}")
async checkCitizenIdProfile( async checkCitizenIdProfile(
@Path() id: string, @Path() id: string,
@Request() req: RequestWithUser,
@Body() @Body()
requestBody: { citizenId: string }, requestBody: { citizenId: string },
) { ) {
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", id)
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: Not(id), citizenId: requestBody.citizenId }, where: { id: Not(id), citizenId: requestBody.citizenId },
}); });
@ -2553,6 +2560,7 @@ export class ProfileEmployeeController extends Controller {
@Get("keycloak/position/{revisionId}") @Get("keycloak/position/{revisionId}")
async getProfileByKeycloakByRevision( async getProfileByKeycloakByRevision(
@Path() revisionId: string, @Path() revisionId: string,
@Path() req: RequestWithUser,
@Request() request: { user: Record<string, any> }, @Request() request: { user: Record<string, any> },
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
@ -2562,7 +2570,7 @@ export class ProfileEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profile.id)
const _profile = { const _profile = {
profileId: profile.id, profileId: profile.id,
rank: profile.rank, rank: profile.rank,
@ -2651,7 +2659,7 @@ export class ProfileEmployeeController extends Controller {
* @summary * @summary
* *
*/ */
@Get("profileid/retire/{year}") @Get("profileid/retire/{year}") //ตส
async getProfileByRetireYear(@Path() year: number) { async getProfileByRetireYear(@Path() year: number) {
const profiles = await this.profileRepo const profiles = await this.profileRepo
.createQueryBuilder("profileEmployee") .createQueryBuilder("profileEmployee")
@ -2849,12 +2857,13 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() @Body()
requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date }, requestBody: { isLeave: boolean; leaveReason: string; dateLeave: Date },
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: id }, where: { id: id },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserCreate(request, "SYS_REGISTRY_EMP", profile.id)
profile.isLeave = requestBody.isLeave; profile.isLeave = requestBody.isLeave;
profile.leaveReason = requestBody.leaveReason; profile.leaveReason = requestBody.leaveReason;
@ -2885,7 +2894,8 @@ export class ProfileEmployeeController extends Controller {
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
@Body() body: UpdateInformationProfileEmployee, @Body() body: UpdateInformationProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request, "SYS_REGISTRY_TEMP");
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", profileEmployeeId)
const profileEmp = await this.profileRepo.findOneBy({ id: profileEmployeeId }); const profileEmp = await this.profileRepo.findOneBy({ id: profileEmployeeId });
if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้"); if (!profileEmp) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลโปรไฟล์นี้");
@ -2913,7 +2923,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} profileEmployeeId profileEmployeeId * @param {string} profileEmployeeId profileEmployeeId
*/ */
@Get("information/{profileEmployeeId}") @Get("information/{profileEmployeeId}")
async getInformationById(@Path() profileEmployeeId: string) { async getInformationById(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const profileInformation = await this.profileRepo.findOne({ const profileInformation = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
@ -2943,7 +2954,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} profileEmployeeId profileEmployeeId * @param {string} profileEmployeeId profileEmployeeId
*/ */
@Get("information/history/{profileEmployeeId}") @Get("information/history/{profileEmployeeId}")
async getInformationHistory(@Path() profileEmployeeId: string) { async getInformationHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const profileInformation = await this.profileRepo.find({ const profileInformation = await this.profileRepo.find({
relations: { relations: {
information_histories: true, information_histories: true,
@ -2984,7 +2996,8 @@ export class ProfileEmployeeController extends Controller {
* @param {string} profileEmployeeId profileEmployeeId * @param {string} profileEmployeeId profileEmployeeId
*/ */
@Get("employment/{profileEmployeeId}") @Get("employment/{profileEmployeeId}")
async ProfileEmployeeEmployment(@Path() profileEmployeeId: string) { async ProfileEmployeeEmployment(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const employment = await this.employmentRepository.find({ const employment = await this.employmentRepository.find({
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId },
order: { createdAt: "ASC" }, order: { createdAt: "ASC" },
@ -3005,10 +3018,13 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("employment/id/{id}") @Get("employment/id/{id}")
async GetEmploymentById(@Path() id: string) { async GetEmploymentById(@Path() id: string, @Request() req: RequestWithUser) {
const employment = await this.employmentRepository.findOne({ const employment = await this.employmentRepository.findOne({
where: { id: id }, where: { id: id },
}); });
if (employment) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
}
return new HttpSuccess(employment); return new HttpSuccess(employment);
} }
@ -3020,7 +3036,13 @@ export class ProfileEmployeeController extends Controller {
* @param {string} id Id * @param {string} id Id
*/ */
@Get("employment/history/{id}") @Get("employment/history/{id}")
async GetHistoryEmploymentById(@Path() id: string) { async GetHistoryEmploymentById(@Path() id: string, @Request() req: RequestWithUser) {
const employment = await this.employmentRepository.findOne({
where: { id: id },
});
if (employment) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
}
const employmentHistory = await this.employmentHistoryRepository.find({ const employmentHistory = await this.employmentHistoryRepository.find({
where: { profileEmployeeEmploymentId: id }, where: { profileEmployeeEmploymentId: id },
order: { lastUpdatedAt: "ASC" }, order: { lastUpdatedAt: "ASC" },
@ -3045,6 +3067,7 @@ export class ProfileEmployeeController extends Controller {
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!profile) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserList(request, "SYS_REGISTRY_EMP", profile.id)
const employment = new ProfileEmployeeEmployment(); const employment = new ProfileEmployeeEmployment();
// const history = new ProfileEmployeeEmploymentHistory(); // const history = new ProfileEmployeeEmploymentHistory();
@ -3076,7 +3099,12 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Delete("employment/{id}") @Delete("employment/{id}")
async DeleteEmployment(@Path() id: string, @Request() request: RequestWithUser) { async DeleteEmployment(@Path() id: string, @Request() request: RequestWithUser) {
await new permission().PermissionDelete(request, "SYS_REGISTRY_TEMP"); const employment = await this.employmentRepository.findOne({
where: { id: id },
});
if (employment) {
await new permission().PermissionOrgUserDelete(request, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
}
await this.employmentHistoryRepository.delete({ await this.employmentHistoryRepository.delete({
profileEmployeeEmploymentId: id, profileEmployeeEmploymentId: id,
}); });
@ -3101,9 +3129,10 @@ export class ProfileEmployeeController extends Controller {
@Path() id: string, @Path() id: string,
@Body() body: UpdateEmploymentProfileEmployee, @Body() body: UpdateEmploymentProfileEmployee,
) { ) {
await new permission().PermissionUpdate(request, "SYS_REGISTRY_TEMP");
const employment = await this.employmentRepository.findOneBy({ id }); const employment = await this.employmentRepository.findOneBy({ id });
if (!employment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!employment) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(request, "SYS_REGISTRY_EMP", employment.profileEmployeeId)
const history = new ProfileEmployeeEmploymentHistory(); const history = new ProfileEmployeeEmploymentHistory();
Object.assign(history, { ...employment, id: undefined }); Object.assign(history, { ...employment, id: undefined });
@ -3386,7 +3415,7 @@ export class ProfileEmployeeController extends Controller {
*/ */
@Get("profileid/position/{id}") @Get("profileid/position/{id}")
async getProfileByProfileid( async getProfileByProfileid(
@Request() request: { user: Record<string, any> }, @Request() request: RequestWithUser,
@Path() id: string, @Path() id: string,
) { ) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
@ -3396,6 +3425,7 @@ export class ProfileEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูลบุคคลนี้ในระบบ");
} }
await new permission().PermissionOrgUserGet(request, "SYS_REGISTRY_EMP", profile.id);
const orgRevisionPublish = await this.orgRevisionRepo const orgRevisionPublish = await this.orgRevisionRepo
.createQueryBuilder("orgRevision") .createQueryBuilder("orgRevision")

View file

@ -77,14 +77,15 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}, },
}) })
public async getFamilyCouple(@Path() profileEmployeeId: string) { public async getFamilyCouple(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profile.id);
const familyCouple = await this.ProfileFamilyCouple.findOne({ const familyCouple = await this.ProfileFamilyCouple.findOne({
select: [ select: [
"id", "id",
@ -176,13 +177,14 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
}, },
], ],
}) })
public async familyCoupleHistory(@Path() profileEmployeeId: string) { public async familyCoupleHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profile.id);
const familyCouple = await this.ProfileFamilyCouple.find({ const familyCouple = await this.ProfileFamilyCouple.find({
relations: ["histories"], relations: ["histories"],
@ -220,7 +222,6 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyCouple, @Body() body: CreateProfileEmployeeFamilyCouple,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
const familyCouple = Object.assign(new ProfileFamilyCouple(), body); const familyCouple = Object.assign(new ProfileFamilyCouple(), body);
if (!familyCouple) { if (!familyCouple) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -229,6 +230,8 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId)); familyCouple.coupleCitizenId = Extension.CheckCitizen(String(body.coupleCitizenId));
familyCouple.createdUserId = req.user.sub; familyCouple.createdUserId = req.user.sub;
familyCouple.createdFullName = req.user.name; familyCouple.createdFullName = req.user.name;
@ -253,7 +256,7 @@ export class ProfileFamilyCoupleEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyCouple, @Body() body: UpdateProfileFamilyCouple,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP"); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const familyCouple = await this.ProfileFamilyCouple.findOneBy({ const familyCouple = await this.ProfileFamilyCouple.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -73,11 +73,11 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}, },
}) })
public async getFamilyFather(@Path() profileEmployeeId: string) { public async getFamilyFather(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
@ -164,7 +164,8 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
}, },
], ],
}) })
public async familyFatherHistory(@Path() profileEmployeeId: string) { public async familyFatherHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
@ -206,7 +207,6 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyFather, @Body() body: CreateProfileEmployeeFamilyFather,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
const familyFather = Object.assign(new ProfileFamilyFather(), body); const familyFather = Object.assign(new ProfileFamilyFather(), body);
if (!familyFather) { if (!familyFather) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -215,6 +215,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId)); familyFather.fatherCitizenId = Extension.CheckCitizen(String(body.fatherCitizenId));
familyFather.createdUserId = req.user.sub; familyFather.createdUserId = req.user.sub;
familyFather.createdFullName = req.user.name; familyFather.createdFullName = req.user.name;
@ -237,7 +238,7 @@ export class ProfileFamilyFatherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyFather, @Body() body: UpdateProfileFamilyFather,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP"); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const familyFather = await this.ProfileFamilyFather.findOneBy({ const familyFather = await this.ProfileFamilyFather.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -73,7 +73,8 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201", profileEmployeeId: "1526d9d3-d8b1-43ab-81b5-a84dfbe99201",
}, },
}) })
public async getFamilyMother(@Path() profileEmployeeId: string) { public async getFamilyMother(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
@ -164,14 +165,14 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
}, },
], ],
}) })
public async familyMotherHistory(@Path() profileEmployeeId: string) { public async familyMotherHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const profile = await this.profileRepo.findOne({ const profile = await this.profileRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
const familyMother = await this.ProfileFamilyMother.find({ const familyMother = await this.ProfileFamilyMother.find({
relations: ["histories"], relations: ["histories"],
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
@ -206,7 +207,6 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeFamilyMother, @Body() body: CreateProfileEmployeeFamilyMother,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
const familyMother = Object.assign(new ProfileFamilyMother(), body); const familyMother = Object.assign(new ProfileFamilyMother(), body);
if (!familyMother) { if (!familyMother) {
throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
@ -215,6 +215,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId)); familyMother.motherCitizenId = Extension.CheckCitizen(String(body.motherCitizenId));
familyMother.createdUserId = req.user.sub; familyMother.createdUserId = req.user.sub;
familyMother.createdFullName = req.user.name; familyMother.createdFullName = req.user.name;
@ -237,7 +238,7 @@ export class ProfileFamilyMotherEmployeeController extends Controller {
@Body() body: UpdateProfileFamilyMother, @Body() body: UpdateProfileFamilyMother,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP"); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const familyMother = await this.ProfileFamilyMother.findOneBy({ const familyMother = await this.ProfileFamilyMother.findOneBy({
profileEmployeeId: profileEmployeeId, profileEmployeeId: profileEmployeeId,
}); });

View file

@ -134,7 +134,8 @@ export class ProfileGovernmentEmployeeController extends Controller {
*/ */
@Get("{profileEmployeeId}") @Get("{profileEmployeeId}")
@Example({}) @Example({})
public async getGovHistory(@Path() profileEmployeeId: string) { public async getGovHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.profileEmployeeRepo.findOne({ const record = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
relations: { relations: {
@ -240,7 +241,8 @@ export class ProfileGovernmentEmployeeController extends Controller {
*/ */
@Get("history/{profileEmployeeId}") @Get("history/{profileEmployeeId}")
@Example({}) @Example({})
public async govHistory(@Path() profileEmployeeId: string) { public async govHistory(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const record = await this.govRepo.find({ const record = await this.govRepo.find({
order: { lastUpdatedAt: "DESC" }, order: { lastUpdatedAt: "DESC" },
where: { profileEmployeeId: profileEmployeeId }, where: { profileEmployeeId: profileEmployeeId },
@ -259,7 +261,7 @@ export class ProfileGovernmentEmployeeController extends Controller {
@Body() body: UpdateProfileGovernment, @Body() body: UpdateProfileGovernment,
@Path() profileEmployeeId: string, @Path() profileEmployeeId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP"); await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", profileEmployeeId)
const record = await this.profileEmployeeRepo.findOne({ const record = await this.profileEmployeeRepo.findOne({
where: { id: profileEmployeeId }, where: { id: profileEmployeeId },
}); });

View file

@ -68,7 +68,8 @@ export class ProfileHonorEmployeeController extends Controller {
}, },
], ],
}) })
public async getHonor(@Path() profileEmployeeId: string) { public async getHonor(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.honorRepo.findBy({ profileEmployeeId }); const record = await this.honorRepo.findBy({ profileEmployeeId });
return new HttpSuccess(record); return new HttpSuccess(record);
} }
@ -133,7 +134,12 @@ export class ProfileHonorEmployeeController extends Controller {
}, },
], ],
}) })
public async honorHistory(@Path() honorId: string) { public async honorHistory(@Path() honorId: string, @Request() req: RequestWithUser) {
const _record = await this.honorRepo.findOneBy({ id: honorId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.honorHistoryRepo.findBy({ const record = await this.honorHistoryRepo.findBy({
profileHonorId: honorId, profileHonorId: honorId,
}); });
@ -142,16 +148,15 @@ export class ProfileHonorEmployeeController extends Controller {
@Post() @Post()
public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) { public async newHonor(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeHonor) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileHonor(); const data = new ProfileHonor();
@ -179,10 +184,9 @@ export class ProfileHonorEmployeeController extends Controller {
@Body() body: UpdateProfileHonor, @Body() body: UpdateProfileHonor,
@Path() honorId: string, @Path() honorId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.honorRepo.findOneBy({ id: honorId }); const record = await this.honorRepo.findOneBy({ id: honorId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileHonorHistory(); const history = new ProfileHonorHistory();
@ -204,7 +208,11 @@ export class ProfileHonorEmployeeController extends Controller {
@Delete("{honorId}") @Delete("{honorId}")
public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) { public async deleteTraning(@Path() honorId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.honorRepo.findOneBy({ id: honorId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.honorHistoryRepo.delete({ await this.honorHistoryRepo.delete({
profileHonorId: honorId, profileHonorId: honorId,
}); });

View file

@ -83,7 +83,8 @@ export class ProfileInsigniaEmployeeController extends Controller {
}, },
], ],
}) })
public async getInsignia(@Path() profileEmployeeId: string) { public async getInsignia(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.insigniaRepo.find({ const record = await this.insigniaRepo.find({
relations: { relations: {
insignia: { insignia: {
@ -150,7 +151,11 @@ export class ProfileInsigniaEmployeeController extends Controller {
}, },
], ],
}) })
public async getInsigniaHistory(@Path() InsigniaId: string) { public async getInsigniaHistory(@Path() InsigniaId: string, @Request() req: RequestWithUser) {
const _record = await this.insigniaRepo.findOneBy({ id: InsigniaId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.insigniaHistoryRepo.find({ const record = await this.insigniaHistoryRepo.find({
relations: { relations: {
insignia: { insignia: {
@ -169,16 +174,15 @@ export class ProfileInsigniaEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeInsignia, @Body() body: CreateProfileEmployeeInsignia,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id)
const insignia = await this.insigniaMetaRepo.findOne({ const insignia = await this.insigniaMetaRepo.findOne({
where: { id: body.insigniaId }, where: { id: body.insigniaId },
@ -213,10 +217,9 @@ export class ProfileInsigniaEmployeeController extends Controller {
@Body() body: UpdateProfileInsignia, @Body() body: UpdateProfileInsignia,
@Path() insigniaId: string, @Path() insigniaId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.insigniaRepo.findOneBy({ id: insigniaId }); const record = await this.insigniaRepo.findOneBy({ id: insigniaId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const insignia = await this.insigniaMetaRepo.findOne({ const insignia = await this.insigniaMetaRepo.findOne({
where: { id: body.insigniaId }, where: { id: body.insigniaId },
@ -245,7 +248,11 @@ export class ProfileInsigniaEmployeeController extends Controller {
@Delete("{insigniaId}") @Delete("{insigniaId}")
public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) { public async deleteInsignia(@Path() insigniaId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.insigniaRepo.findOneBy({ id: insigniaId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.insigniaHistoryRepo.delete({ await this.insigniaHistoryRepo.delete({
profileInsigniaId: insigniaId, profileInsigniaId: insigniaId,
}); });

View file

@ -49,7 +49,8 @@ export class ProfileLeaveEmployeeController extends Controller {
} }
@Get("{profileId}") @Get("{profileId}")
public async getLeave(@Path() profileId: string) { public async getLeave(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.leaveRepo.find({ const record = await this.leaveRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
@ -58,7 +59,11 @@ export class ProfileLeaveEmployeeController extends Controller {
} }
@Get("history/{leaveId}") @Get("history/{leaveId}")
public async leaveHistory(@Path() leaveId: string) { public async leaveHistory(@Path() leaveId: string, @Request() req: RequestWithUser) {
const _record = await this.leaveRepo.findOneBy({ id: leaveId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.leaveHistoryRepo.find({ const record = await this.leaveHistoryRepo.find({
relations: { leaveType: true }, relations: { leaveType: true },
where: { profileLeaveId: leaveId }, where: { profileLeaveId: leaveId },
@ -68,16 +73,17 @@ export class ProfileLeaveEmployeeController extends Controller {
@Post() @Post()
public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) { public async newLeave(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeLeave) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const leaveType = await this.leaveTypeRepository.findOne({ const leaveType = await this.leaveTypeRepository.findOne({
where: { id: body.leaveTypeId }, where: { id: body.leaveTypeId },
}); });
@ -111,10 +117,9 @@ export class ProfileLeaveEmployeeController extends Controller {
@Body() body: UpdateProfileLeave, @Body() body: UpdateProfileLeave,
@Path() leaveId: string, @Path() leaveId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.leaveRepo.findOneBy({ id: leaveId }); const record = await this.leaveRepo.findOneBy({ id: leaveId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const leaveType = await this.leaveTypeRepository.findOne({ const leaveType = await this.leaveTypeRepository.findOne({
where: { id: body.leaveTypeId }, where: { id: body.leaveTypeId },
@ -143,7 +148,11 @@ export class ProfileLeaveEmployeeController extends Controller {
@Delete("{leaveId}") @Delete("{leaveId}")
public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) { public async deleteLeave(@Path() leaveId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.leaveRepo.findOneBy({ id: leaveId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.leaveHistoryRepo.delete({ await this.leaveHistoryRepo.delete({
profileLeaveId: leaveId, profileLeaveId: leaveId,
}); });

View file

@ -67,16 +67,16 @@ export class ProfileNopaidEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeNopaid, @Body() body: CreateProfileEmployeeNopaid,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileNopaid(); const data = new ProfileNopaid();
@ -104,10 +104,9 @@ export class ProfileNopaidEmployeeController extends Controller {
@Body() body: UpdateProfileNopaid, @Body() body: UpdateProfileNopaid,
@Path() nopaidId: string, @Path() nopaidId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.nopaidRepository.findOneBy({ id: nopaidId }); const record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileNopaidHistory(); const history = new ProfileNopaidHistory();
@ -132,7 +131,11 @@ export class ProfileNopaidEmployeeController extends Controller {
@Delete("{nopaidId}") @Delete("{nopaidId}")
public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) { public async deleteNopaid(@Path() nopaidId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.nopaidRepository.findOneBy({ id: nopaidId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.nopaidHistoryRepository.delete({ await this.nopaidHistoryRepository.delete({
profileNopaidId: nopaidId, profileNopaidId: nopaidId,
}); });

View file

@ -46,7 +46,8 @@ export class ProfileOtherEmployeeController extends Controller {
} }
@Get("{profileId}") @Get("{profileId}")
public async getOther(@Path() profileId: string) { public async getOther(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const lists = await this.otherRepository.find({ const lists = await this.otherRepository.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
}); });
@ -54,7 +55,11 @@ export class ProfileOtherEmployeeController extends Controller {
} }
@Get("history/{otherId}") @Get("history/{otherId}")
public async otherHistory(@Path() otherId: string) { public async otherHistory(@Path() otherId: string, @Request() req: RequestWithUser) {
const _record = await this.otherRepository.findOneBy({ id: otherId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.otherHistoryRepository.find({ const record = await this.otherHistoryRepository.find({
where: { profileOtherId: otherId }, where: { profileOtherId: otherId },
order: { createdAt: "DESC" }, order: { createdAt: "DESC" },
@ -64,16 +69,15 @@ export class ProfileOtherEmployeeController extends Controller {
@Post() @Post()
public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) { public async newOther(@Request() req: RequestWithUser, @Body() body: CreateProfileEmployeeOther) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileId");
} }
const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepository.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileOther(); const data = new ProfileOther();
@ -101,10 +105,10 @@ export class ProfileOtherEmployeeController extends Controller {
@Body() body: UpdateProfileOther, @Body() body: UpdateProfileOther,
@Path() otherId: string, @Path() otherId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.otherRepository.findOneBy({ id: otherId });
const record = await this.otherRepository.findOneBy({ id: otherId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileOtherHistory(); const history = new ProfileOtherHistory();
@ -129,7 +133,11 @@ export class ProfileOtherEmployeeController extends Controller {
@Delete("{otherId}") @Delete("{otherId}")
public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) { public async deleteOther(@Path() otherId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.otherRepository.findOneBy({ id: otherId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.otherHistoryRepository.delete({ await this.otherHistoryRepository.delete({
profileOtherId: otherId, profileOtherId: otherId,
}); });

View file

@ -48,7 +48,8 @@ export class ProfileSalaryEmployeeController extends Controller {
} }
@Get("{profileId}") @Get("{profileId}")
public async getSalaryEmployee(@Path() profileId: string) { public async getSalaryEmployee(@Path() profileId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileId);
const record = await this.salaryRepo.find({ const record = await this.salaryRepo.find({
where: { profileEmployeeId: profileId }, where: { profileEmployeeId: profileId },
order: { order: "ASC" }, order: { order: "ASC" },
@ -57,7 +58,11 @@ export class ProfileSalaryEmployeeController extends Controller {
} }
@Get("history/{salaryId}") @Get("history/{salaryId}")
public async salaryHistory(@Path() salaryId: string) { public async salaryHistory(@Path() salaryId: string, @Request() req: RequestWithUser) {
const _record = await this.salaryRepo.findOneBy({ id: salaryId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.salaryHistoryRepo.findBy({ const record = await this.salaryHistoryRepo.findBy({
profileSalaryId: salaryId, profileSalaryId: salaryId,
}); });
@ -69,16 +74,15 @@ export class ProfileSalaryEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileSalaryEmployee, @Body() body: CreateProfileSalaryEmployee,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const dest_item = await this.salaryRepo.findOne({ const dest_item = await this.salaryRepo.findOne({
where: { profileEmployeeId: body.profileEmployeeId }, where: { profileEmployeeId: body.profileEmployeeId },
@ -112,10 +116,10 @@ export class ProfileSalaryEmployeeController extends Controller {
@Body() body: UpdateProfileSalaryEmployee, @Body() body: UpdateProfileSalaryEmployee,
@Path() salaryId: string, @Path() salaryId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.salaryRepo.findOneBy({ id: salaryId });
const record = await this.salaryRepo.findOneBy({ id: salaryId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileSalaryHistory(); const history = new ProfileSalaryHistory();
@ -137,7 +141,11 @@ export class ProfileSalaryEmployeeController extends Controller {
@Delete("{salaryId}") @Delete("{salaryId}")
public async deleteSalaryEmployee(@Path() salaryId: string, @Request() req: RequestWithUser) { public async deleteSalaryEmployee(@Path() salaryId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.salaryRepo.findOneBy({ id: salaryId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.salaryHistoryRepo.delete({ await this.salaryHistoryRepo.delete({
profileSalaryId: salaryId, profileSalaryId: salaryId,
}); });
@ -152,7 +160,11 @@ export class ProfileSalaryEmployeeController extends Controller {
} }
@Get("swap/{direction}/{salaryId}") @Get("swap/{direction}/{salaryId}")
public async swapSalaryEmployee(@Path() direction: string, salaryId: string) { public async swapSalaryEmployee(@Path() direction: string, salaryId: string, @Request() req: RequestWithUser) {
const _record = await this.salaryRepo.findOneBy({ id: salaryId });
if (_record) {
await new permission().PermissionOrgUserGet(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } }); const source_item = await this.salaryRepo.findOne({ where: { id: salaryId } });
if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (source_item == null) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
const sourceOrder = source_item.order; const sourceOrder = source_item.order;

View file

@ -74,7 +74,8 @@ export class ProfileTrainingEmployeeController extends Controller {
}, },
], ],
}) })
public async getTraining(@Path() profileEmployeeId: string) { public async getTraining(@Path() profileEmployeeId: string, @Request() req: RequestWithUser) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", profileEmployeeId);
const record = await this.trainingRepo.findBy({ profileEmployeeId }); const record = await this.trainingRepo.findBy({ profileEmployeeId });
return new HttpSuccess(record); return new HttpSuccess(record);
} }
@ -130,7 +131,12 @@ export class ProfileTrainingEmployeeController extends Controller {
}, },
], ],
}) })
public async trainingHistory(@Path() trainingId: string) { public async trainingHistory(@Path() trainingId: string, @Request() req: RequestWithUser) {
const _record = await this.trainingRepo.findOneBy({ id: trainingId });
if (_record) {
await new permission().PermissionOrgUserList(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
const record = await this.trainingHistoryRepo.findBy({ const record = await this.trainingHistoryRepo.findBy({
profileTrainingId: trainingId, profileTrainingId: trainingId,
}); });
@ -142,16 +148,16 @@ export class ProfileTrainingEmployeeController extends Controller {
@Request() req: RequestWithUser, @Request() req: RequestWithUser,
@Body() body: CreateProfileEmployeeTraining, @Body() body: CreateProfileEmployeeTraining,
) { ) {
await new permission().PermissionCreate(req, "SYS_REGISTRY_EMP");
if (!body.profileEmployeeId) { if (!body.profileEmployeeId) {
throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId"); throw new HttpError(HttpStatus.BAD_REQUEST, "กรุณากรอก profileEmployeeId");
} }
const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId }); const profile = await this.profileEmployeeRepo.findOneBy({ id: body.profileEmployeeId });
if (!profile) { if (!profile) {
throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว"); throw new HttpError(HttpStatus.BAD_REQUEST, "ไม่พบ profile ดังกล่าว");
} }
await new permission().PermissionOrgUserCreate(req, "SYS_REGISTRY_EMP", profile.id);
const data = new ProfileTraining(); const data = new ProfileTraining();
@ -179,10 +185,9 @@ export class ProfileTrainingEmployeeController extends Controller {
@Body() body: UpdateProfileTraining, @Body() body: UpdateProfileTraining,
@Path() trainingId: string, @Path() trainingId: string,
) { ) {
await new permission().PermissionUpdate(req, "SYS_REGISTRY_EMP");
const record = await this.trainingRepo.findOneBy({ id: trainingId }); const record = await this.trainingRepo.findOneBy({ id: trainingId });
if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล"); if (!record) throw new HttpError(HttpStatus.NOT_FOUND, "ไม่พบข้อมูล");
await new permission().PermissionOrgUserUpdate(req, "SYS_REGISTRY_EMP", record.profileEmployeeId)
const history = new ProfileTrainingHistory(); const history = new ProfileTrainingHistory();
@ -204,7 +209,11 @@ export class ProfileTrainingEmployeeController extends Controller {
@Delete("{trainingId}") @Delete("{trainingId}")
public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) { public async deleteTraining(@Path() trainingId: string, @Request() req: RequestWithUser) {
await new permission().PermissionDelete(req, "SYS_REGISTRY_EMP"); const _record = await this.trainingRepo.findOneBy({ id: trainingId });
if (_record) {
await new permission().PermissionOrgUserDelete(req, "SYS_REGISTRY_EMP", _record.profileEmployeeId);
}
await this.trainingHistoryRepo.delete({ await this.trainingHistoryRepo.delete({
profileTrainingId: trainingId, profileTrainingId: trainingId,
}); });