filter disable get space models in get query

This commit is contained in:
hannathkadher
2025-01-22 12:03:53 +04:00
parent 414495c7fe
commit 3ee2e66e39

View File

@ -159,8 +159,6 @@ export class SpaceModelService {
queryBuilder, queryBuilder,
); );
console.log(baseResponseDto);
return new PageResponse<SpaceModelDto>( return new PageResponse<SpaceModelDto>(
baseResponseDto, baseResponseDto,
paginationResponseDto, paginationResponseDto,
@ -344,35 +342,51 @@ export class SpaceModelService {
try { try {
await this.validateProject(params.projectUuid); await this.validateProject(params.projectUuid);
const spaceModel = await this.validateSpaceModel(params.spaceModelUuid); const spaceModel = await this.validateSpaceModel(params.spaceModelUuid);
return new SuccessResponseDto({ return new SuccessResponseDto({
message: 'SpaceModel retrieved successfully', message: 'SpaceModel retrieved successfully',
data: spaceModel, data: spaceModel,
}); });
} catch (error) { } catch (error) {
throw new HttpException( throw new HttpException(
`Failed to retrieve space model ${error}`, `Failed to retrieve space model: ${error.message}`,
HttpStatus.INTERNAL_SERVER_ERROR, HttpStatus.INTERNAL_SERVER_ERROR,
); );
} }
} }
async validateSpaceModel(uuid: string): Promise<SpaceModelEntity> { async validateSpaceModel(uuid: string): Promise<SpaceModelEntity> {
const spaceModel = await this.spaceModelRepository.findOne({ const spaceModel = await this.spaceModelRepository
where: { .createQueryBuilder('spaceModel')
uuid, .leftJoinAndSelect(
disabled: false, 'spaceModel.subspaceModels',
},
relations: [
'subspaceModels', 'subspaceModels',
'subspaceModels.disabled = :subspaceDisabled',
{ subspaceDisabled: false },
)
.leftJoinAndSelect(
'spaceModel.tags',
'tags', 'tags',
'tags.product', 'tags.disabled = :tagsDisabled',
{ tagsDisabled: false },
)
.leftJoinAndSelect('tags.product', 'spaceTagproduct')
.leftJoinAndSelect(
'subspaceModels.tags', 'subspaceModels.tags',
'subspaceModels.tags.product', 'subspaceModelTags',
], 'subspaceModelTags.disabled = :subspaceModelTagsDisabled',
}); { subspaceModelTagsDisabled: false },
)
.leftJoinAndSelect('subspaceModelTags.product', 'subspaceTagproduct')
.where('spaceModel.disabled = :disabled', { disabled: false })
.where('spaceModel.disabled = :disabled', { disabled: false })
.andWhere('spaceModel.uuid = :uuid', { uuid })
.getOne();
if (!spaceModel) { if (!spaceModel) {
throw new HttpException('space model not found', HttpStatus.NOT_FOUND); throw new HttpException('space model not found', HttpStatus.NOT_FOUND);
} }
return spaceModel; return spaceModel;
} }
} }