api endpoints for space user controller base root has been mapped from project

This commit is contained in:
hannathkadher
2024-12-09 17:44:22 +04:00
parent bb031dd15b
commit dade201752
3 changed files with 20 additions and 33 deletions

View File

@ -193,7 +193,7 @@ export class ControllerRoute {
static SPACE_USER = class { static SPACE_USER = class {
public static readonly ROUTE = public static readonly ROUTE =
'/communities/:communityUuid/spaces/:spaceUuid/user'; '/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/user';
static ACTIONS = class { static ACTIONS = class {
public static readonly ASSOCIATE_SPACE_USER_SUMMARY = public static readonly ASSOCIATE_SPACE_USER_SUMMARY =
'Associate a user to a space'; 'Associate a user to a space';

View File

@ -26,10 +26,7 @@ export class SpaceUserController {
async associateUserToSpace( async associateUserToSpace(
@Param() params: UserSpaceParam, @Param() params: UserSpaceParam,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
return this.spaceUserService.associateUserToSpace( return this.spaceUserService.associateUserToSpace(params);
params.userUuid,
params.spaceUuid,
);
} }
@ApiBearerAuth() @ApiBearerAuth()
@ -43,9 +40,6 @@ export class SpaceUserController {
async disassociateUserFromSpace( async disassociateUserFromSpace(
@Param() params: UserSpaceParam, @Param() params: UserSpaceParam,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
return this.spaceUserService.disassociateUserFromSpace( return this.spaceUserService.disassociateUserFromSpace(params);
params.userUuid,
params.spaceUuid,
);
} }
} }

View File

@ -6,6 +6,8 @@ import {
UserSpaceRepository, UserSpaceRepository,
} from '@app/common/modules/user/repositories'; } from '@app/common/modules/user/repositories';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { SpaceService } from './space.service';
import { UserSpaceParam } from '../dtos';
@Injectable() @Injectable()
export class SpaceUserService { export class SpaceUserService {
@ -13,11 +15,10 @@ export class SpaceUserService {
private readonly spaceRepository: SpaceRepository, private readonly spaceRepository: SpaceRepository,
private readonly userRepository: UserRepository, private readonly userRepository: UserRepository,
private readonly userSpaceRepository: UserSpaceRepository, private readonly userSpaceRepository: UserSpaceRepository,
private readonly spaceService: SpaceService,
) {} ) {}
async associateUserToSpace( async associateUserToSpace(params: UserSpaceParam): Promise<BaseResponseDto> {
userUuid: string, const { communityUuid, spaceUuid, userUuid, projectUuid } = params;
spaceUuid: string,
): Promise<BaseResponseDto> {
// Find the user by ID // Find the user by ID
const user = await this.userRepository.findOne({ const user = await this.userRepository.findOne({
where: { uuid: userUuid }, where: { uuid: userUuid },
@ -30,15 +31,11 @@ export class SpaceUserService {
} }
// Find the space by ID // Find the space by ID
const space = await this.spaceRepository.findOne({ const space = await this.spaceService.validateCommunityAndSpace(
where: { uuid: spaceUuid }, communityUuid,
}); spaceUuid,
if (!space) { projectUuid,
throw new HttpException(
`Space with ID ${spaceUuid} not found`,
HttpStatus.NOT_FOUND,
); );
}
// Check if the association already exists // Check if the association already exists
const existingAssociation = await this.userSpaceRepository.findOne({ const existingAssociation = await this.userSpaceRepository.findOne({
@ -61,9 +58,9 @@ export class SpaceUserService {
} }
async disassociateUserFromSpace( async disassociateUserFromSpace(
userUuid: string, params: UserSpaceParam,
spaceUuid: string,
): Promise<BaseResponseDto> { ): Promise<BaseResponseDto> {
const { userUuid, spaceUuid, communityUuid, projectUuid } = params;
// Find the user by ID // Find the user by ID
const user = await this.userRepository.findOne({ const user = await this.userRepository.findOne({
where: { uuid: userUuid }, where: { uuid: userUuid },
@ -76,15 +73,11 @@ export class SpaceUserService {
} }
// Find the space by ID // Find the space by ID
const space = await this.spaceRepository.findOne({ await this.spaceService.validateCommunityAndSpace(
where: { uuid: spaceUuid }, communityUuid,
}); spaceUuid,
if (!space) { projectUuid,
throw new HttpException(
`Space with ID ${spaceUuid} not found`,
HttpStatus.NOT_FOUND,
); );
}
// Find the existing association // Find the existing association
const existingAssociation = await this.userSpaceRepository.findOne({ const existingAssociation = await this.userSpaceRepository.findOne({