mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 19:54:54 +00:00
add validation to check both space model and products, subspaces are not created
This commit is contained in:
@ -9,6 +9,7 @@ import {
|
||||
AddSpaceDto,
|
||||
CommunitySpaceParam,
|
||||
GetSpaceParam,
|
||||
ProductAssignmentDto,
|
||||
UpdateSpaceDto,
|
||||
} from '../dtos';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
@ -19,6 +20,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
||||
import { SpaceLinkService } from './space-link';
|
||||
import { SpaceProductService } from './space-products';
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceService {
|
||||
@ -34,11 +36,14 @@ export class SpaceService {
|
||||
addSpaceDto: AddSpaceDto,
|
||||
params: CommunitySpaceParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { parentUuid, direction, products } = addSpaceDto;
|
||||
const { parentUuid, direction, products, spaceModelUuid, subspaces } =
|
||||
addSpaceDto;
|
||||
const { communityUuid, projectUuid } = params;
|
||||
|
||||
await this.validateProject(projectUuid);
|
||||
|
||||
this.validateSpaceCreation(spaceModelUuid, products, subspaces);
|
||||
|
||||
const community = await this.validateCommunity(communityUuid);
|
||||
|
||||
const parent = parentUuid ? await this.validateSpace(parentUuid) : null;
|
||||
@ -344,4 +349,17 @@ export class SpaceService {
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
private validateSpaceCreation(
|
||||
spaceModelUuid?: string,
|
||||
products?: ProductAssignmentDto[],
|
||||
subSpaces?: CreateSubspaceModelDto[],
|
||||
) {
|
||||
if (spaceModelUuid && (products?.length || subSpaces?.length)) {
|
||||
throw new HttpException(
|
||||
'Space model cannot be assigned with products or subspaces.',
|
||||
HttpStatus.CONFLICT,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user