From 951b5d3bba4c84c3655f5c1ecfaa3fc29a52545f Mon Sep 17 00:00:00 2001 From: Igor Richter <93926487+IgorCapCoder@users.noreply.github.com> Date: Fri, 17 May 2024 17:38:44 +0200 Subject: [PATCH] fix copy course (#5013) --- .../service/context-external-tool.service.spec.ts | 4 +++- .../service/context-external-tool.service.ts | 11 ++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts index c6b01502ecf..1aeac5675ff 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.spec.ts @@ -500,7 +500,9 @@ describe(ContextExternalToolService.name, () => { await service.copyContextExternalTool(contextExternalTool, contextCopyId); - expect(contextExternalToolRepo.save).toHaveBeenCalledWith(contextExternalTool); + expect(contextExternalToolRepo.save).toHaveBeenCalledWith( + new ContextExternalTool({ ...contextExternalTool.getProps(), id: expect.any(String) }) + ); }); }); }); diff --git a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.ts b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.ts index c050b69f527..7ba0878bfd3 100644 --- a/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.ts +++ b/apps/server/src/modules/tool/context-external-tool/service/context-external-tool.service.ts @@ -10,9 +10,9 @@ import { SchoolExternalTool } from '../../school-external-tool/domain'; import { SchoolExternalToolService } from '../../school-external-tool/service'; import { ContextExternalTool, + ContextExternalToolLaunchable, ContextRef, RestrictedContextMismatchLoggableException, - ContextExternalToolLaunchable, } from '../domain'; import { ContextExternalToolQuery } from '../uc/dto/context-external-tool.types'; @@ -88,11 +88,8 @@ export class ContextExternalToolService { contextCopyId: EntityId ): Promise { const copy = new ContextExternalTool({ + ...contextExternalTool.getProps(), id: new ObjectId().toHexString(), - schoolToolRef: contextExternalTool.schoolToolRef, - contextRef: contextExternalTool.contextRef, - displayName: contextExternalTool.displayName, - parameters: contextExternalTool.parameters, }); copy.contextRef.id = contextCopyId; @@ -113,11 +110,11 @@ export class ContextExternalToolService { externalTool.parameters?.forEach((parameter: CustomParameter): void => { if (parameter.isProtected) { - this.deleteProtectedValues(contextExternalTool, parameter.name); + this.deleteProtectedValues(copy, parameter.name); } }); - const copiedTool: ContextExternalTool = await this.contextExternalToolRepo.save(contextExternalTool); + const copiedTool: ContextExternalTool = await this.contextExternalToolRepo.save(copy); return copiedTool; }