@@ -11,37 +11,17 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
11
11
let seatsData : Seat [ ] = [ ] ;
12
12
13
13
let response ;
14
- if ( process . env . VUE_APP_MOCKED_DATA === "true" ) {
15
- if ( process . env . VUE_APP_SCOPE === "organization" ) {
14
+ if ( process . env . VUE_APP_SCOPE !== "organization" ) {
15
+ // when the scope is not organization, return seatsData,by default it will return empty array
16
+ return seatsData ;
17
+ }
18
+ else {
19
+ if ( process . env . VUE_APP_MOCKED_DATA === "true" ) {
16
20
response = organizationMockedResponse_seats ;
17
- } else if ( process . env . VUE_APP_SCOPE === "enterprise" ) {
18
- response = enterpriseMockedResponse_seats ;
19
- } else {
20
- throw new Error ( `Invalid VUE_APP_SCOPE value: ${ process . env . VUE_APP_SCOPE } . Expected "organization" or "enterprise".` ) ;
21
- }
22
- seatsData = response . seats . map ( ( item : any ) => new Seat ( item ) ) ;
23
- } else {
24
- // Fetch the first page
25
- response = await axios . get ( `https://api.github.com/orgs/${ process . env . VUE_APP_GITHUB_ORG } /copilot/billing/seats` , {
26
- headers : {
27
- Accept : "application/vnd.github+json" ,
28
- Authorization : `Bearer ${ process . env . VUE_APP_GITHUB_TOKEN } ` ,
29
- "X-GitHub-Api-Version" : "2022-11-28" ,
30
- } ,
31
- params : {
32
- per_page : perPage ,
33
- page : page
34
- }
35
- } ) ;
36
-
37
- seatsData = seatsData . concat ( response . data . seats . map ( ( item : any ) => new Seat ( item ) ) ) ;
38
-
39
- // Calculate the total pages
40
- const totalSeats = response . data . total_seats ;
41
- const totalPages = Math . ceil ( totalSeats / perPage ) ;
42
-
43
- // Fetch the remaining pages
44
- for ( page = 2 ; page <= totalPages ; page ++ ) {
21
+ seatsData = seatsData . concat ( response . seats . map ( ( item : any ) => new Seat ( item ) ) ) ;
22
+ }
23
+ else if ( process . env . VUE_APP_MOCKED_DATA === "false" ) {
24
+ // Fetch the first page to get the total number of seats
45
25
response = await axios . get ( `https://api.github.com/orgs/${ process . env . VUE_APP_GITHUB_ORG } /copilot/billing/seats` , {
46
26
headers : {
47
27
Accept : "application/vnd.github+json" ,
@@ -55,8 +35,27 @@ export const getSeatsApi = async (): Promise<Seat[]> => {
55
35
} ) ;
56
36
57
37
seatsData = seatsData . concat ( response . data . seats . map ( ( item : any ) => new Seat ( item ) ) ) ;
58
- }
59
- }
60
-
38
+ // Calculate the total pages
39
+ const totalSeats = response . data . total_seats ;
40
+ const totalPages = Math . ceil ( totalSeats / perPage ) ;
41
+
42
+ // Fetch the remaining pages
43
+ for ( page = 2 ; page <= totalPages ; page ++ ) {
44
+ response = await axios . get ( `https://api.github.com/orgs/${ process . env . VUE_APP_GITHUB_ORG } /copilot/billing/seats` , {
45
+ headers : {
46
+ Accept : "application/vnd.github+json" ,
47
+ Authorization : `Bearer ${ process . env . VUE_APP_GITHUB_TOKEN } ` ,
48
+ "X-GitHub-Api-Version" : "2022-11-28" ,
49
+ } ,
50
+ params : {
51
+ per_page : perPage ,
52
+ page : page
53
+ }
54
+ } ) ;
55
+
56
+ seatsData = seatsData . concat ( response . data . seats . map ( ( item : any ) => new Seat ( item ) ) ) ;
57
+ } //end of else if (process.env.VUE_APP_MOCKED_DATA === "false")
58
+ } //end of else if (process.env.VUE_APP_SCOPE !== "organization")
61
59
return seatsData ;
60
+ }
62
61
}
0 commit comments