Generic params type to get a record by id from api

This commit is contained in:
Johannes Klein
2026-07-17 13:32:58 +02:00
parent cafe0a49de
commit c5e6d6447c
3 changed files with 9 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
import type { ErrorWithResponse, INatApiError } from "api/error";
import handleError from "api/error";
import type {
ApiDefaultResult, ApiOpts, ApiParams, ApiResponse,
ApiDefaultResult, ApiGetByIdParams, ApiOpts, ApiParams, ApiResponse,
} from "api/types";
import inatjs from "inaturalistjs";
@@ -21,12 +21,8 @@ const fetchBlogPosts = async <T = ApiDefaultResult>(
}
};
interface ProjectPostsParams extends ApiParams {
id: number;
}
const fetchProjectPosts = async <T = ApiDefaultResult>(
params: ProjectPostsParams,
params: ApiGetByIdParams,
opts: ApiOpts = {},
): Promise<ApiResponse<T> | null | ErrorWithResponse | INatApiError> => {
try {
@@ -41,12 +37,8 @@ const fetchProjectPosts = async <T = ApiDefaultResult>(
}
};
interface UserPostsParams extends ApiParams {
id: number;
}
const fetchUserPosts = async <T = ApiDefaultResult>(
params: UserPostsParams,
params: ApiGetByIdParams,
opts: ApiOpts = {},
): Promise<ApiResponse<T> | null | ErrorWithResponse | INatApiError> => {
try {

4
src/api/types.d.ts vendored
View File

@@ -14,6 +14,10 @@ export interface ApiParams {
ttl?: number;
}
export interface ApiGetByIdParams extends ApiParams {
id: number;
}
export interface ApiPlace {
id?: number;
name?: string;

View File

@@ -1,16 +1,12 @@
import type { ErrorWithResponse, INatApiError } from "api/error";
import handleError from "api/error";
import type {
ApiDefaultResult, ApiOpts, ApiParams, ApiResponse,
ApiDefaultResult, ApiGetByIdParams, ApiOpts, ApiResponse,
} from "api/types";
import inatjs from "inaturalistjs";
interface UsersProjectsParams extends ApiParams {
id: number;
}
const fetchUserProjects = async <T = ApiDefaultResult>(
params: UsersProjectsParams,
params: ApiGetByIdParams,
opts: ApiOpts = {},
): Promise<ApiResponse<T> | null | ErrorWithResponse | INatApiError> => {
try {