Skip to content

Commit

Permalink
+missing merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffwilcox committed Oct 6, 2023
1 parent e55f5ca commit 676d7b5
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
35 changes: 35 additions & 0 deletions api/client/users.ts
Original file line number Diff line number Diff line change
@@ -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;
77 changes: 77 additions & 0 deletions business/repositoryInvitation.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 676d7b5

Please sign in to comment.