From 6cf8757120c8139b441e300c8d8a2f31da0e8c92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.me> Date: Tue, 5 Mar 2024 16:39:40 +0100 Subject: [PATCH] Sonar => Resolve issues --- .../subcommands/ExerciseCorrectionCommand.ts | 2 +- NodeApp/src/managers/DojoBackendManager.ts | 35 +++++++++---------- NodeApp/src/sharedByClients | 2 +- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts b/NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts index 0e98826..e2405a9 100644 --- a/NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts +++ b/NodeApp/src/commander/exercise/subcommands/ExerciseCorrectionCommand.ts @@ -41,7 +41,7 @@ class ExerciseCorrectionCommand extends CommanderCommand { return assignment.corrections.map(correction => { return { name : correction.name.replace(correction.assignmentName, '').split('-')[2].trim(), - value: correction.correctionCommit!.web_url?.replace('/commit/', '/tree/') ?? '' + value: correction.correctionCommit?.web_url?.replace('/commit/', '/tree/') ?? '' }; }); } diff --git a/NodeApp/src/managers/DojoBackendManager.ts b/NodeApp/src/managers/DojoBackendManager.ts index b2ef629..9bf65df 100644 --- a/NodeApp/src/managers/DojoBackendManager.ts +++ b/NodeApp/src/managers/DojoBackendManager.ts @@ -9,6 +9,7 @@ import Exercise from '../sharedByClients/models/Exercise'; import GitlabToken from '../shared/types/Gitlab/GitlabToken'; import User from '../sharedByClients/models/User'; import DojoStatusCode from '../shared/types/Dojo/DojoStatusCode'; +import DojoBackendHelper from '../sharedByClients/helpers/Dojo/DojoBackendHelper'; class DojoBackendManager { @@ -55,14 +56,9 @@ class DojoBackendManager { } - public getApiUrl(route: ApiRoute): string { - return `${ ClientsSharedConfig.apiURL }${ route }`; - } - - public async login(gitlabTokens: GitlabToken): Promise<User | undefined> { try { - return (await axios.post<DojoBackendResponse<User>>(this.getApiUrl(ApiRoute.LOGIN), { + return (await axios.post<DojoBackendResponse<User>>(DojoBackendHelper.getApiUrl(ApiRoute.LOGIN), { accessToken : gitlabTokens.access_token, refreshToken: gitlabTokens.refresh_token })).data.data; @@ -73,7 +69,7 @@ class DojoBackendManager { public async refreshTokens(refreshToken: string): Promise<GitlabToken> { - return (await axios.post<DojoBackendResponse<GitlabToken>>(this.getApiUrl(ApiRoute.REFRESH_TOKENS), { + return (await axios.post<DojoBackendResponse<GitlabToken>>(DojoBackendHelper.getApiUrl(ApiRoute.REFRESH_TOKENS), { refreshToken: refreshToken })).data.data; } @@ -81,7 +77,7 @@ class DojoBackendManager { public async getAssignment(nameOrUrl: string): Promise<Assignment | undefined> { try { - return (await axios.get<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_GET).replace('{{nameOrUrl}}', encodeURIComponent(nameOrUrl)))).data.data; + return (await axios.get<DojoBackendResponse<Assignment>>(DojoBackendHelper.getApiUrl(ApiRoute.ASSIGNMENT_GET, { assignmentNameOrUrl: nameOrUrl }))).data.data; } catch ( error ) { return undefined; } @@ -96,7 +92,7 @@ class DojoBackendManager { } try { - await axios.get(this.getApiUrl(ApiRoute.GITLAB_CHECK_TEMPLATE_ACCESS).replace('{{id}}', idOrNamespace)); + await axios.get(DojoBackendHelper.getApiUrl(ApiRoute.GITLAB_CHECK_TEMPLATE_ACCESS, { gitlabProjectId: idOrNamespace })); if ( verbose ) { spinner.succeed('Template access granted'); @@ -118,10 +114,10 @@ class DojoBackendManager { } try { - const response = await axios.post<DojoBackendResponse<Assignment>>(this.getApiUrl(ApiRoute.ASSIGNMENT_CREATE), Object.assign({ - name : name, - members: JSON.stringify(members) - }, templateIdOrNamespace ? { template: templateIdOrNamespace } : {})); + const response = await axios.post<DojoBackendResponse<Assignment>>(DojoBackendHelper.getApiUrl(ApiRoute.ASSIGNMENT_CREATE), Object.assign({ + name : name, + members: JSON.stringify(members) + }, templateIdOrNamespace ? { template: templateIdOrNamespace } : {})); if ( verbose ) { spinner.succeed(`Assignment successfully created`); @@ -143,7 +139,7 @@ class DojoBackendManager { } try { - const response = await axios.post<DojoBackendResponse<Exercise>>(this.getApiUrl(ApiRoute.EXERCISE_CREATE).replace('{{nameOrUrl}}', encodeURIComponent(assignmentName)), { members: JSON.stringify(members) }); + const response = await axios.post<DojoBackendResponse<Exercise>>(DojoBackendHelper.getApiUrl(ApiRoute.EXERCISE_CREATE, { assignmentNameOrUrl: assignmentName }), { members: JSON.stringify(members) }); if ( verbose ) { spinner.succeed(`Exercise successfully created`); @@ -165,7 +161,7 @@ class DojoBackendManager { } try { - await axios.patch<DojoBackendResponse<null>>(this.getApiUrl(publish ? ApiRoute.ASSIGNMENT_PUBLISH : ApiRoute.ASSIGNMENT_UNPUBLISH).replace('{{nameOrUrl}}', encodeURIComponent(assignment.name)), {}); + await axios.patch<DojoBackendResponse<null>>(DojoBackendHelper.getApiUrl(publish ? ApiRoute.ASSIGNMENT_PUBLISH : ApiRoute.ASSIGNMENT_UNPUBLISH, { assignmentNameOrUrl: assignment.name }), {}); if ( verbose ) { spinner.succeed(`Assignment ${ assignment.name } successfully ${ publish ? 'published' : 'unpublished' }`); @@ -196,9 +192,12 @@ class DojoBackendManager { const axiosFunction = isUpdate ? axios.patch : axios.post; const route = isUpdate ? ApiRoute.ASSIGNMENT_CORRECTION_UPDATE : ApiRoute.ASSIGNMENT_CORRECTION_LINK; - await axiosFunction(this.getApiUrl(route).replace('{{assignmentNameOrUrl}}', encodeURIComponent(assignment.name)).replace('{{exerciseIdOrUrl}}', encodeURIComponent(exerciseIdOrUrl)), { - exerciseIdOrUrl: exerciseIdOrUrl - }); + await axiosFunction(DojoBackendHelper.getApiUrl(route, { + assignmentNameOrUrl: assignment.name, + exerciseIdOrUrl : exerciseIdOrUrl + }), { + exerciseIdOrUrl: exerciseIdOrUrl + }); if ( verbose ) { spinner.succeed(`Correction ${ isUpdate ? 'updated' : 'linked' }`); diff --git a/NodeApp/src/sharedByClients b/NodeApp/src/sharedByClients index 2b2b237..ce49568 160000 --- a/NodeApp/src/sharedByClients +++ b/NodeApp/src/sharedByClients @@ -1 +1 @@ -Subproject commit 2b2b2376b0389a39283327bba5bfaf7d1ce136ac +Subproject commit ce495680ad5fe004f65f7b062660280077d23909 -- GitLab