mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 09:54:55 +00:00
added constrains for orphan space in services
This commit is contained in:
@ -20,8 +20,9 @@ import { SpaceLinkService } from './space-link';
|
|||||||
import { SpaceProductService } from './space-products';
|
import { SpaceProductService } from './space-products';
|
||||||
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
|
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
|
||||||
import { SubSpaceService } from './subspace';
|
import { SubSpaceService } from './subspace';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource, Not } from 'typeorm';
|
||||||
import { ValidationService } from './space-validation.service';
|
import { ValidationService } from './space-validation.service';
|
||||||
|
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SpaceService {
|
export class SpaceService {
|
||||||
@ -42,6 +43,13 @@ export class SpaceService {
|
|||||||
addSpaceDto;
|
addSpaceDto;
|
||||||
const { communityUuid, projectUuid } = params;
|
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();
|
const queryRunner = this.dataSource.createQueryRunner();
|
||||||
|
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
@ -137,7 +145,10 @@ export class SpaceService {
|
|||||||
try {
|
try {
|
||||||
// Get all spaces related to the community, including the parent-child relations
|
// Get all spaces related to the community, including the parent-child relations
|
||||||
const spaces = await this.spaceRepository.find({
|
const spaces = await this.spaceRepository.find({
|
||||||
where: { community: { uuid: communityUuid } },
|
where: {
|
||||||
|
community: { uuid: communityUuid },
|
||||||
|
spaceName: Not(`${ORPHAN_SPACE_NAME}`),
|
||||||
|
},
|
||||||
relations: [
|
relations: [
|
||||||
'parent',
|
'parent',
|
||||||
'children',
|
'children',
|
||||||
@ -200,6 +211,12 @@ export class SpaceService {
|
|||||||
spaceUuid,
|
spaceUuid,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (space.spaceName === ORPHAN_SPACE_NAME) {
|
||||||
|
throw new HttpException(
|
||||||
|
`space ${ORPHAN_SPACE_NAME} cannot be deleted`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
// Delete the space
|
// Delete the space
|
||||||
await this.spaceRepository.remove(space);
|
await this.spaceRepository.remove(space);
|
||||||
|
|
||||||
@ -236,6 +253,13 @@ export class SpaceService {
|
|||||||
spaceUuid,
|
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
|
// If a parentId is provided, check if the parent exists
|
||||||
const { parentUuid, products } = updateSpaceDto;
|
const { parentUuid, products } = updateSpaceDto;
|
||||||
const parent = parentUuid
|
const parent = parentUuid
|
||||||
|
|||||||
Reference in New Issue
Block a user