mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
optimizing space call
This commit is contained in:
@ -7,6 +7,8 @@ import {
|
||||
SpaceModelEntity,
|
||||
SpaceModelRepository,
|
||||
} from '@app/common/modules/space-model';
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
|
||||
@Injectable()
|
||||
export class ValidationService {
|
||||
@ -14,6 +16,8 @@ export class ValidationService {
|
||||
private readonly projectService: ProjectService,
|
||||
private readonly communityService: CommunityService,
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly projectRepository: ProjectRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
private readonly spaceModelRepository: SpaceModelRepository,
|
||||
) {}
|
||||
|
||||
@ -30,6 +34,31 @@ export class ValidationService {
|
||||
return { community: community.data, project: project };
|
||||
}
|
||||
|
||||
async checkCommunityAndProjectSpaceExistence(
|
||||
communityUuid: string,
|
||||
projectUuid: string,
|
||||
spaceUuid?: string,
|
||||
): Promise<void> {
|
||||
const [projectExists, communityExists, spaceExists] = await Promise.all([
|
||||
this.projectRepository.exists({ where: { uuid: projectUuid } }),
|
||||
this.communityRepository.exists({
|
||||
where: { uuid: communityUuid, project: { uuid: projectUuid } },
|
||||
}),
|
||||
spaceUuid
|
||||
? this.spaceRepository.exists({
|
||||
where: { uuid: spaceUuid },
|
||||
})
|
||||
: Promise.resolve(true),
|
||||
]);
|
||||
|
||||
if (!projectExists)
|
||||
throw new HttpException(`Project not found`, HttpStatus.NOT_FOUND);
|
||||
if (!communityExists)
|
||||
throw new HttpException(`Community not found`, HttpStatus.NOT_FOUND);
|
||||
if (spaceUuid && !spaceExists)
|
||||
throw new HttpException(`Space not found`, HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
async validateSpaceWithinCommunityAndProject(
|
||||
communityUuid: string,
|
||||
projectUuid: string,
|
||||
@ -50,10 +79,10 @@ export class ValidationService {
|
||||
'tags',
|
||||
'subspaces.tags',
|
||||
'subspaces.devices',
|
||||
'devices',
|
||||
'devices.productDevice',
|
||||
'devices.tag',
|
||||
'devices.subspace',
|
||||
//'devices',
|
||||
//'devices.productDevice',
|
||||
//'devices.tag',
|
||||
// 'devices.subspace',
|
||||
],
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user