-
Notifications
You must be signed in to change notification settings - Fork 0
/
Organization.ts
39 lines (31 loc) · 1.08 KB
/
Organization.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { components } from '@octokit/openapi-types';
import { ListModel, Stream, toggle } from 'mobx-restful';
import { buildURLData } from 'web-utility';
import { githubClient } from './client';
export type Organization = components['schemas']['organization'];
export class OrganizationModel extends Stream<Organization>(ListModel) {
client = githubClient;
baseURI = 'orgs';
async *openStream() {
var per_page = this.pageSize,
since: number | undefined,
count = 0;
while (true) {
const { body } = await this.client.get<Organization[]>(
`user/${this.baseURI}?${buildURLData({ per_page, since })}`
);
if (!body![0]) break;
since = body![0].id;
count += body!.length;
yield* body!;
if (body!.length < this.pageSize) break;
}
this.totalCount = count;
}
@toggle('downloading')
async getOne(name: string) {
return this.currentOne.login === name
? this.currentOne
: super.getOne(name);
}
}