Merge branch 'dev' into feat/project-tag

This commit is contained in:
hannathkadher
2025-03-02 00:22:28 +04:00
26 changed files with 320 additions and 88 deletions
+3 -3
View File
@@ -32,10 +32,10 @@ export class SpaceDeviceService {
);
}
// Fetch space hierarchy **once** and reverse it to get an ordered hierarchy
const spaceHierarchy =
await this.validationService.getFullSpaceHierarchy(space);
const orderedHierarchy = spaceHierarchy.reverse();
await this.validationService.getParentHierarchy(space);
const orderedHierarchy = [space, ...spaceHierarchy.reverse()];
// Fetch Tuya details for each device in parallel using Promise.allSettled
const deviceDetailsPromises = space.devices.map((device) =>
@@ -222,4 +222,32 @@ export class ValidationService {
return descendants;
}
async getParentHierarchy(
space: SpaceEntity,
): Promise<{ uuid: string; spaceName: string }[]> {
try {
const targetSpace = await this.spaceRepository.findOne({
where: { uuid: space.uuid },
relations: ['parent'],
});
if (!targetSpace) {
throw new HttpException('Space not found', HttpStatus.NOT_FOUND);
}
const ancestors = await this.fetchAncestors(targetSpace);
return ancestors.map((parentSpace) => ({
uuid: parentSpace.uuid,
spaceName: parentSpace.spaceName,
}));
} catch (error) {
console.error('Error fetching parent hierarchy:', error.message);
throw new HttpException(
'Error fetching parent hierarchy',
HttpStatus.INTERNAL_SERVER_ERROR,
);
}
}
}
@@ -84,7 +84,7 @@ export class SubspaceDeviceService {
if (device.tag?.subspace?.uuid !== subspace.uuid) {
await this.tagRepository.update(
{ uuid: device.tag.uuid },
{ subspace },
{ subspace, space: null },
);
}