diff --git a/apps/server/src/modules/board/service/content-element.service.ts b/apps/server/src/modules/board/service/content-element.service.ts index b7a6301563d..55063d3604a 100644 --- a/apps/server/src/modules/board/service/content-element.service.ts +++ b/apps/server/src/modules/board/service/content-element.service.ts @@ -40,7 +40,7 @@ export class ContentElementService { return parent; } - async create(parent: Card, type: ContentElementType): Promise { + async create(parent: Card | SubmissionItem, type: ContentElementType): Promise { const element = this.contentElementFactory.build(type, parent.id); parent.addChild(element); await this.boardDoRepo.save(parent.children, parent); diff --git a/apps/server/src/modules/board/uc/element.uc.ts b/apps/server/src/modules/board/uc/element.uc.ts index d094e758fd5..af3c69d0264 100644 --- a/apps/server/src/modules/board/uc/element.uc.ts +++ b/apps/server/src/modules/board/uc/element.uc.ts @@ -1,7 +1,7 @@ import { ForbiddenException, forwardRef, Inject, Injectable, UnprocessableEntityException } from '@nestjs/common'; import { AnyBoardDo, - AnyContentElementDo, + AnyContentElementDo, DrawingElement, EntityId, isSubmissionContainerElement, isSubmissionItem, @@ -14,6 +14,9 @@ import { AnyElementContentBody } from '../controller/dto'; import { BoardDoAuthorizableService, ContentElementService } from '../service'; import { SubmissionItemService } from '../service/submission-item.service'; import { BaseUc } from './base.uc'; +import {firstValueFrom} from "rxjs"; +import {HttpService} from "@nestjs/axios"; +import {Configuration} from "@hpi-schul-cloud/commons/lib"; @Injectable() export class ElementUc extends BaseUc { @@ -23,7 +26,8 @@ export class ElementUc extends BaseUc { protected readonly boardDoAuthorizableService: BoardDoAuthorizableService, private readonly elementService: ContentElementService, private readonly submissionItemService: SubmissionItemService, - private readonly logger: Logger + private readonly logger: Logger, + private readonly httpService: HttpService ) { super(authorizationService, boardDoAuthorizableService); this.logger.setContext(ElementUc.name); @@ -40,10 +44,21 @@ export class ElementUc extends BaseUc { return element; } - async deleteElement(userId: EntityId, elementId: EntityId): Promise { + async deleteElement(userId: EntityId, elementId: EntityId, auth: string): Promise { const element = await this.getElementWithWritePermission(userId, elementId); await this.elementService.delete(element); + + if (element instanceof DrawingElement) { + await firstValueFrom( + this.httpService.delete(`${Configuration.get('TLDRAW_URI') as string}/tldraw-document/${element.drawingName}`, { + headers: { + Accept: 'Application/json', + Authorization: auth, + }, + }) + ); + } } private async getElementWithWritePermission(userId: EntityId, elementId: EntityId): Promise { diff --git a/apps/server/src/modules/tldraw/tldraw.module.ts b/apps/server/src/modules/tldraw/tldraw.module.ts index b4c84eb7201..6b59668c00c 100644 --- a/apps/server/src/modules/tldraw/tldraw.module.ts +++ b/apps/server/src/modules/tldraw/tldraw.module.ts @@ -7,13 +7,13 @@ import { TldrawBoardRepo } from './repo'; import { MikroOrmModule, MikroOrmModuleSyncOptions } from '@mikro-orm/nestjs'; import { TldrawDrawing } from '@src/modules/tldraw/entities'; import { AuthenticationModule } from '@src/modules/authentication/authentication.module'; -import { AuthorizationModule } from '@src/modules'; import { RabbitMQWrapperTestModule } from '@shared/infra/rabbitmq'; import { Dictionary, IPrimaryKey } from '@mikro-orm/core'; import { config } from './config'; import { TldrawController } from './controller/tldraw.controller'; import {TldrawService} from "./service/tldraw.service"; import {TldrawRepo} from "./repo/tldraw.repo"; +import {AuthorizationModule} from "@modules/authorization"; const defaultMikroOrmOptions: MikroOrmModuleSyncOptions = { findOneOrFailHandler: (entityName: string, where: Dictionary | IPrimaryKey) =>