From c76fc2fee056260e0ae79d5d22f91eaffc60f405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marvin=20=C3=96hlerking?= Date: Fri, 24 Nov 2023 13:37:30 +0100 Subject: [PATCH] fix mapping --- .../SchoolExternalToolApi.composable.ts | 16 ++----- src/serverApi/v3/api.ts | 46 +++++++++---------- .../mapper/school-external-tool.mapper.ts | 6 +-- 3 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/components/data-external-tool/SchoolExternalToolApi.composable.ts b/src/components/data-external-tool/SchoolExternalToolApi.composable.ts index a051668d1c..d0d7b3c7ba 100644 --- a/src/components/data-external-tool/SchoolExternalToolApi.composable.ts +++ b/src/components/data-external-tool/SchoolExternalToolApi.composable.ts @@ -3,9 +3,9 @@ import { ToolApiFactory, ToolApiInterface, } from "@/serverApi/v3"; -import { $axios } from "@/utils/api"; import { SchoolExternalToolMetadata } from "@/store/external-tool"; import { SchoolExternalToolMapper } from "@/store/external-tool/mapper"; +import { $axios } from "@/utils/api"; import { AxiosResponse } from "axios"; export const useSchoolExternalToolApi = () => { @@ -19,18 +19,10 @@ export const useSchoolExternalToolApi = () => { schoolExternalToolId ); - if ( - response.data.contextExternalToolCountPerContext.course || - response.data.contextExternalToolCountPerContext.boardElement - ) { - const mapped: SchoolExternalToolMetadata = - SchoolExternalToolMapper.mapSchoolExternalToolMetadata(response.data); + const mapped: SchoolExternalToolMetadata = + SchoolExternalToolMapper.mapSchoolExternalToolMetadata(response.data); - return mapped; - } - throw new Error( - "SchoolExternalToolMetadataResponse is missing required fields" - ); + return mapped; }; return { diff --git a/src/serverApi/v3/api.ts b/src/serverApi/v3/api.ts index 30707cf1c6..2a5baffe06 100644 --- a/src/serverApi/v3/api.ts +++ b/src/serverApi/v3/api.ts @@ -720,6 +720,25 @@ export interface ContextExternalToolConfigurationTemplateResponse { */ version: number; } +/** + * + * @export + * @interface ContextExternalToolCountPerContextResponse + */ +export interface ContextExternalToolCountPerContextResponse { + /** + * + * @type {number} + * @memberof ContextExternalToolCountPerContextResponse + */ + course: number; + /** + * + * @type {number} + * @memberof ContextExternalToolCountPerContextResponse + */ + boardElement: number; +} /** * * @export @@ -1633,10 +1652,10 @@ export interface ExternalToolMetadataResponse { schoolExternalToolCount: number; /** * - * @type {SchoolExternalToolMetadataResponseContextExternalToolCountPerContext} + * @type {ContextExternalToolCountPerContextResponse} * @memberof ExternalToolMetadataResponse */ - contextExternalToolCountPerContext: SchoolExternalToolMetadataResponseContextExternalToolCountPerContext; + contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse; } /** * @@ -3923,29 +3942,10 @@ export interface SchoolExternalToolConfigurationTemplateResponse { export interface SchoolExternalToolMetadataResponse { /** * - * @type {SchoolExternalToolMetadataResponseContextExternalToolCountPerContext} + * @type {ContextExternalToolCountPerContextResponse} * @memberof SchoolExternalToolMetadataResponse */ - contextExternalToolCountPerContext: SchoolExternalToolMetadataResponseContextExternalToolCountPerContext; -} -/** - * - * @export - * @interface SchoolExternalToolMetadataResponseContextExternalToolCountPerContext - */ -export interface SchoolExternalToolMetadataResponseContextExternalToolCountPerContext { - /** - * - * @type {number} - * @memberof SchoolExternalToolMetadataResponseContextExternalToolCountPerContext - */ - course?: number; - /** - * - * @type {number} - * @memberof SchoolExternalToolMetadataResponseContextExternalToolCountPerContext - */ - boardElement?: number; + contextExternalToolCountPerContext: ContextExternalToolCountPerContextResponse; } /** * diff --git a/src/store/external-tool/mapper/school-external-tool.mapper.ts b/src/store/external-tool/mapper/school-external-tool.mapper.ts index c508423169..9de244b128 100644 --- a/src/store/external-tool/mapper/school-external-tool.mapper.ts +++ b/src/store/external-tool/mapper/school-external-tool.mapper.ts @@ -11,6 +11,7 @@ import { SchoolExternalTool, SchoolExternalToolSave, } from "../school-external-tool"; +import { SchoolExternalToolMetadata } from "../school-external-tool-metadata"; import { SchoolExternalToolConfigurationTemplate } from "../tool-configuration-template"; import { ToolParameter } from "../tool-parameter"; import { ToolParameterEntry } from "../tool-parameter-entry"; @@ -19,7 +20,6 @@ import { ToolConfigurationStatusMapping, } from "./common-tool.mapper"; import { ExternalToolMapper } from "./external-tool.mapper"; -import { SchoolExternalToolMetadata } from "../school-external-tool-metadata"; export class SchoolExternalToolMapper { static mapToSchoolExternalToolConfigurationTemplate( @@ -121,8 +121,8 @@ export class SchoolExternalToolMapper { response: SchoolExternalToolMetadataResponse ): SchoolExternalToolMetadata { const mapped: SchoolExternalToolMetadata = { - course: response.contextExternalToolCountPerContext.course!, - boardElement: response.contextExternalToolCountPerContext.boardElement!, + course: response.contextExternalToolCountPerContext.course, + boardElement: response.contextExternalToolCountPerContext.boardElement, }; return mapped;