mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
added space link entity
This commit is contained in:
@ -1,4 +1,7 @@
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
SpaceLinkRepository,
|
||||
SpaceRepository,
|
||||
} from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
BadRequestException,
|
||||
HttpException,
|
||||
@ -16,6 +19,7 @@ import { generateRandomString } from '@app/common/helper/randomString';
|
||||
export class SpaceService {
|
||||
constructor(
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly spaceLinkRepository: SpaceLinkRepository,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
) {}
|
||||
|
||||
@ -25,7 +29,7 @@ export class SpaceService {
|
||||
): Promise<BaseResponseDto> {
|
||||
let parent: SpaceEntity | null = null;
|
||||
|
||||
const { parentUuid } = addSpaceDto;
|
||||
const { parentUuid, direction } = addSpaceDto;
|
||||
const community = await this.communityRepository.findOne({
|
||||
where: { uuid: communityId },
|
||||
});
|
||||
@ -60,6 +64,16 @@ export class SpaceService {
|
||||
|
||||
await this.spaceRepository.save(newSpace);
|
||||
|
||||
if (direction && parent) {
|
||||
const spaceLink = await this.spaceLinkRepository.create({
|
||||
direction,
|
||||
endSpace: newSpace,
|
||||
startSpace: parent,
|
||||
});
|
||||
|
||||
await this.spaceLinkRepository.save(spaceLink);
|
||||
}
|
||||
|
||||
return new SuccessResponseDto({
|
||||
statusCode: HttpStatus.CREATED,
|
||||
data: newSpace,
|
||||
@ -88,7 +102,7 @@ export class SpaceService {
|
||||
// Get all spaces related to the community, including the parent-child relations
|
||||
const spaces = await this.spaceRepository.find({
|
||||
where: { community: { uuid: communityUuid } },
|
||||
relations: ['parent', 'children'], // Include parent and children relations
|
||||
relations: ['parent', 'children', 'incomingConnections'], // Include parent and children relations
|
||||
});
|
||||
|
||||
// Organize spaces into a hierarchical structure
|
||||
|
||||
Reference in New Issue
Block a user