refactor: change the role to roles and many to many
This commit is contained in:
@@ -106,7 +106,7 @@ export class DanakServicesController {
|
||||
@AuthGuards()
|
||||
@Roles(RoleEnum.USER, RoleEnum.ADMIN)
|
||||
@Get(":id")
|
||||
getDanakServiceById(@Param() paramDto: ParamDto, @UserDec("role") userRole: RoleEnum) {
|
||||
getDanakServiceById(@Param() paramDto: ParamDto, @UserDec("roles") userRole: RoleEnum[]) {
|
||||
return this.danakServicesService.getDanakServiceByIdWithSubs(paramDto.id, userRole);
|
||||
}
|
||||
|
||||
|
||||
@@ -173,9 +173,10 @@ export class DanakServicesService {
|
||||
}
|
||||
/******************************************** */
|
||||
|
||||
async getDanakServiceByIdWithSubs(serviceId: string, role: RoleEnum) {
|
||||
async getDanakServiceByIdWithSubs(serviceId: string, roles: RoleEnum[]) {
|
||||
const hasAccess = roles.includes(RoleEnum.ADMIN);
|
||||
const danakService = await this.danakServicesRepository.findOne({
|
||||
where: { id: serviceId, ...(role !== RoleEnum.ADMIN && { isActive: true, subscriptionPlans: { isActive: true } }) },
|
||||
where: { id: serviceId, ...(hasAccess && { isActive: true, subscriptionPlans: { isActive: true } }) },
|
||||
relations: { images: true, subscriptionPlans: true },
|
||||
});
|
||||
if (!danakService) throw new BadRequestException(ServiceMessage.SERVICE_NOT_FOUND_BY_ID);
|
||||
|
||||
Reference in New Issue
Block a user