Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

83 changes: 83 additions & 0 deletions public/mock-data/enterprise_seats_response_sample.json.backup
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"total_seats": 3,
"seats": [
{
"created_at": "2021-08-03T18:00:00-06:00",
"updated_at": "2021-09-23T15:00:00-06:00",
"pending_cancellation_date": null,
"last_activity_at": "2021-10-14T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octocat_byEnterprise",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"assigning_team": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Justice League",
"slug": "justice-league",
"description": "A great team.",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
},
{
"created_at": "2021-09-23T18:00:00-06:00",
"updated_at": "2021-09-23T15:00:00-06:00",
"pending_cancellation_date": "2021-11-01",
"last_activity_at": "2021-10-13T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octokitten",
"id": 1,
"node_id": "MDQ76VNlcjE=",
"avatar_url": "https://github.com/images/error/octokitten_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octokitten",
"html_url": "https://github.com/octokitten",
"followers_url": "https://api.github.com/users/octokitten/followers",
"following_url": "https://api.github.com/users/octokitten/following{/other_user}",
"gists_url": "https://api.github.com/users/octokitten/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokitten/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octokitten/subscriptions",
"organizations_url": "https://api.github.com/users/octokitten/orgs",
"repos_url": "https://api.github.com/users/octokitten/repos",
"events_url": "https://api.github.com/users/octokitten/events{/privacy}",
"received_events_url": "https://api.github.com/users/octokitten/received_events",
"type": "User",
"site_admin": false
}
},
{
"created_at": "2021-09-23T18:00:00-06:00",
"updated_at": "2021-09-23T15:00:00-06:00",
"pending_cancellation_date": "2021-11-01",
"last_activity_at": "2021-10-12T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": null,
"assigning_team": null
}
]
}
173 changes: 173 additions & 0 deletions public/mock-data/enterprise_seats_with_duplicates.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
{
"total_seats": 2,
"seats": [
{
"created_at": "2021-08-03T18:00:00-06:00",
"updated_at": "2021-09-23T15:00:00-06:00",
"pending_cancellation_date": null,
"last_activity_at": "2021-10-14T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"assigning_team": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Team Alpha",
"slug": "team-alpha",
"description": "A great team.",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
},
{
"created_at": "2021-08-03T18:00:00-06:00",
"updated_at": "2021-09-23T15:00:00-06:00",
"pending_cancellation_date": null,
"last_activity_at": "2021-10-16T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octocat",
"id": 1,
"node_id": "MDQ6VXNlcjE=",
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octocat",
"html_url": "https://github.com/octocat",
"followers_url": "https://api.github.com/users/octocat/followers",
"following_url": "https://api.github.com/users/octocat/following{/other_user}",
"gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
"organizations_url": "https://api.github.com/users/octocat/orgs",
"repos_url": "https://api.github.com/users/octocat/repos",
"events_url": "https://api.github.com/users/octocat/events{/privacy}",
"received_events_url": "https://api.github.com/users/octocat/received_events",
"type": "User",
"site_admin": false
},
"assigning_team": {
"id": 2,
"node_id": "MDQ6VGVhbTI=",
"url": "https://api.github.com/teams/2",
"html_url": "https://github.com/orgs/github/teams/beta-team",
"name": "Team Beta",
"slug": "team-beta",
"description": "Another great team.",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"permission": "admin",
"members_url": "https://api.github.com/teams/2/members{/member}",
"repositories_url": "https://api.github.com/teams/2/repos",
"parent": null
}
},
{
"created_at": "2021-08-04T18:00:00-06:00",
"updated_at": "2021-09-24T15:00:00-06:00",
"pending_cancellation_date": null,
"last_activity_at": "2021-10-13T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octokitten",
"id": 2,
"node_id": "MDQ76VNlcjI=",
"avatar_url": "https://github.com/images/error/octokitten_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octokitten",
"html_url": "https://github.com/octokitten",
"followers_url": "https://api.github.com/users/octokitten/followers",
"following_url": "https://api.github.com/users/octokitten/following{/other_user}",
"gists_url": "https://api.github.com/users/octokitten/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokitten/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octokitten/subscriptions",
"organizations_url": "https://api.github.com/users/octokitten/orgs",
"repos_url": "https://api.github.com/users/octokitten/repos",
"events_url": "https://api.github.com/users/octokitten/events{/privacy}",
"received_events_url": "https://api.github.com/users/octokitten/received_events",
"type": "User",
"site_admin": false
},
"assigning_team": {
"id": 1,
"node_id": "MDQ6VGVhbTE=",
"url": "https://api.github.com/teams/1",
"html_url": "https://github.com/orgs/github/teams/justice-league",
"name": "Team Alpha",
"slug": "team-alpha",
"description": "A great team.",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"permission": "admin",
"members_url": "https://api.github.com/teams/1/members{/member}",
"repositories_url": "https://api.github.com/teams/1/repos",
"parent": null
}
},
{
"created_at": "2021-08-04T18:00:00-06:00",
"updated_at": "2021-09-24T15:00:00-06:00",
"pending_cancellation_date": null,
"last_activity_at": "2021-10-15T00:53:32-06:00",
"last_activity_editor": "vscode/1.77.3/copilot/1.86.82",
"assignee": {
"login": "octokitten",
"id": 2,
"node_id": "MDQ76VNlcjI=",
"avatar_url": "https://github.com/images/error/octokitten_happy.gif",
"gravatar_id": "",
"url": "https://api.github.com/users/octokitten",
"html_url": "https://github.com/octokitten",
"followers_url": "https://api.github.com/users/octokitten/followers",
"following_url": "https://api.github.com/users/octokitten/following{/other_user}",
"gists_url": "https://api.github.com/users/octokitten/gists{/gist_id}",
"starred_url": "https://api.github.com/users/octokitten/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/octokitten/subscriptions",
"organizations_url": "https://api.github.com/users/octokitten/orgs",
"repos_url": "https://api.github.com/users/octokitten/repos",
"events_url": "https://api.github.com/users/octokitten/events{/privacy}",
"received_events_url": "https://api.github.com/users/octokitten/received_events",
"type": "User",
"site_admin": false
},
"assigning_team": {
"id": 2,
"node_id": "MDQ6VGVhbTI=",
"url": "https://api.github.com/teams/2",
"html_url": "https://github.com/orgs/github/teams/beta-team",
"name": "Team Beta",
"slug": "team-beta",
"description": "Another great team.",
"privacy": "closed",
"notification_setting": "notifications_enabled",
"permission": "admin",
"members_url": "https://api.github.com/teams/2/members{/member}",
"repositories_url": "https://api.github.com/teams/2/repos",
"parent": null
}
}
]
}
43 changes: 40 additions & 3 deletions server/api/seats.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,39 @@
import { Seat } from "@/model/Seat";
import type FetchError from 'ofetch';
import { readFileSync } from 'fs';
import { resolve } from 'path';

