Skip to content

Commit 784fde4

Browse files
fixed stars count bug
1 parent 9314522 commit 784fde4

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

src/apis/apis.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export class APIService {
1717
'https://api.github.com/graphql',
1818
{
1919
query: "query GetUserDetails($username: String!) { user(login: $username)" +
20-
"{ name login followers { totalCount } repositories(first: 3, orderBy: {field: STARGAZERS, direction: DESC})" +
21-
"{ nodes { name stargazerCount } totalCount } } } }",
20+
"{ name login followers { totalCount } repositories(first: 100, orderBy: {field: STARGAZERS, direction: DESC})" +
21+
"{ nodes { name stargazerCount } } } } }",
2222
variables: {
2323
username: username
2424
}
@@ -31,8 +31,11 @@ export class APIService {
3131

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

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

3841

src/apis/types.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ interface GithubRepos {
1111
name: string,
1212
stargazerCount: number
1313

14-
}[],
15-
totalCount: number
14+
}[]
1615
}
1716
}
18-
}
17+
},
18+
total_stars: number
1919
}
2020

2121
interface GithubStreak {

src/widget/widget.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export class WidgetService {
6161
this.apiService.getActivity(process.env.ACTIVITY_API, process.env.ACTIVITY_ID)
6262
]);
6363

64-
const top_repos = github_data.data.user?.repositories?.nodes?.reduce((acc, value) => {
64+
const top_repos = github_data.data.user?.repositories?.nodes?.slice(0, 3)?.reduce((acc, value) => {
6565
const el = { [value.name]: value.stargazerCount };
6666
acc = { ...acc, ...el };
6767
return acc;
@@ -78,7 +78,7 @@ export class WidgetService {
7878
description: process.env.DESCRIPTION,
7979
github: {
8080
followers: github_data.data.user?.followers?.totalCount ?? null,
81-
total_stars: github_data.data.user?.repositories?.totalCount ?? null,
81+
total_stars: github_data?.total_stars ?? null,
8282
top_repos: top_repos ?? null,
8383
streak: streak ? {
8484
current: streak.streak,

0 commit comments

Comments
 (0)