Skip to content

Commit

Permalink
add contextRestriction to uc
Browse files Browse the repository at this point in the history
  • Loading branch information
MBergCap committed Sep 25, 2024
1 parent d61ab13 commit a33ac08
Showing 1 changed file with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { CommonToolMetadataService } from '../../common/service/common-tool-meta
import { SchoolExternalTool, SchoolExternalToolMetadata, SchoolExternalToolProps } from '../domain';
import { SchoolExternalToolService, SchoolExternalToolValidationService } from '../service';
import { SchoolExternalToolQueryInput } from './dto/school-external-tool.types';
import { ExternalToolService } from '@modules/tool';
import { ExternalTool } from '@modules/tool/external-tool/domain';

@Injectable()
export class SchoolExternalToolUc {
Expand All @@ -16,14 +18,17 @@ export class SchoolExternalToolUc {
private readonly schoolExternalToolValidationService: SchoolExternalToolValidationService,
private readonly commonToolMetadataService: CommonToolMetadataService,
@Inject(forwardRef(() => AuthorizationService)) private readonly authorizationService: AuthorizationService,
private readonly schoolService: SchoolService
private readonly schoolService: SchoolService,
private readonly externalToolService: ExternalToolService
) {}

async findSchoolExternalTools(userId: EntityId, query: SchoolExternalToolQueryInput): Promise<SchoolExternalTool[]> {
let tools: SchoolExternalTool[] = [];
if (query.schoolId) {
tools = await this.schoolExternalToolService.findSchoolExternalTools({ schoolId: query.schoolId });

tools = await this.getContextRestrictions(tools);

const user: User = await this.authorizationService.getUserWithPermissions(userId);
const school: School = await this.schoolService.getSchoolById(query.schoolId);

Expand All @@ -35,6 +40,16 @@ export class SchoolExternalToolUc {
return tools;
}

private async getContextRestrictions(tools: SchoolExternalTool[]): Promise<SchoolExternalTool[]> {
const schoolExternalTools = tools.map(async tool => {
const externalTool: ExternalTool = await this.externalToolService.findById(tool.toolId)
tool.restrictToContexts = externalTool.restrictToContexts;
return tool;
})

return Promise.all(schoolExternalTools)
}

async createSchoolExternalTool(
userId: EntityId,
schoolExternalToolDto: SchoolExternalToolProps
Expand Down

0 comments on commit a33ac08

Please sign in to comment.