Skip to content

Commit cf26560

Browse files
committed
fix deletion order
1 parent 45233ac commit cf26560

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

apps/server/src/modules/tool/common/service/common-tool-delete.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,14 @@ export class CommonToolDeleteService {
6060
externalTool: ExternalTool,
6161
schoolExternalTool: SchoolExternalTool
6262
): Promise<void> {
63-
await this.schoolExternalToolRepo.deleteById(schoolExternalTool.id);
64-
6563
const contextExternalTools: ContextExternalTool[] = await this.contextExternalToolRepo.find({
6664
schoolToolRef: { schoolToolId: schoolExternalTool.id },
6765
});
6866

67+
// we have to wait with deleting the school external tool until the context external tools are populated,
68+
// otherwise the context external tools won't be found due to the missing reference
69+
await this.schoolExternalToolRepo.deleteById(schoolExternalTool.id);
70+
6971
const promises: Promise<void>[] = contextExternalTools.map(async (contextExternalTool) => {
7072
await this.deleteContextExternalToolInternal(externalTool, contextExternalTool);
7173
});

apps/server/src/modules/tool/context-external-tool/repo/mikro-orm/context-external-tool.scope.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('CourseExternalToolScope', () => {
4444

4545
scope.bySchoolToolId(schoolExternalToolEntity.id);
4646

47-
expect(scope.query).toEqual({ schoolTool: schoolExternalToolEntity.id });
47+
expect(scope.query).toEqual({ schoolTool: new ObjectId(schoolExternalToolEntity.id) });
4848
});
4949
});
5050
});

apps/server/src/modules/tool/context-external-tool/repo/mikro-orm/context-external-tool.scope.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class ContextExternalToolScope extends Scope<ContextExternalToolEntity> {
1515

1616
public bySchoolToolId(schoolToolId: EntityId | undefined): ContextExternalToolScope {
1717
if (schoolToolId !== undefined) {
18-
this.addQuery({ schoolTool: schoolToolId });
18+
this.addQuery({ schoolTool: new ObjectId(schoolToolId) });
1919
}
2020
return this;
2121
}

0 commit comments

Comments
 (0)