Skip to content

Commit

Permalink
Merge branch 'main' into EW-1029
Browse files Browse the repository at this point in the history
  • Loading branch information
psachmann authored Oct 22, 2024
2 parents d2f2e2f + e98150b commit bd8401d
Show file tree
Hide file tree
Showing 4 changed files with 452 additions and 239 deletions.
1 change: 1 addition & 0 deletions apps/server/src/modules/board/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export {
UserWithBoardRoles,
isCard,
isColumn,
isColumnBoard,
isDrawingElement,
isLinkElement,
isRichTextElement,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Injectable } from '@nestjs/common';
import { CourseService } from '@modules/learnroom';
import { type AnyBoardNode, BoardExternalReferenceType, BoardNodeService, isColumnBoard } from '@modules/board';
import { Group, GroupService } from '@modules/group';
import { CourseService } from '@modules/learnroom';
import { Injectable } from '@nestjs/common';
import { Course } from '@shared/domain/entity';
import { ToolContextType } from '../../../common/enum';
import { ContextExternalToolLaunchable } from '../../../context-external-tool/domain';
Expand All @@ -9,28 +10,46 @@ import { AutoParameterStrategy } from './auto-parameter.strategy';

@Injectable()
export class AutoGroupExternalUuidStrategy implements AutoParameterStrategy {
constructor(private readonly courseService: CourseService, private readonly groupService: GroupService) {}
constructor(
private readonly courseService: CourseService,
private readonly groupService: GroupService,
private readonly boardNodeService: BoardNodeService
) {}

async getValue(
_schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalToolLaunchable
): Promise<string | undefined> {
if (contextExternalTool.contextRef.type !== ToolContextType.COURSE) {
return undefined;
switch (contextExternalTool.contextRef.type) {
case ToolContextType.BOARD_ELEMENT: {
const boardElement: AnyBoardNode = await this.boardNodeService.findById(contextExternalTool.contextRef.id);
const board: AnyBoardNode = await this.boardNodeService.findRoot(boardElement);

if (!isColumnBoard(board) || board.context.type !== BoardExternalReferenceType.Course) {
return undefined;
}

const uuid: string | undefined = await this.getExternalUuidFromCourse(board.context.id);

return uuid;
}
case ToolContextType.COURSE: {
const uuid: string | undefined = await this.getExternalUuidFromCourse(contextExternalTool.contextRef.id);

return uuid;
}
default: {
return undefined;
}
}
}

const courseId = contextExternalTool.contextRef.id;
private async getExternalUuidFromCourse(courseId: string): Promise<string | undefined> {
const course: Course = await this.courseService.findById(courseId);

const syncedGroup: Group | undefined = await this.getSyncedGroup(course);
if (!syncedGroup) {
return undefined;
}

const groupUuid = syncedGroup.externalSource?.externalId;
if (!groupUuid) {
return undefined;
}
const groupUuid = syncedGroup?.externalSource?.externalId;

return groupUuid;
}
Expand All @@ -42,6 +61,7 @@ export class AutoGroupExternalUuidStrategy implements AutoParameterStrategy {
}

const syncedGroup = await this.groupService.findById(syncedGroupId);

return syncedGroup;
}
}
Loading

0 comments on commit bd8401d

Please sign in to comment.