add validation to check both space model and products, subspaces are not created

This commit is contained in:
hannathkadher
2024-12-11 17:01:23 +04:00
parent a2ee7a0001
commit 8af29cddfd
2 changed files with 40 additions and 2 deletions

View File

@ -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,
);
}
}
}