update in tag service

This commit is contained in:
hannathkadher
2024-12-24 11:33:58 +04:00
parent 1e47fffc0a
commit cb2778dce5
22 changed files with 705 additions and 117 deletions

View File

@ -16,11 +16,11 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
import { SpaceEntity } from '@app/common/modules/space/entities';
import { generateRandomString } from '@app/common/helper/randomString';
import { SpaceLinkService } from './space-link';
import { CreateSubspaceModelDto } from 'src/space-model/dtos';
import { SubSpaceService } from './subspace';
import { DataSource, Not } from 'typeorm';
import { ValidationService } from './space-validation.service';
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
import { TagService } from './tag';
@Injectable()
export class SpaceService {
@ -30,13 +30,15 @@ export class SpaceService {
private readonly spaceLinkService: SpaceLinkService,
private readonly subSpaceService: SubSpaceService,
private readonly validationService: ValidationService,
private readonly tagService: TagService,
) {}
async createSpace(
addSpaceDto: AddSpaceDto,
params: CommunitySpaceParam,
): Promise<BaseResponseDto> {
const { parentUuid, direction, spaceModelUuid, subspaces } = addSpaceDto;
const { parentUuid, direction, spaceModelUuid, subspaces, tags } =
addSpaceDto;
const { communityUuid, projectUuid } = params;
if (addSpaceDto.spaceName === ORPHAN_SPACE_NAME) {
@ -67,14 +69,14 @@ export class SpaceService {
: null;
try {
const newSpace = queryRunner.manager.create(SpaceEntity, {
const space = queryRunner.manager.create(SpaceEntity, {
...addSpaceDto,
spaceModel,
parent: parentUuid ? parent : null,
community,
});
await queryRunner.manager.save(newSpace);
const newSpace = await queryRunner.manager.save(space);
if (direction && parent) {
await this.spaceLinkService.saveSpaceLink(
@ -90,11 +92,14 @@ export class SpaceService {
newSpace,
queryRunner,
);
} else if (spaceModel && spaceModel.subspaceModels.length) {
await this.subSpaceService.createSubSpaceFromModel(
spaceModel,
newSpace,
}
if (tags?.length) {
newSpace.tags = await this.tagService.createTags(
tags,
queryRunner,
newSpace,
null,
);
}
@ -242,19 +247,32 @@ export class SpaceService {
HttpStatus.BAD_REQUEST,
);
}
if (updateSpaceDto.spaceName) space.spaceName = updateSpaceDto.spaceName;
// If a parentId is provided, check if the parent exists
const { parentUuid } = updateSpaceDto;
const parent = parentUuid
? await this.validationService.validateSpace(parentUuid)
: null;
if (updateSpaceDto.x) space.x = updateSpaceDto.x;
// Update other space properties from updateSpaceDto
Object.assign(space, updateSpaceDto, { parent });
if (updateSpaceDto.y) space.y = updateSpaceDto.y;
if (updateSpaceDto.icon) space.icon = updateSpaceDto.icon;
if (updateSpaceDto.icon) space.icon = updateSpaceDto.icon;
// Save the updated space
await queryRunner.manager.save(space);
if (updateSpaceDto.subspaceModels) {
await this.subSpaceService.modifySubSpace(
updateSpaceDto.subspaceModels,
space,
queryRunner,
);
}
if (updateSpaceDto.tags) {
await this.tagService.modifyTags(
updateSpaceDto.tags,
queryRunner,
space,
);
}
await queryRunner.commitTransaction();
return new SuccessResponseDto({