From 5ba5ca2829a93421c493c26b6b3f711c99fa2a64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 24 Nov 2023 13:37:57 +0100 Subject: [PATCH 1/3] fix api --- ...ext-external-tool-count-per-context.response.ts | 14 ++++++++++++++ .../modules/tool/common/controller/dto/index.ts | 1 + .../response/external-tool-metadata.response.ts | 11 +++-------- .../external-tool/domain/external-tool-metadata.ts | 4 +++- .../service/external-tool-metadata.service.ts | 6 +++--- .../dto/school-external-tool-metadata.response.ts | 11 +++-------- .../domain/school-external-tool-metadata.ts | 4 +++- .../school-external-tool-metadata.service.ts | 4 ++-- 8 files changed, 32 insertions(+), 23 deletions(-) create mode 100644 apps/server/src/modules/tool/common/controller/dto/context-external-tool-count-per-context.response.ts create mode 100644 apps/server/src/modules/tool/common/controller/dto/index.ts diff --git a/apps/server/src/modules/tool/common/controller/dto/context-external-tool-count-per-context.response.ts b/apps/server/src/modules/tool/common/controller/dto/context-external-tool-count-per-context.response.ts new file mode 100644 index 00000000000..7e34d995267 --- /dev/null +++ b/apps/server/src/modules/tool/common/controller/dto/context-external-tool-count-per-context.response.ts @@ -0,0 +1,14 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class ContextExternalToolCountPerContextResponse { + @ApiProperty() + course: number; + + @ApiProperty() + boardElement: number; + + constructor(props: ContextExternalToolCountPerContextResponse) { + this.course = props.course; + this.boardElement = props.boardElement; + } +} diff --git a/apps/server/src/modules/tool/common/controller/dto/index.ts b/apps/server/src/modules/tool/common/controller/dto/index.ts new file mode 100644 index 00000000000..87fa450d468 --- /dev/null +++ b/apps/server/src/modules/tool/common/controller/dto/index.ts @@ -0,0 +1 @@ +export { ContextExternalToolCountPerContextResponse } from './context-external-tool-count-per-context.response'; diff --git a/apps/server/src/modules/tool/external-tool/controller/dto/response/external-tool-metadata.response.ts b/apps/server/src/modules/tool/external-tool/controller/dto/response/external-tool-metadata.response.ts index d38b48cc503..745d0208a39 100644 --- a/apps/server/src/modules/tool/external-tool/controller/dto/response/external-tool-metadata.response.ts +++ b/apps/server/src/modules/tool/external-tool/controller/dto/response/external-tool-metadata.response.ts @@ -1,17 +1,12 @@ import { ApiProperty } from '@nestjs/swagger'; -import { ContextExternalToolType } from '../../../../context-external-tool/entity'; +import { ContextExternalToolCountPerContextResponse } from '../../../../common/controller/dto'; export class ExternalToolMetadataResponse { @ApiProperty() schoolExternalToolCount: number; - @ApiProperty({ - type: 'object', - properties: Object.fromEntries( - Object.values(ContextExternalToolType).map((key: ContextExternalToolType) => [key, { type: 'number' }]) - ), - }) - contextExternalToolCountPerContext: Record; + @ApiProperty() + contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse; constructor(externalToolMetadataResponse: ExternalToolMetadataResponse) { this.schoolExternalToolCount = externalToolMetadataResponse.schoolExternalToolCount; diff --git a/apps/server/src/modules/tool/external-tool/domain/external-tool-metadata.ts b/apps/server/src/modules/tool/external-tool/domain/external-tool-metadata.ts index 04492680ff7..5fa4b0f3f7c 100644 --- a/apps/server/src/modules/tool/external-tool/domain/external-tool-metadata.ts +++ b/apps/server/src/modules/tool/external-tool/domain/external-tool-metadata.ts @@ -1,7 +1,9 @@ +import { ContextExternalToolType } from '../../context-external-tool/entity'; + export class ExternalToolMetadata { schoolExternalToolCount: number; - contextExternalToolCountPerContext: Record; + contextExternalToolCountPerContext: Record; constructor(externalToolMetadata: ExternalToolMetadata) { this.schoolExternalToolCount = externalToolMetadata.schoolExternalToolCount; diff --git a/apps/server/src/modules/tool/external-tool/service/external-tool-metadata.service.ts b/apps/server/src/modules/tool/external-tool/service/external-tool-metadata.service.ts index 9476e738a87..ef82629e87d 100644 --- a/apps/server/src/modules/tool/external-tool/service/external-tool-metadata.service.ts +++ b/apps/server/src/modules/tool/external-tool/service/external-tool-metadata.service.ts @@ -2,10 +2,10 @@ import { Injectable } from '@nestjs/common'; import { EntityId } from '@shared/domain'; import { ContextExternalToolRepo, SchoolExternalToolRepo } from '@shared/repo'; import { ToolContextType } from '../../common/enum'; +import { ToolContextMapper } from '../../common/mapper/tool-context.mapper'; import { ContextExternalToolType } from '../../context-external-tool/entity'; import { SchoolExternalTool } from '../../school-external-tool/domain'; import { ExternalToolMetadata } from '../domain'; -import { ToolContextMapper } from '../../common/mapper/tool-context.mapper'; @Injectable() export class ExternalToolMetadataService { @@ -40,11 +40,11 @@ export class ExternalToolMetadataService { ); } - const externaltoolMetadata: ExternalToolMetadata = new ExternalToolMetadata({ + const externalToolMetadata: ExternalToolMetadata = new ExternalToolMetadata({ schoolExternalToolCount: schoolExternalTools.length, contextExternalToolCountPerContext: contextExternalToolCount, }); - return externaltoolMetadata; + return externalToolMetadata; } } diff --git a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-metadata.response.ts b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-metadata.response.ts index db4806d23ec..c61b24df3c9 100644 --- a/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-metadata.response.ts +++ b/apps/server/src/modules/tool/school-external-tool/controller/dto/school-external-tool-metadata.response.ts @@ -1,14 +1,9 @@ import { ApiProperty } from '@nestjs/swagger'; -import { ContextExternalToolType } from '../../../context-external-tool/entity'; +import { ContextExternalToolCountPerContextResponse } from '../../../common/controller/dto'; export class SchoolExternalToolMetadataResponse { - @ApiProperty({ - type: 'object', - properties: Object.fromEntries( - Object.values(ContextExternalToolType).map((key: ContextExternalToolType) => [key, { type: 'number' }]) - ), - }) - contextExternalToolCountPerContext: Record; + @ApiProperty() + contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse; constructor(schoolExternalToolMetadataResponse: SchoolExternalToolMetadataResponse) { this.contextExternalToolCountPerContext = schoolExternalToolMetadataResponse.contextExternalToolCountPerContext; diff --git a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool-metadata.ts b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool-metadata.ts index 4cccdfe11a1..741857352d3 100644 --- a/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool-metadata.ts +++ b/apps/server/src/modules/tool/school-external-tool/domain/school-external-tool-metadata.ts @@ -1,5 +1,7 @@ +import { ContextExternalToolType } from '../../context-external-tool/entity'; + export class SchoolExternalToolMetadata { - contextExternalToolCountPerContext: Record; + contextExternalToolCountPerContext: Record; constructor(schoolExternalToolMetadata: SchoolExternalToolMetadata) { this.contextExternalToolCountPerContext = schoolExternalToolMetadata.contextExternalToolCountPerContext; diff --git a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool-metadata.service.ts b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool-metadata.service.ts index fa8fd4fc926..53061147aca 100644 --- a/apps/server/src/modules/tool/school-external-tool/service/school-external-tool-metadata.service.ts +++ b/apps/server/src/modules/tool/school-external-tool/service/school-external-tool-metadata.service.ts @@ -28,10 +28,10 @@ export class SchoolExternalToolMetadataService { }) ); - const schoolExternaltoolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({ + const schoolExternalToolMetadata: SchoolExternalToolMetadata = new SchoolExternalToolMetadata({ contextExternalToolCountPerContext: contextExternalToolCount, }); - return schoolExternaltoolMetadata; + return schoolExternalToolMetadata; } } From 9de4775c96aba78acadb06b22423e7d59b1eb6eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 24 Nov 2023 14:09:23 +0100 Subject: [PATCH 2/3] fix test --- .../modules/tool/external-tool/uc/external-tool.uc.spec.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts b/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts index ff209ac301d..35a20ca8997 100644 --- a/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts +++ b/apps/server/src/modules/tool/external-tool/uc/external-tool.uc.spec.ts @@ -7,10 +7,7 @@ import { Test, TestingModule } from '@nestjs/testing'; import { IFindOptions, Permission, Role, SortOrder, User } from '@shared/domain'; import { Page } from '@shared/domain/domainobject/page'; import { roleFactory, setupEntities, userFactory } from '@shared/testing'; -import { - externalToolFactory, - oauth2ToolConfigFactory, -} from '@shared/testing/factory/domainobject/tool/external-tool.factory'; +import { externalToolFactory, oauth2ToolConfigFactory } from '@shared/testing/factory'; import { ExternalToolSearchQuery } from '../../common/interface'; import { ExternalTool, ExternalToolMetadata, Oauth2ToolConfig } from '../domain'; import { @@ -550,7 +547,7 @@ describe('ExternalToolUc', () => { const externalToolMetadata: ExternalToolMetadata = new ExternalToolMetadata({ schoolExternalToolCount: 2, - contextExternalToolCountPerContext: { course: 3, 'board-element': 3 }, + contextExternalToolCountPerContext: { course: 3, boardElement: 3 }, }); externalToolMetadataService.getMetadata.mockResolvedValue(externalToolMetadata); From 17d90834c2185677034770c92c5a0c18ba5b4be2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 24 Nov 2023 16:07:00 +0100 Subject: [PATCH 3/3] use constructor --- .../external-tool/mapper/external-tool-metadata.mapper.ts | 5 ++++- .../mapper/school-external-tool-metadata.mapper.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/server/src/modules/tool/external-tool/mapper/external-tool-metadata.mapper.ts b/apps/server/src/modules/tool/external-tool/mapper/external-tool-metadata.mapper.ts index b3d6555f898..f5c257b5430 100644 --- a/apps/server/src/modules/tool/external-tool/mapper/external-tool-metadata.mapper.ts +++ b/apps/server/src/modules/tool/external-tool/mapper/external-tool-metadata.mapper.ts @@ -1,3 +1,4 @@ +import { ContextExternalToolCountPerContextResponse } from '../../common/controller/dto'; import { ExternalToolMetadataResponse } from '../controller/dto'; import { ExternalToolMetadata } from '../domain'; @@ -5,7 +6,9 @@ export class ExternalToolMetadataMapper { static mapToExternalToolMetadataResponse(externalToolMetadata: ExternalToolMetadata): ExternalToolMetadataResponse { const externalToolMetadataResponse: ExternalToolMetadataResponse = new ExternalToolMetadataResponse({ schoolExternalToolCount: externalToolMetadata.schoolExternalToolCount, - contextExternalToolCountPerContext: externalToolMetadata.contextExternalToolCountPerContext, + contextExternalToolCountPerContext: new ContextExternalToolCountPerContextResponse( + externalToolMetadata.contextExternalToolCountPerContext + ), }); return externalToolMetadataResponse; diff --git a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-metadata.mapper.ts b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-metadata.mapper.ts index 1e42f22ebf2..acc58dd6ef8 100644 --- a/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-metadata.mapper.ts +++ b/apps/server/src/modules/tool/school-external-tool/mapper/school-external-tool-metadata.mapper.ts @@ -1,3 +1,4 @@ +import { ContextExternalToolCountPerContextResponse } from '../../common/controller/dto'; import { SchoolExternalToolMetadataResponse } from '../controller/dto'; import { SchoolExternalToolMetadata } from '../domain'; @@ -6,7 +7,9 @@ export class SchoolExternalToolMetadataMapper { schoolExternalToolMetadata: SchoolExternalToolMetadata ): SchoolExternalToolMetadataResponse { const externalToolMetadataResponse: SchoolExternalToolMetadataResponse = new SchoolExternalToolMetadataResponse({ - contextExternalToolCountPerContext: schoolExternalToolMetadata.contextExternalToolCountPerContext, + contextExternalToolCountPerContext: new ContextExternalToolCountPerContextResponse( + schoolExternalToolMetadata.contextExternalToolCountPerContext + ), }); return externalToolMetadataResponse;