diff --git a/ExpressAPI/package.json b/ExpressAPI/package.json index f70be4a42cd4341c268f9912d741b392f67679e2..19de02e95b3fd52093da953787fb98cf34e91f7c 100644 --- a/ExpressAPI/package.json +++ b/ExpressAPI/package.json @@ -1,7 +1,7 @@ { "name" : "dojo_backend_api", "description" : "Backend API for the Dojo Project", - "version" : "1.0.0", + "version" : "1.0.1", "license" : "", "author" : "Michaƫl Minelli <michael-jean.minelli@hesge.ch>", "main" : "app.js", diff --git a/ExpressAPI/src/helpers/DojoValidators.ts b/ExpressAPI/src/helpers/DojoValidators.ts index 617c55642dea997b32839f671e0835f090e747a3..c4430360bb482496c6078ba4f8a12eff905e4cd1 100644 --- a/ExpressAPI/src/helpers/DojoValidators.ts +++ b/ExpressAPI/src/helpers/DojoValidators.ts @@ -4,7 +4,7 @@ import { CustomValidator, ErrorMessage, FieldMessageFactory, Meta } from 'expres import { BailOptions, ValidationChain } from 'express-validator/src/chain'; import GitlabManager from '../managers/GitlabManager'; import express from 'express'; -import ExerciceHelper from '../shared/helpers/ExerciceHelper'; +import SharedExerciceHelper from '../shared/helpers/Dojo/SharedExerciceHelper'; declare type DojoMeta = Meta & { @@ -49,7 +49,7 @@ class DojoValidators { readonly templateUrlValidator = this.toValidatorSchemaOptions({ bail : true, errorMessage: 'Template doesn\'t exist or you don\'t have access to it', - options : (value, { + options : (_value, { req, path }) => { @@ -86,14 +86,14 @@ class DojoValidators { readonly exerciceResultsValidator = this.toValidatorSchemaOptions({ bail : true, errorMessage: 'Results: not provided or invalid format', - options : (value, { + options : (_value, { req, path }) => { return new Promise((resolve, reject) => { const results = this.getParamValue(req, path); if ( results ) { - ExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject(); + SharedExerciceHelper.validateResultFile(results, false).isValid ? resolve(true) : reject(); } else { reject(); } diff --git a/ExpressAPI/src/managers/GitlabManager.ts b/ExpressAPI/src/managers/GitlabManager.ts index 0b33bd5f5e65d6347e48081a1f01e95b3bfd8124..53b6ee38ff698ccca6cb71b7916d1fe98a68da8b 100644 --- a/ExpressAPI/src/managers/GitlabManager.ts +++ b/ExpressAPI/src/managers/GitlabManager.ts @@ -6,15 +6,15 @@ import GitlabMember from '../shared/types/Gitlab/GitlabMember'; import { StatusCodes } from 'http-status-codes'; import GitlabVisibility from '../shared/types/Gitlab/GitlabVisibility'; import GitlabUser from '../shared/types/Gitlab/GitlabUser'; -import GitlabRoutes from '../shared/types/Gitlab/GitlabRoutes'; import GitlabTreeFile from '../shared/types/Gitlab/GitlabTreeFile'; import parseLinkHeader from 'parse-link-header'; import GitlabFile from '../shared/types/Gitlab/GitlabFile'; import express from 'express'; +import GitlabRoute from '../shared/types/Gitlab/GitlabRoute'; class GitlabManager { - private getApiUrl(route: GitlabRoutes): string { + private getApiUrl(route: GitlabRoute): string { return `${ Config.gitlab.apiURL }${ route }`; } @@ -22,7 +22,7 @@ class GitlabManager { try { const params: any = {}; params[paramName] = paramToSearch; - return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoutes.USERS_GET), { params: params })).data[0]; + return (await axios.get<Array<GitlabUser>>(this.getApiUrl(GitlabRoute.USERS_GET), { params: params })).data[0]; } catch ( e ) { } return undefined; @@ -37,19 +37,19 @@ class GitlabManager { } async getRepository(idOrNamespace: string): Promise<GitlabRepository> { - const response = await axios.get<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); + const response = await axios.get<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); return response.data; } async getRepositoryMembers(idOrNamespace: string): Promise<Array<GitlabMember>> { - const response = await axios.get<Array<GitlabMember>>(this.getApiUrl(GitlabRoutes.REPOSITORY_MEMBERS_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); + const response = await axios.get<Array<GitlabMember>>(this.getApiUrl(GitlabRoute.REPOSITORY_MEMBERS_GET).replace('{{id}}', encodeURIComponent(idOrNamespace))); return response.data; } async createRepository(name: string, description: string, visibility: string, initializeWithReadme: boolean, namespace: number, sharedRunnersEnabled: boolean, wikiEnabled: boolean, import_url: string): Promise<GitlabRepository> { - const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_CREATE), { + const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_CREATE), { name : name, description : description, import_url : import_url, @@ -64,7 +64,7 @@ class GitlabManager { } async forkRepository(forkId: number, name: string, path: string, description: string, visibility: string, namespace: number): Promise<GitlabRepository> { - const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_FORK).replace('{{id}}', String(forkId)), { + const response = await axios.post<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_FORK).replace('{{id}}', String(forkId)), { name : name, path : path, description : description, @@ -76,7 +76,7 @@ class GitlabManager { } async editRepository(repoId: number, newAttributes: Partial<GitlabRepository>): Promise<GitlabRepository> { - const response = await axios.put<GitlabRepository>(this.getApiUrl(GitlabRoutes.REPOSITORY_EDIT).replace('{{id}}', String(repoId)), newAttributes); + const response = await axios.put<GitlabRepository>(this.getApiUrl(GitlabRoute.REPOSITORY_EDIT).replace('{{id}}', String(repoId)), newAttributes); return response.data; } @@ -86,7 +86,7 @@ class GitlabManager { } async addRepositoryMember(repoId: number, userId: number, accessLevel: GitlabAccessLevel): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_MEMBER_ADD).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_MEMBER_ADD).replace('{{id}}', String(repoId)), { user_id : userId, access_level: accessLevel }); @@ -95,7 +95,7 @@ class GitlabManager { } async addRepositoryVariable(repoId: number, key: string, value: string, isProtected: boolean, isMasked: boolean): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_VARIABLES_ADD).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_VARIABLES_ADD).replace('{{id}}', String(repoId)), { key : key, variable_type: 'env_var', value : value, @@ -138,7 +138,7 @@ class GitlabManager { } async protectBranch(repoId: number, branchName: string, allowForcePush: boolean, allowedToMerge: GitlabAccessLevel, allowedToPush: GitlabAccessLevel, allowedToUnprotect: GitlabAccessLevel): Promise<GitlabMember> { - const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoutes.REPOSITORY_BRANCHES_PROTECT).replace('{{id}}', String(repoId)), { + const response = await axios.post<GitlabMember>(this.getApiUrl(GitlabRoute.REPOSITORY_BRANCHES_PROTECT).replace('{{id}}', String(repoId)), { name : branchName, allow_force_push : allowForcePush, merge_access_level : allowedToMerge.valueOf(), @@ -150,7 +150,7 @@ class GitlabManager { } async getRepositoryTree(repoId: number, recursive: boolean = true, branch: string = 'main'): Promise<Array<GitlabTreeFile>> { - let address: string | undefined = this.getApiUrl(GitlabRoutes.REPOSITORY_TREE).replace('{{id}}', String(repoId)); + let address: string | undefined = this.getApiUrl(GitlabRoute.REPOSITORY_TREE).replace('{{id}}', String(repoId)); let params: any = { pagination: 'keyset', recursive : recursive, @@ -178,7 +178,7 @@ class GitlabManager { } async getFile(repoId: number, filePath: string, branch: string = 'main'): Promise<GitlabFile> { - const response = await axios.get<GitlabFile>(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { + const response = await axios.get<GitlabFile>(this.getApiUrl(GitlabRoute.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { params: { ref: branch } @@ -188,7 +188,7 @@ class GitlabManager { } async createFile(repoId: number, filePath: string, fileBase64: string, commitMessage: string, branch: string = 'main', authorName: string = 'Dojo', authorMail: string | undefined = undefined) { - await axios.post(this.getApiUrl(GitlabRoutes.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { + await axios.post(this.getApiUrl(GitlabRoute.REPOSITORY_FILE).replace('{{id}}', String(repoId)).replace('{{filePath}}', encodeURIComponent(filePath)), { encoding : 'base64', branch : branch, commit_message: commitMessage, diff --git a/ExpressAPI/src/shared b/ExpressAPI/src/shared index eab5c0a5a32079fcb439a1ad79453611c8605536..f33e4e0c7b34f9060e8995550920d25cd3e73c40 160000 --- a/ExpressAPI/src/shared +++ b/ExpressAPI/src/shared @@ -1 +1 @@ -Subproject commit eab5c0a5a32079fcb439a1ad79453611c8605536 +Subproject commit f33e4e0c7b34f9060e8995550920d25cd3e73c40