Refactor space permission service

This commit is contained in:
faris Aljohari
2024-05-08 09:35:42 +03:00
parent aff52be540
commit 616ddd4d4c
2 changed files with 21 additions and 17 deletions

View File

@ -11,25 +11,29 @@ export class SpacePermissionService {
userUuid: string,
type: string,
): Promise<void> {
const spaceData = await this.spaceRepository.findOne({
where: {
uuid: spaceUuid,
spaceType: {
type: type,
},
userSpaces: {
user: {
uuid: userUuid,
try {
const spaceData = await this.spaceRepository.findOne({
where: {
uuid: spaceUuid,
spaceType: {
type: type,
},
userSpaces: {
user: {
uuid: userUuid,
},
},
},
},
relations: ['spaceType', 'userSpaces', 'userSpaces.user'],
});
relations: ['spaceType', 'userSpaces', 'userSpaces.user'],
});
if (!spaceData) {
throw new BadRequestException(
`You do not have permission to access this ${type}`,
);
if (!spaceData) {
throw new BadRequestException(
`You do not have permission to access this ${type}`,
);
}
} catch (err) {
throw new BadRequestException(err.message || 'Invalid UUID');
}
}
}

View File

@ -111,7 +111,7 @@ export class CommunityController {
}
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
@Put('rename/:communityUuid')
async renameCommunityByUuid(
@Param('communityUuid') communityUuid: string,