diff --git a/helpers/Dojo/AssignmentValidator.ts b/helpers/Dojo/AssignmentValidator.ts index 3072ec08446ef3b20777647fc1fecba86f511cff..d35d8fc0932f3f1a923007ed1556e813a2f2cea1 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 0000000000000000000000000000000000000000..c682bfb71fdd895a6d3761fea6694754542074ee --- /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 53e3f9f59129ce7eecef1c82d9ecd6a0ab28db27..8e4969b6de34599ca29e803ca6fbcd3a3c91d799 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' }