Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ export class CommonToolDeleteService {
externalTool: ExternalTool,
schoolExternalTool: SchoolExternalTool
): Promise<void> {
await this.schoolExternalToolRepo.deleteById(schoolExternalTool.id);

const contextExternalTools: ContextExternalTool[] = await this.contextExternalToolRepo.find({
schoolToolRef: { schoolToolId: schoolExternalTool.id },
});

// we have to wait with deleting the school external tool until the context external tools are populated,
// otherwise the context external tools won't be found due to the missing reference
await this.schoolExternalToolRepo.deleteById(schoolExternalTool.id);

const promises: Promise<void>[] = contextExternalTools.map(async (contextExternalTool) => {
await this.deleteContextExternalToolInternal(externalTool, contextExternalTool);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('CourseExternalToolScope', () => {

scope.bySchoolToolId(schoolExternalToolEntity.id);

expect(scope.query).toEqual({ schoolTool: schoolExternalToolEntity.id });
expect(scope.query).toEqual({ schoolTool: new ObjectId(schoolExternalToolEntity.id) });
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class ContextExternalToolScope extends Scope<ContextExternalToolEntity> {

public bySchoolToolId(schoolToolId: EntityId | undefined): ContextExternalToolScope {
if (schoolToolId !== undefined) {
this.addQuery({ schoolTool: schoolToolId });
this.addQuery({ schoolTool: new ObjectId(schoolToolId) });
}
return this;
}
Expand Down
Loading