diff --git a/src/space/services/space.service.ts b/src/space/services/space.service.ts index 59aceb5..df0b0a4 100644 --- a/src/space/services/space.service.ts +++ b/src/space/services/space.service.ts @@ -20,8 +20,9 @@ import { SpaceLinkService } from './space-link'; import { SpaceProductService } from './space-products'; import { CreateSubspaceModelDto } from 'src/space-model/dtos'; import { SubSpaceService } from './subspace'; -import { DataSource } from 'typeorm'; +import { DataSource, Not } from 'typeorm'; import { ValidationService } from './space-validation.service'; +import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant'; @Injectable() export class SpaceService { @@ -42,6 +43,13 @@ export class SpaceService { addSpaceDto; const { communityUuid, projectUuid } = params; + if (addSpaceDto.spaceName === ORPHAN_SPACE_NAME) { + throw new HttpException( + `Name ${ORPHAN_SPACE_NAME} cannot be used`, + HttpStatus.BAD_REQUEST, + ); + } + const queryRunner = this.dataSource.createQueryRunner(); await queryRunner.connect(); @@ -137,7 +145,10 @@ export class SpaceService { try { // Get all spaces related to the community, including the parent-child relations const spaces = await this.spaceRepository.find({ - where: { community: { uuid: communityUuid } }, + where: { + community: { uuid: communityUuid }, + spaceName: Not(`${ORPHAN_SPACE_NAME}`), + }, relations: [ 'parent', 'children', @@ -200,6 +211,12 @@ export class SpaceService { spaceUuid, ); + if (space.spaceName === ORPHAN_SPACE_NAME) { + throw new HttpException( + `space ${ORPHAN_SPACE_NAME} cannot be deleted`, + HttpStatus.BAD_REQUEST, + ); + } // Delete the space await this.spaceRepository.remove(space); @@ -236,6 +253,13 @@ export class SpaceService { spaceUuid, ); + if (space.spaceName === ORPHAN_SPACE_NAME) { + throw new HttpException( + `space ${ORPHAN_SPACE_NAME} cannot be updated`, + HttpStatus.BAD_REQUEST, + ); + } + // If a parentId is provided, check if the parent exists const { parentUuid, products } = updateSpaceDto; const parent = parentUuid