mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 19:07:54 +00:00
Add space permission service and guards for various entities
This commit is contained in:
@@ -1 +1,2 @@
|
||||
export * from './helper.hash.service';
|
||||
export * from './space.permission.service';
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
|
||||
@Injectable()
|
||||
export class SpacePermissionService {
|
||||
constructor(private readonly spaceRepository: SpaceRepository) {}
|
||||
|
||||
async checkUserPermission(
|
||||
spaceUuid: string,
|
||||
userUuid: string,
|
||||
type: string,
|
||||
): Promise<void> {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: {
|
||||
uuid: spaceUuid,
|
||||
spaceType: {
|
||||
type: type,
|
||||
},
|
||||
userSpaces: {
|
||||
user: {
|
||||
uuid: userUuid,
|
||||
},
|
||||
},
|
||||
},
|
||||
relations: ['spaceType', 'userSpaces', 'userSpaces.user'],
|
||||
});
|
||||
|
||||
if (!spaceData) {
|
||||
throw new BadRequestException(
|
||||
`You do not have permission to access this ${type}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user