From ce495680ad5fe004f65f7b062660280077d23909 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Minelli?= <git@minelli.me> Date: Tue, 5 Mar 2024 16:38:18 +0100 Subject: [PATCH] Sonar => Resolve issues --- helpers/Dojo/AssignmentValidator.ts | 2 +- helpers/Dojo/DojoBackendHelper.ts | 28 ++++++++++++++++++++++++++++ types/Dojo/ApiRoute.ts | 14 +++++++------- 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 helpers/Dojo/DojoBackendHelper.ts diff --git a/helpers/Dojo/AssignmentValidator.ts b/helpers/Dojo/AssignmentValidator.ts index 3072ec0..d35d8fc 100644 --- a/helpers/Dojo/AssignmentValidator.ts +++ b/helpers/Dojo/AssignmentValidator.ts @@ -146,7 +146,7 @@ class AssignmentValidator { // Immutable files validation (Check if exists and if the given type is correct) this.newSubStep('ASSIGNMENT_FILE_IMMUTABLES_VALIDATION', 'Validating immutable files'); - for ( const immutable of validationResults.content!.immutable ) { + for ( const immutable of this.assignmentFile.immutable ) { const immutablePath = path.join(this.folderAssignment, immutable.path); if ( !fs.existsSync(immutablePath) ) { this.emitError(`Immutable path not found: ${ immutable.path }`, assignmentFileValidationError, AssignmentCheckerError.IMMUTABLE_PATH_NOT_FOUND); diff --git a/helpers/Dojo/DojoBackendHelper.ts b/helpers/Dojo/DojoBackendHelper.ts new file mode 100644 index 0000000..c682bfb --- /dev/null +++ b/helpers/Dojo/DojoBackendHelper.ts @@ -0,0 +1,28 @@ +import ApiRoute from '../../types/Dojo/ApiRoute'; +import ClientsSharedConfig from '../../config/ClientsSharedConfig'; + + +class DojoBackendHelper { + public getApiUrl(route: ApiRoute, options?: Partial<{ assignmentNameOrUrl: string, exerciseIdOrUrl: string, gitlabProjectId: string }>): string { + const url = `${ ClientsSharedConfig.apiURL }${ route }`; + + if ( options ) { + if ( options.assignmentNameOrUrl ) { + return url.replace('{{assignmentNameOrUrl}}', encodeURIComponent(options.assignmentNameOrUrl)); + } + + if ( options.exerciseIdOrUrl ) { + return url.replace('{{exerciseIdOrUrl}}', encodeURIComponent(options.exerciseIdOrUrl)); + } + + if ( options.gitlabProjectId ) { + return url.replace('{{gitlabProjectId}}', encodeURIComponent(options.gitlabProjectId)); + } + } + + return url; + } +} + + +export default new DojoBackendHelper(); \ No newline at end of file diff --git a/types/Dojo/ApiRoute.ts b/types/Dojo/ApiRoute.ts index 53e3f9f..8e4969b 100644 --- a/types/Dojo/ApiRoute.ts +++ b/types/Dojo/ApiRoute.ts @@ -2,16 +2,16 @@ enum ApiRoute { LOGIN = '/login', REFRESH_TOKENS = '/refresh_tokens', TEST_SESSION = '/test_session', - GITLAB_CHECK_TEMPLATE_ACCESS = '/gitlab/project/{{id}}/checkTemplateAccess', - ASSIGNMENT_GET = '/assignments/{{nameOrUrl}}', + GITLAB_CHECK_TEMPLATE_ACCESS = '/gitlab/project/{{gitlabProjectId}}/checkTemplateAccess', + ASSIGNMENT_GET = '/assignments/{{assignmentNameOrUrl}}', ASSIGNMENT_CREATE = '/assignments', - ASSIGNMENT_PUBLISH = '/assignments/{{nameOrUrl}}/publish', - ASSIGNMENT_UNPUBLISH = '/assignments/{{nameOrUrl}}/unpublish', + ASSIGNMENT_PUBLISH = '/assignments/{{assignmentNameOrUrl}}/publish', + ASSIGNMENT_UNPUBLISH = '/assignments/{{assignmentNameOrUrl}}/unpublish', ASSIGNMENT_CORRECTION_LINK = '/assignments/{{assignmentNameOrUrl}}/corrections', ASSIGNMENT_CORRECTION_UPDATE = '/assignments/{{assignmentNameOrUrl}}/corrections/{{exerciseIdOrUrl}}', - EXERCISE_CREATE = '/assignments/{{nameOrUrl}}/exercises', - EXERCISE_ASSIGNMENT = '/exercises/{{id}}/assignment', - EXERCISE_RESULTS = '/exercises/{{id}}/results' + EXERCISE_CREATE = '/assignments/{{assignmentNameOrUrl}}/exercises', + EXERCISE_ASSIGNMENT = '/exercises/{{exerciseIdOrUrl}}/assignment', + EXERCISE_RESULTS = '/exercises/{{exerciseIdOrUrl}}/results' } -- GitLab