mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-27 04:34:54 +00:00
Merge pull request #31 from SyncrowIOT/SP-202-be-handle-space-permissions
Sp 202 be handle space permissions
This commit is contained in:
@ -1,11 +1,14 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { HelperHashService } from './services';
|
import { HelperHashService } from './services';
|
||||||
|
import { SpacePermissionService } from './services/space.permission.service';
|
||||||
|
import { SpaceRepository } from '../modules/space/repositories';
|
||||||
|
import { SpaceRepositoryModule } from '../modules/space/space.repository.module';
|
||||||
|
|
||||||
@Global()
|
@Global()
|
||||||
@Module({
|
@Module({
|
||||||
providers: [HelperHashService],
|
providers: [HelperHashService, SpacePermissionService, SpaceRepository],
|
||||||
exports: [HelperHashService],
|
exports: [HelperHashService, SpacePermissionService],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
imports: [],
|
imports: [SpaceRepositoryModule],
|
||||||
})
|
})
|
||||||
export class HelperModule {}
|
export class HelperModule {}
|
||||||
|
|||||||
@ -1 +1,2 @@
|
|||||||
export * from './helper.hash.service';
|
export * from './helper.hash.service';
|
||||||
|
export * from './space.permission.service';
|
||||||
|
|||||||
39
libs/common/src/helper/services/space.permission.service.ts
Normal file
39
libs/common/src/helper/services/space.permission.service.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
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> {
|
||||||
|
try {
|
||||||
|
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}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
throw new BadRequestException(err.message || 'Invalid UUID');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -18,6 +18,7 @@ import { GetBuildingChildDto } from '../dtos/get.building.dto';
|
|||||||
import { UpdateBuildingNameDto } from '../dtos/update.building.dto';
|
import { UpdateBuildingNameDto } from '../dtos/update.building.dto';
|
||||||
import { CheckCommunityTypeGuard } from 'src/guards/community.type.guard';
|
import { CheckCommunityTypeGuard } from 'src/guards/community.type.guard';
|
||||||
import { CheckUserBuildingGuard } from 'src/guards/user.building.guard';
|
import { CheckUserBuildingGuard } from 'src/guards/user.building.guard';
|
||||||
|
import { BuildingPermissionGuard } from 'src/guards/building.permission.guard';
|
||||||
|
|
||||||
@ApiTags('Building Module')
|
@ApiTags('Building Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -43,7 +44,7 @@ export class BuildingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||||
@Get(':buildingUuid')
|
@Get(':buildingUuid')
|
||||||
async getBuildingByUuid(@Param('buildingUuid') buildingUuid: string) {
|
async getBuildingByUuid(@Param('buildingUuid') buildingUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -59,7 +60,7 @@ export class BuildingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||||
@Get('child/:buildingUuid')
|
@Get('child/:buildingUuid')
|
||||||
async getBuildingChildByUuid(
|
async getBuildingChildByUuid(
|
||||||
@Param('buildingUuid') buildingUuid: string,
|
@Param('buildingUuid') buildingUuid: string,
|
||||||
@ -79,7 +80,7 @@ export class BuildingController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||||
@Get('parent/:buildingUuid')
|
@Get('parent/:buildingUuid')
|
||||||
async getBuildingParentByUuid(@Param('buildingUuid') buildingUuid: string) {
|
async getBuildingParentByUuid(@Param('buildingUuid') buildingUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -122,7 +123,7 @@ export class BuildingController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
|
||||||
@Put('rename/:buildingUuid')
|
@Put('rename/:buildingUuid')
|
||||||
async renameBuildingByUuid(
|
async renameBuildingByUuid(
|
||||||
@Param('buildingUuid') buildingUuid: string,
|
@Param('buildingUuid') buildingUuid: string,
|
||||||
|
|||||||
@ -10,6 +10,7 @@ import { UserSpaceRepositoryModule } from '@app/common/modules/user-space/user.s
|
|||||||
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
import { UserSpaceRepository } from '@app/common/modules/user-space/repositories';
|
||||||
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
import { UserRepositoryModule } from '@app/common/modules/user/user.repository.module';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
|
import { SpacePermissionService } from '@app/common/helper/services';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@ -26,7 +27,8 @@ import { UserRepository } from '@app/common/modules/user/repositories';
|
|||||||
SpaceTypeRepository,
|
SpaceTypeRepository,
|
||||||
UserSpaceRepository,
|
UserSpaceRepository,
|
||||||
UserRepository,
|
UserRepository,
|
||||||
|
SpacePermissionService,
|
||||||
],
|
],
|
||||||
exports: [CommunityService],
|
exports: [CommunityService, SpacePermissionService],
|
||||||
})
|
})
|
||||||
export class CommunityModule {}
|
export class CommunityModule {}
|
||||||
|
|||||||
@ -20,6 +20,7 @@ import {
|
|||||||
import { GetCommunityChildDto } from '../dtos/get.community.dto';
|
import { GetCommunityChildDto } from '../dtos/get.community.dto';
|
||||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||||
import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
||||||
|
import { CommunityPermissionGuard } from 'src/guards/community.permission.guard';
|
||||||
|
|
||||||
@ApiTags('Community Module')
|
@ApiTags('Community Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -46,7 +47,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||||
@Get(':communityUuid')
|
@Get(':communityUuid')
|
||||||
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
|
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -62,7 +63,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||||
@Get('child/:communityUuid')
|
@Get('child/:communityUuid')
|
||||||
async getCommunityChildByUuid(
|
async getCommunityChildByUuid(
|
||||||
@Param('communityUuid') communityUuid: string,
|
@Param('communityUuid') communityUuid: string,
|
||||||
@ -110,7 +111,7 @@ export class CommunityController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, CommunityPermissionGuard)
|
||||||
@Put('rename/:communityUuid')
|
@Put('rename/:communityUuid')
|
||||||
async renameCommunityByUuid(
|
async renameCommunityByUuid(
|
||||||
@Param('communityUuid') communityUuid: string,
|
@Param('communityUuid') communityUuid: string,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import { GetFloorChildDto } from '../dtos/get.floor.dto';
|
|||||||
import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
||||||
import { CheckBuildingTypeGuard } from 'src/guards/building.type.guard';
|
import { CheckBuildingTypeGuard } from 'src/guards/building.type.guard';
|
||||||
import { CheckUserFloorGuard } from 'src/guards/user.floor.guard';
|
import { CheckUserFloorGuard } from 'src/guards/user.floor.guard';
|
||||||
|
import { FloorPermissionGuard } from 'src/guards/floor.permission.guard';
|
||||||
|
|
||||||
@ApiTags('Floor Module')
|
@ApiTags('Floor Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -43,7 +44,7 @@ export class FloorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||||
@Get(':floorUuid')
|
@Get(':floorUuid')
|
||||||
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
|
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -58,7 +59,7 @@ export class FloorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||||
@Get('child/:floorUuid')
|
@Get('child/:floorUuid')
|
||||||
async getFloorChildByUuid(
|
async getFloorChildByUuid(
|
||||||
@Param('floorUuid') floorUuid: string,
|
@Param('floorUuid') floorUuid: string,
|
||||||
@ -78,7 +79,7 @@ export class FloorController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||||
@Get('parent/:floorUuid')
|
@Get('parent/:floorUuid')
|
||||||
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
|
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -122,7 +123,7 @@ export class FloorController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
|
||||||
@Put('rename/:floorUuid')
|
@Put('rename/:floorUuid')
|
||||||
async renameFloorByUuid(
|
async renameFloorByUuid(
|
||||||
@Param('floorUuid') floorUuid: string,
|
@Param('floorUuid') floorUuid: string,
|
||||||
|
|||||||
35
src/guards/building.permission.guard.ts
Normal file
35
src/guards/building.permission.guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class BuildingPermissionGuard implements CanActivate {
|
||||||
|
constructor(private readonly permissionService: SpacePermissionService) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { buildingUuid } = req.params;
|
||||||
|
const { user } = req;
|
||||||
|
|
||||||
|
if (!buildingUuid) {
|
||||||
|
throw new BadRequestException('buildingUuid is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.permissionService.checkUserPermission(
|
||||||
|
buildingUuid,
|
||||||
|
user.uuid,
|
||||||
|
'building',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/guards/community.permission.guard.ts
Normal file
35
src/guards/community.permission.guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class CommunityPermissionGuard implements CanActivate {
|
||||||
|
constructor(private readonly permissionService: SpacePermissionService) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { communityUuid } = req.params;
|
||||||
|
const { user } = req;
|
||||||
|
|
||||||
|
if (!communityUuid) {
|
||||||
|
throw new BadRequestException('communityUuid is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.permissionService.checkUserPermission(
|
||||||
|
communityUuid,
|
||||||
|
user.uuid,
|
||||||
|
'community',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/guards/floor.permission.guard.ts
Normal file
35
src/guards/floor.permission.guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class FloorPermissionGuard implements CanActivate {
|
||||||
|
constructor(private readonly permissionService: SpacePermissionService) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { floorUuid } = req.params;
|
||||||
|
const { user } = req;
|
||||||
|
|
||||||
|
if (!floorUuid) {
|
||||||
|
throw new BadRequestException('floorUuid is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.permissionService.checkUserPermission(
|
||||||
|
floorUuid,
|
||||||
|
user.uuid,
|
||||||
|
'floor',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/guards/room.permission.guard.ts
Normal file
35
src/guards/room.permission.guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class RoomPermissionGuard implements CanActivate {
|
||||||
|
constructor(private readonly permissionService: SpacePermissionService) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { roomUuid } = req.params;
|
||||||
|
const { user } = req;
|
||||||
|
|
||||||
|
if (!roomUuid) {
|
||||||
|
throw new BadRequestException('roomUuid is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.permissionService.checkUserPermission(
|
||||||
|
roomUuid,
|
||||||
|
user.uuid,
|
||||||
|
'room',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
35
src/guards/unit.permission.guard.ts
Normal file
35
src/guards/unit.permission.guard.ts
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
CanActivate,
|
||||||
|
ExecutionContext,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class UnitPermissionGuard implements CanActivate {
|
||||||
|
constructor(private readonly permissionService: SpacePermissionService) {}
|
||||||
|
|
||||||
|
async canActivate(context: ExecutionContext): Promise<boolean> {
|
||||||
|
const req = context.switchToHttp().getRequest();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const { unitUuid } = req.params;
|
||||||
|
const { user } = req;
|
||||||
|
|
||||||
|
if (!unitUuid) {
|
||||||
|
throw new BadRequestException('unitUuid is required');
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.permissionService.checkUserPermission(
|
||||||
|
unitUuid,
|
||||||
|
user.uuid,
|
||||||
|
'unit',
|
||||||
|
);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,6 +16,7 @@ import { AddRoomDto, AddUserRoomDto } from '../dtos/add.room.dto';
|
|||||||
import { UpdateRoomNameDto } from '../dtos/update.room.dto';
|
import { UpdateRoomNameDto } from '../dtos/update.room.dto';
|
||||||
import { CheckUnitTypeGuard } from 'src/guards/unit.type.guard';
|
import { CheckUnitTypeGuard } from 'src/guards/unit.type.guard';
|
||||||
import { CheckUserRoomGuard } from 'src/guards/user.room.guard';
|
import { CheckUserRoomGuard } from 'src/guards/user.room.guard';
|
||||||
|
import { RoomPermissionGuard } from 'src/guards/room.permission.guard';
|
||||||
|
|
||||||
@ApiTags('Room Module')
|
@ApiTags('Room Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -41,7 +42,7 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||||
@Get(':roomUuid')
|
@Get(':roomUuid')
|
||||||
async getRoomByUuid(@Param('roomUuid') roomUuid: string) {
|
async getRoomByUuid(@Param('roomUuid') roomUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -56,7 +57,7 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||||
@Get('parent/:roomUuid')
|
@Get('parent/:roomUuid')
|
||||||
async getRoomParentByUuid(@Param('roomUuid') roomUuid: string) {
|
async getRoomParentByUuid(@Param('roomUuid') roomUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -98,7 +99,7 @@ export class RoomController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
|
||||||
@Put('rename/:roomUuid')
|
@Put('rename/:roomUuid')
|
||||||
async renameRoomByUuid(
|
async renameRoomByUuid(
|
||||||
@Param('roomUuid') roomUuid: string,
|
@Param('roomUuid') roomUuid: string,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ import { GetUnitChildDto } from '../dtos/get.unit.dto';
|
|||||||
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
||||||
import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard';
|
import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard';
|
||||||
import { CheckUserUnitGuard } from 'src/guards/user.unit.guard';
|
import { CheckUserUnitGuard } from 'src/guards/user.unit.guard';
|
||||||
|
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
||||||
|
|
||||||
@ApiTags('Unit Module')
|
@ApiTags('Unit Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -43,7 +44,7 @@ export class UnitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||||
@Get(':unitUuid')
|
@Get(':unitUuid')
|
||||||
async getUnitByUuid(@Param('unitUuid') unitUuid: string) {
|
async getUnitByUuid(@Param('unitUuid') unitUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -58,7 +59,7 @@ export class UnitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||||
@Get('child/:unitUuid')
|
@Get('child/:unitUuid')
|
||||||
async getUnitChildByUuid(
|
async getUnitChildByUuid(
|
||||||
@Param('unitUuid') unitUuid: string,
|
@Param('unitUuid') unitUuid: string,
|
||||||
@ -75,7 +76,7 @@ export class UnitController {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||||
@Get('parent/:unitUuid')
|
@Get('parent/:unitUuid')
|
||||||
async getUnitParentByUuid(@Param('unitUuid') unitUuid: string) {
|
async getUnitParentByUuid(@Param('unitUuid') unitUuid: string) {
|
||||||
try {
|
try {
|
||||||
@ -117,7 +118,7 @@ export class UnitController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
|
||||||
@Put('rename/:unitUuid')
|
@Put('rename/:unitUuid')
|
||||||
async renameUnitByUuid(
|
async renameUnitByUuid(
|
||||||
@Param('unitUuid') unitUuid: string,
|
@Param('unitUuid') unitUuid: string,
|
||||||
|
|||||||
Reference in New Issue
Block a user