Skip to content

Commit

Permalink
added new auto param strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
GordonNicholasCap committed Jul 31, 2024
1 parent c8fbf70 commit 53d4461
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable } from '@nestjs/common';
import { CourseService } from '@modules/learnroom';
import { ToolContextType } from '../../../common/enum';
import { MissingToolParameterValueLoggableException } from '../../error';
import { ContextExternalToolLaunchable } from '../../../context-external-tool/domain';
import { SchoolExternalTool } from '../../../school-external-tool/domain';
import { AutoParameterStrategy } from './auto-parameter.strategy';

@Injectable()
export class AutoMoinSchuleGroupUuidStrategy implements AutoParameterStrategy {
constructor(private readonly courseService: CourseService) {}

async getValue(
_schoolExternalTool: SchoolExternalTool,
contextExternalTool: ContextExternalToolLaunchable
): Promise<string | undefined> {
if (contextExternalTool.contextRef.type !== ToolContextType.COURSE) {
return undefined;
}

const courseId = contextExternalTool.contextRef.id;
const courseEntity = await this.courseService.findById(courseId);
const syncedGroup = courseEntity.syncedWithGroup;

if (!syncedGroup) {
return undefined;
}

const uuid = syncedGroup.externalSource?.externalId;

if (!uuid) {
// TODO: think if a new special error is needed for this case
throw new MissingToolParameterValueLoggableException(contextExternalTool, []);
}

return uuid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export * from './auto-school-id.strategy';
export * from './auto-context-id.strategy';
export * from './auto-context-name.strategy';
export * from './auto-school-number.strategy';
export * from './auto-moin-schule-group-uuid.strategy';
export { AutoMediumIdStrategy } from './auto-medium-id.strategy';
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
AutoParameterStrategy,
AutoSchoolIdStrategy,
AutoSchoolNumberStrategy,
AutoMoinSchuleGroupUuidStrategy,
} from '../auto-parameter-strategy';
import { ToolLaunchParams } from './tool-launch-params.interface';
import { ToolLaunchStrategy } from './tool-launch-strategy.interface';
Expand All @@ -29,14 +30,16 @@ export abstract class AbstractLaunchStrategy implements ToolLaunchStrategy {
autoSchoolNumberStrategy: AutoSchoolNumberStrategy,
autoContextIdStrategy: AutoContextIdStrategy,
autoContextNameStrategy: AutoContextNameStrategy,
autoMediumIdStrategy: AutoMediumIdStrategy
autoMediumIdStrategy: AutoMediumIdStrategy,
autoMoinSchuleGroupUuidStrategy: AutoMoinSchuleGroupUuidStrategy
) {
this.autoParameterStrategyMap = new Map<CustomParameterType, AutoParameterStrategy>([
[CustomParameterType.AUTO_SCHOOLID, autoSchoolIdStrategy],
[CustomParameterType.AUTO_SCHOOLNUMBER, autoSchoolNumberStrategy],
[CustomParameterType.AUTO_CONTEXTID, autoContextIdStrategy],
[CustomParameterType.AUTO_CONTEXTNAME, autoContextNameStrategy],
[CustomParameterType.AUTO_MEDIUMID, autoMediumIdStrategy],
[CustomParameterType.AUTO_MOINSCHULE_GROUPUUID, autoMoinSchuleGroupUuidStrategy],
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
AutoMediumIdStrategy,
AutoSchoolIdStrategy,
AutoSchoolNumberStrategy,
AutoMoinSchuleGroupUuidStrategy,
} from '../auto-parameter-strategy';
import { Lti11EncryptionService } from '../lti11-encryption.service';
import { AbstractLaunchStrategy } from './abstract-launch.strategy';
Expand All @@ -31,14 +32,16 @@ export class Lti11ToolLaunchStrategy extends AbstractLaunchStrategy {
autoSchoolNumberStrategy: AutoSchoolNumberStrategy,
autoContextIdStrategy: AutoContextIdStrategy,
autoContextNameStrategy: AutoContextNameStrategy,
autoMediumIdStrategy: AutoMediumIdStrategy
autoMediumIdStrategy: AutoMediumIdStrategy,
autoMoinSchuleGroupUuidStrategy: AutoMoinSchuleGroupUuidStrategy
) {
super(
autoSchoolIdStrategy,
autoSchoolNumberStrategy,
autoContextIdStrategy,
autoContextNameStrategy,
autoMediumIdStrategy
autoMediumIdStrategy,
autoMoinSchuleGroupUuidStrategy
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
AutoMediumIdStrategy,
AutoSchoolIdStrategy,
AutoSchoolNumberStrategy,
AutoMoinSchuleGroupUuidStrategy,
} from './service/auto-parameter-strategy';
import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrategy } from './service/launch-strategy';

Expand All @@ -41,6 +42,7 @@ import { BasicToolLaunchStrategy, Lti11ToolLaunchStrategy, OAuth2ToolLaunchStrat
AutoSchoolIdStrategy,
AutoSchoolNumberStrategy,
AutoMediumIdStrategy,
AutoMoinSchuleGroupUuidStrategy,
],
exports: [ToolLaunchService],
})
Expand Down

0 comments on commit 53d4461

Please sign in to comment.