Skip to content

Commit

Permalink
fixed stars count bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Andcool-Systems committed Dec 21, 2024
1 parent 9314522 commit 784fde4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
11 changes: 7 additions & 4 deletions src/apis/apis.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ export class APIService {
'https://api.github.com/graphql',
{
query: "query GetUserDetails($username: String!) { user(login: $username)" +
"{ name login followers { totalCount } repositories(first: 3, orderBy: {field: STARGAZERS, direction: DESC})" +
"{ nodes { name stargazerCount } totalCount } } } }",
"{ name login followers { totalCount } repositories(first: 100, orderBy: {field: STARGAZERS, direction: DESC})" +
"{ nodes { name stargazerCount } } } } }",
variables: {
username: username
}
Expand All @@ -31,8 +31,11 @@ export class APIService {

if (response.status !== 200) return null;

await this.cacheManager.set(`repos:${username}`, JSON.stringify(response.data), 1000 * 60 * 60);
return response.data;
const data: GithubRepos = response.data;
data.total_stars = data?.data?.user?.repositories?.nodes?.reduce((acc, node) => acc + node.stargazerCount, 0);

await this.cacheManager.set(`repos:${username}`, JSON.stringify(data), 1000 * 60 * 60);
return data;
}


Expand Down
6 changes: 3 additions & 3 deletions src/apis/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ interface GithubRepos {
name: string,
stargazerCount: number

}[],
totalCount: number
}[]
}
}
}
},
total_stars: number
}

interface GithubStreak {
Expand Down
4 changes: 2 additions & 2 deletions src/widget/widget.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export class WidgetService {
this.apiService.getActivity(process.env.ACTIVITY_API, process.env.ACTIVITY_ID)
]);

const top_repos = github_data.data.user?.repositories?.nodes?.reduce((acc, value) => {
const top_repos = github_data.data.user?.repositories?.nodes?.slice(0, 3)?.reduce((acc, value) => {
const el = { [value.name]: value.stargazerCount };
acc = { ...acc, ...el };
return acc;
Expand All @@ -78,7 +78,7 @@ export class WidgetService {
description: process.env.DESCRIPTION,
github: {
followers: github_data.data.user?.followers?.totalCount ?? null,
total_stars: github_data.data.user?.repositories?.totalCount ?? null,
total_stars: github_data?.total_stars ?? null,
top_repos: top_repos ?? null,
streak: streak ? {
current: streak.streak,
Expand Down

0 comments on commit 784fde4

Please sign in to comment.