fixed the heirarchy device fetching issue

This commit is contained in:
hannathkadher
2025-02-20 13:29:19 +04:00
parent c2a6012063
commit a0790f0b48
3 changed files with 64 additions and 5 deletions

View File

@ -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,
);
}
}
}