/**
* Deduplicates seats by user ID, keeping the seat with the most recent activity.
* This handles enterprise scenarios where users are assigned to multiple organizations.
* @param seats Array of seats to deduplicate
* @returns Array of unique seats
*/
function deduplicateSeats(seats: Seat[]): Seat[] {
const uniqueSeats = new Map<number, Seat>();

for (const seat of seats) {
// Skip seats with invalid user ID
if (!seat.id || seat.id === 0) {
continue;
}

const existingSeat = uniqueSeats.get(seat.id);
if (!existingSeat) {
uniqueSeats.set(seat.id, seat);
} else {
// Keep the seat with more recent activity, treating null as earliest date
const seatActivity = seat.last_activity_at || '1970-01-01T00:00:00Z';
const existingActivity = existingSeat.last_activity_at || '1970-01-01T00:00:00Z';

if (seatActivity > existingActivity) {
uniqueSeats.set(seat.id, seat);
}
}
}

return Array.from(uniqueSeats.values());
}

export default defineEventHandler(async (event) => {

const logger = console;
Expand All @@ -29,9 +60,12 @@ export default defineEventHandler(async (event) => {
const data = readFileSync(path, 'utf8');
const dataJson = JSON.parse(data);
const seatsData = dataJson.seats.map((item: unknown) => new Seat(item));

// Deduplicate seats by user ID to handle enterprise scenarios where users are assigned to multiple organizations
const deduplicatedSeats = deduplicateSeats(seatsData);

logger.info('Using mocked data');
return seatsData;
return deduplicatedSeats;
}

if (!event.context.headers.has('Authorization')) {
Expand Down Expand Up @@ -76,5 +110,8 @@ export default defineEventHandler(async (event) => {
seatsData = seatsData.concat(response.seats.map((item: unknown) => new Seat(item)));
}

return seatsData;
// Deduplicate seats by user ID to handle enterprise scenarios where users are assigned to multiple organizations
const deduplicatedSeats = deduplicateSeats(seatsData);

return deduplicatedSeats;
})
Loading
Loading