mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 06:57:54 +00:00
space management without roles
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
export * from './user.controller';
|
||||
export * from './user-communities.controller';
|
||||
export * from './user-space.controller';
|
||||
@@ -0,0 +1,30 @@
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { UserSpaceService } from '../services';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { UserParamDto } from '../dtos';
|
||||
|
||||
@ApiTags('User Module')
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.USER_SPACE.ROUTE,
|
||||
})
|
||||
export class UserSpaceController {
|
||||
constructor(private readonly userSpaceService: UserSpaceService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get()
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.USER_SPACE.ACTIONS.GET_USER_SPACES_SUMMARY,
|
||||
description: ControllerRoute.USER_SPACE.ACTIONS.GET_USER_SPACES_DESCRIPTION,
|
||||
})
|
||||
async getSpacesForUser(
|
||||
@Param() params: UserParamDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.userSpaceService.getSpacesForUser(params.userUuid);
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './user.service';
|
||||
export * from './user-community.service';
|
||||
export * from './user-space.service';
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
|
||||
@Injectable()
|
||||
export class UserSpaceService {
|
||||
constructor(private readonly userSpaceRepository: UserSpaceRepository) {}
|
||||
|
||||
async getSpacesForUser(userUuid: string): Promise<BaseResponseDto> {
|
||||
const userSpaces = await this.userSpaceRepository.find({
|
||||
where: { user: { uuid: userUuid } },
|
||||
relations: ['space'],
|
||||
});
|
||||
|
||||
if (!userSpaces || userSpaces.length === 0) {
|
||||
throw new HttpException(
|
||||
`No spaces found for user with ID ${userUuid}`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
const spaces = userSpaces.map((userSpace) => userSpace.space);
|
||||
|
||||
return new SuccessResponseDto({
|
||||
data: spaces,
|
||||
message: `Spaces for user ${userUuid} retrieved successfully`,
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user