Skip to content

Commit

Permalink
Adjust code after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
blazejpass committed Nov 6, 2023
1 parent 31b4f20 commit bcd3cbe
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export class ContentElementService {
return parent;
}

async create(parent: Card, type: ContentElementType): Promise<AnyContentElementDo> {
async create(parent: Card | SubmissionItem, type: ContentElementType): Promise<AnyContentElementDo> {
const element = this.contentElementFactory.build(type, parent.id);
parent.addChild(element);
await this.boardDoRepo.save(parent.children, parent);
Expand Down
21 changes: 18 additions & 3 deletions apps/server/src/modules/board/uc/element.uc.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ForbiddenException, forwardRef, Inject, Injectable, UnprocessableEntityException } from '@nestjs/common';
import {
AnyBoardDo,
AnyContentElementDo,
AnyContentElementDo, DrawingElement,
EntityId,
isSubmissionContainerElement,
isSubmissionItem,
Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -40,10 +44,21 @@ export class ElementUc extends BaseUc {
return element;
}

async deleteElement(userId: EntityId, elementId: EntityId): Promise<void> {
async deleteElement(userId: EntityId, elementId: EntityId, auth: string): Promise<void> {
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<AnyContentElementDo> {
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/modules/tldraw/tldraw.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down

0 comments on commit bcd3cbe

Please sign in to comment.