-
Notifications
You must be signed in to change notification settings - Fork 1
/
getRepoInfo.ts
28 lines (24 loc) · 827 Bytes
/
getRepoInfo.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { RepoInfoTypes as RepoInfoResponse } from "@features/info/types";
import { convertObjectToCamelCase } from "@utils";
import { githubApiService } from "@utils/apiUtils";
type Params = {
username: string;
repo: string;
};
export const repoInfoApi = githubApiService.injectEndpoints({
endpoints: builder => ({
fetchRepoInfo: builder.query<RepoInfoResponse, object>({
query: (params: Params) => {
if (!params.username || !params.repo) {
throw new Error("Invalid params");
}
return `repos/${params.username}/${params.repo}`;
},
transformResponse: (response: RepoInfoResponse) => {
return convertObjectToCamelCase<RepoInfoResponse>(response);
},
}),
}),
overrideExisting: false,
});
export const { useFetchRepoInfoQuery } = repoInfoApi;