mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-25 16:47:55 +00:00
space management without roles
This commit is contained in:
@@ -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