mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
api endpoints for space user controller base root has been mapped from project
This commit is contained in:
@ -193,7 +193,7 @@ export class ControllerRoute {
|
||||
|
||||
static SPACE_USER = class {
|
||||
public static readonly ROUTE =
|
||||
'/communities/:communityUuid/spaces/:spaceUuid/user';
|
||||
'/projects/:projectUuid/communities/:communityUuid/spaces/:spaceUuid/user';
|
||||
static ACTIONS = class {
|
||||
public static readonly ASSOCIATE_SPACE_USER_SUMMARY =
|
||||
'Associate a user to a space';
|
||||
|
@ -26,10 +26,7 @@ export class SpaceUserController {
|
||||
async associateUserToSpace(
|
||||
@Param() params: UserSpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.spaceUserService.associateUserToSpace(
|
||||
params.userUuid,
|
||||
params.spaceUuid,
|
||||
);
|
||||
return this.spaceUserService.associateUserToSpace(params);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@ -43,9 +40,6 @@ export class SpaceUserController {
|
||||
async disassociateUserFromSpace(
|
||||
@Param() params: UserSpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.spaceUserService.disassociateUserFromSpace(
|
||||
params.userUuid,
|
||||
params.spaceUuid,
|
||||
);
|
||||
return this.spaceUserService.disassociateUserFromSpace(params);
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ import {
|
||||
UserSpaceRepository,
|
||||
} from '@app/common/modules/user/repositories';
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { SpaceService } from './space.service';
|
||||
import { UserSpaceParam } from '../dtos';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceUserService {
|
||||
@ -13,11 +15,10 @@ export class SpaceUserService {
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly userRepository: UserRepository,
|
||||
private readonly userSpaceRepository: UserSpaceRepository,
|
||||
private readonly spaceService: SpaceService,
|
||||
) {}
|
||||
async associateUserToSpace(
|
||||
userUuid: string,
|
||||
spaceUuid: string,
|
||||
): Promise<BaseResponseDto> {
|
||||
async associateUserToSpace(params: UserSpaceParam): Promise<BaseResponseDto> {
|
||||
const { communityUuid, spaceUuid, userUuid, projectUuid } = params;
|
||||
// Find the user by ID
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { uuid: userUuid },
|
||||
@ -30,15 +31,11 @@ export class SpaceUserService {
|
||||
}
|
||||
|
||||
// Find the space by ID
|
||||
const space = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid },
|
||||
});
|
||||
if (!space) {
|
||||
throw new HttpException(
|
||||
`Space with ID ${spaceUuid} not found`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
const space = await this.spaceService.validateCommunityAndSpace(
|
||||
communityUuid,
|
||||
spaceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
// Check if the association already exists
|
||||
const existingAssociation = await this.userSpaceRepository.findOne({
|
||||
@ -61,9 +58,9 @@ export class SpaceUserService {
|
||||
}
|
||||
|
||||
async disassociateUserFromSpace(
|
||||
userUuid: string,
|
||||
spaceUuid: string,
|
||||
params: UserSpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { userUuid, spaceUuid, communityUuid, projectUuid } = params;
|
||||
// Find the user by ID
|
||||
const user = await this.userRepository.findOne({
|
||||
where: { uuid: userUuid },
|
||||
@ -76,15 +73,11 @@ export class SpaceUserService {
|
||||
}
|
||||
|
||||
// Find the space by ID
|
||||
const space = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid },
|
||||
});
|
||||
if (!space) {
|
||||
throw new HttpException(
|
||||
`Space with ID ${spaceUuid} not found`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
await this.spaceService.validateCommunityAndSpace(
|
||||
communityUuid,
|
||||
spaceUuid,
|
||||
projectUuid,
|
||||
);
|
||||
|
||||
// Find the existing association
|
||||
const existingAssociation = await this.userSpaceRepository.findOne({
|
||||
|
Reference in New Issue
Block a user