added space link entity

This commit is contained in:
hannathkadher
2024-11-20 09:11:22 +04:00
parent 891129e7e3
commit 857b02b97b
10 changed files with 102 additions and 5 deletions

View File

@ -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