|
@@ -1,10 +1,15 @@ |
|
|
|
|
|
import {constants} from 'http2'; |
|
|
import * as codeCore from '@modal/code-core'; |
|
|
import * as codeCore from '@modal/code-core'; |
|
|
|
|
|
import {HttpError} from '../../packages/fastify-compliant-http-errors'; |
|
|
|
|
|
|
|
|
export interface GitService { |
|
|
export interface GitService { |
|
|
createRepo(options: codeCore.git.CreateRepoData, user?: codeCore.common.User): Promise<codeCore.git.Repo>; |
|
|
createRepo(options: codeCore.git.CreateRepoData, user?: codeCore.common.User): Promise<codeCore.git.Repo>; |
|
|
deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> |
|
|
deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export class UnableToCreateRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Create Repo') {} |
|
|
|
|
|
export class UnableToDeleteRepoError extends HttpError(constants.HTTP_STATUS_UNAUTHORIZED, 'Unable to Delete Repo') {} |
|
|
|
|
|
|
|
|
export class GitServiceImpl implements GitService { |
|
|
export class GitServiceImpl implements GitService { |
|
|
private readonly coreGitService: codeCore.git.GitService; |
|
|
private readonly coreGitService: codeCore.git.GitService; |
|
|
|
|
|
|
|
@@ -16,13 +21,13 @@ export class GitServiceImpl implements GitService { |
|
|
if (user) { |
|
|
if (user) { |
|
|
return this.coreGitService.create(options, user); |
|
|
return this.coreGitService.create(options, user); |
|
|
} |
|
|
} |
|
|
throw new Error('Unauthorized'); |
|
|
|
|
|
|
|
|
throw new UnableToCreateRepoError('Unauthorized'); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
async deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> { |
|
|
async deleteRepo(repoId: codeCore.git.Repo['id'], user?: codeCore.common.User): Promise<void> { |
|
|
if (user) { |
|
|
if (user) { |
|
|
await this.coreGitService.delete(repoId, user); |
|
|
await this.coreGitService.delete(repoId, user); |
|
|
} |
|
|
} |
|
|
throw new Error('Unauthorized'); |
|
|
|
|
|
|
|
|
throw new UnableToDeleteRepoError('Unauthorized'); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |