diff --git a/api/client/users.ts b/api/client/users.ts new file mode 100644 index 000000000..a794d5306 --- /dev/null +++ b/api/client/users.ts @@ -0,0 +1,35 @@ +// +// Copyright (c) Microsoft. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +import { NextFunction, Response, Router } from 'express'; +import asyncHandler from 'express-async-handler'; + +import { ReposAppRequest, AccountJsonFormat } from '../../interfaces'; +import { CreateError, getProviders } from '../../transitional'; + +const router: Router = Router(); + +router.get( + '/:login', + asyncHandler(async (req: ReposAppRequest, res: Response, next: NextFunction) => { + const { operations } = getProviders(req); + const login = req.params.login as string; + try { + if (!login) { + throw CreateError.ParameterRequired('login'); + } + const accountInfo = await operations.getAccountByUsername(login); + return res.json(accountInfo.asJson(AccountJsonFormat.GitHubExtended)) as any as void; + } catch (error) { + return next(error); + } + }) +); + +router.use('*', (req, res: Response, next: NextFunction) => { + return next(CreateError.NotFound('/users: no API found')); +}); + +export default router; diff --git a/business/repositoryInvitation.ts b/business/repositoryInvitation.ts new file mode 100644 index 000000000..449774cbb --- /dev/null +++ b/business/repositoryInvitation.ts @@ -0,0 +1,77 @@ +// +// Copyright (c) Microsoft. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. +// + +import { GitHubRepositoryPermission, GitHubSimpleAccount } from '../interfaces'; +import * as common from './common'; +import { Repository } from './repository'; + +const primaryProperties = ['inviter', 'invitee', 'permissions', 'created_at', 'html_url', 'node_id']; + +export type RepositoryInvitationClientJson = { + inviter: { + id: number; + login: string; + }; + invitee: { + id: number; + login: string; + }; + permissions: GitHubRepositoryPermission; + created_at: string; + html_url: string; + // node_id: string; +}; + +export class RepositoryInvitation { + public static PrimaryProperties = primaryProperties; + + private _inviter: GitHubSimpleAccount; + private _invitee: GitHubSimpleAccount; + private _permissions: GitHubRepositoryPermission; + private _html_url: string; + private _created_at: string; + + constructor( + private repository: Repository, + entity: unknown + ) { + if (entity) { + common.assignKnownFieldsPrefixed(this, entity, 'invitation', primaryProperties); + } + } + + asJson(): RepositoryInvitationClientJson { + return { + invitee: this.invitee, + inviter: this.inviter, + permissions: this.permission, + html_url: this.invitationUrl, + created_at: this._created_at, + }; + } + + get permission(): GitHubRepositoryPermission { + return this._permissions; + } + + // getHighestPermission() { + // if (!this._permissions) { + // return GitHubRepositoryPermission.None; + // } + // return projectCollaboratorPermissionsObjectToGitHubRepositoryPermission(this._permissions); + // } + + get inviter(): GitHubSimpleAccount { + return this._inviter; + } + + get invitee(): GitHubSimpleAccount { + return this._invitee; + } + + get invitationUrl(): string { + return this._html_url; + } +}