Skip to content

Commit 31f26b9

Browse files
Added the proper types to the github endpoint function
1 parent b939ee9 commit 31f26b9

File tree

1 file changed

+31
-3
lines changed

1 file changed

+31
-3
lines changed

src/routes/api/github/index.json.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,32 @@ const GITHUB_USER_REPO_ENDPOINT = environment.gitHubConfig.GITHUB_USER_REPO_ENDP
99
: 'https://api.github.com/users/navneetsharmaui/repos?per_page=100';
1010

1111
/** @type {import('@sveltejs/kit').RequestHandler} */
12-
export async function get({ query }) {
12+
export async function get({
13+
query,
14+
}: {
15+
query: URLSearchParams;
16+
}): Promise<
17+
| {
18+
status: number;
19+
headers?: {
20+
[key: string]: string;
21+
};
22+
body?: {
23+
followers: unknown;
24+
stars: unknown;
25+
};
26+
}
27+
| {
28+
status: number;
29+
headers?: {
30+
[key: string]: string;
31+
};
32+
body: {
33+
followers: unknown;
34+
stars: unknown;
35+
};
36+
}
37+
> {
1338
const limit = Number(query.get('limit') ?? 10);
1439

1540
if (Number.isNaN(limit)) {
@@ -24,8 +49,11 @@ export async function get({ query }) {
2449
const user = await githubUser.json();
2550
const allRespos = await githubUserRepos.json();
2651

27-
const reposWithoutFork = allRespos.filter((repo) => !repo.fork);
28-
const stars = reposWithoutFork.reduce((accumulator, repo) => accumulator + repo['stargazers_count'], 0);
52+
const reposWithoutFork = allRespos.filter((repo: { fork: unknown }) => !repo.fork);
53+
const stars = reposWithoutFork.reduce(
54+
(accumulator: unknown, repo: { [x: string]: unknown }) => `${accumulator} ${repo['stargazers_count']}`,
55+
0,
56+
);
2957
return {
3058
status: 200,
3159
headers: {

0 commit comments

Comments
 (0)