linking dto

This commit is contained in:
hannathkadher
2025-02-26 15:39:23 +04:00
parent 4326ac1900
commit 25f5c62ecf
5 changed files with 71 additions and 2 deletions
@@ -3,11 +3,15 @@ import {
SpaceModelRepository,
} from '@app/common/modules/space-model';
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
import { CreateSpaceModelDto, UpdateSpaceModelDto } from '../dtos';
import {
CreateSpaceModelDto,
LinkSpacesToModelDto,
UpdateSpaceModelDto,
} from '../dtos';
import { ProjectParam } from 'src/community/dtos';
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
import { SubSpaceModelService } from './subspace/subspace-model.service';
import { DataSource, QueryRunner } from 'typeorm';
import { DataSource, In, QueryRunner } from 'typeorm';
import {
TypeORMCustomModel,
TypeORMCustomModelFindAllQuery,
@@ -23,6 +27,7 @@ import { SpaceModelDto } from '@app/common/modules/space-model/dtos';
import { TagService as NewTagService } from 'src/tags/services';
import { ProcessTagDto } from 'src/tags/dtos';
import { SpaceModelProductAllocationService } from './space-model-product-allocation.service';
import { SpaceRepository } from '@app/common/modules/space';
@Injectable()
export class SpaceModelService {
@@ -35,6 +40,7 @@ export class SpaceModelService {
private commandBus: CommandBus,
private readonly tagService: NewTagService,
private readonly spaceModelProductAllocationService: SpaceModelProductAllocationService,
private readonly spaceRepository: SpaceRepository,
) {}
async createSpaceModel(
@@ -408,4 +414,34 @@ export class SpaceModelService {
}
}
}
async linkSpacesToModel(params: SpaceModelParam, dto: LinkSpacesToModelDto) {
await this.validateProject(params.projectUuid);
const spaceModel = await this.validateSpaceModel(params.spaceModelUuid);
const spaces = await this.spaceRepository.find({
where: { uuid: In(dto.spaceUuids) },
relations: [
'spaceModel',
'devices',
'subspaces',
'productAllocations',
'subspace.productAllocations',
],
});
if (!spaces.length) {
throw new HttpException(
`No spaces found for the given UUIDs`,
HttpStatus.NOT_FOUND,
);
}
for (const space of spaces) {
const hasDependencies =
space.devices.length > 0 ||
space.subspaces.length > 0 ||
space.productAllocations.length > 0;
}
}
}