space management without roles

This commit is contained in:
hannathkadher
2024-10-21 09:47:52 +04:00
parent 96d52962aa
commit f8c011f9dc
15 changed files with 417 additions and 31 deletions
+1
View File
@@ -1,2 +1,3 @@
export * from './user.service';
export * from './user-community.service';
export * from './user-space.service';
+30
View File
@@ -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`,
});
}
}