Fix paginated TS interfaces

This commit is contained in:
Antoine Bartuccio 2025-03-05 17:04:06 +01:00
parent 2d0fd4e3f6
commit 6f39dfc803
3 changed files with 7 additions and 5 deletions

View File

@ -14,6 +14,7 @@ export interface PaginatedRequest {
// biome-ignore lint/style/useNamingConvention: api is in snake_case // biome-ignore lint/style/useNamingConvention: api is in snake_case
page_size?: number; page_size?: number;
}; };
url: string;
} }
type PaginatedEndpoint<T> = <ThrowOnError extends boolean = false>( type PaginatedEndpoint<T> = <ThrowOnError extends boolean = false>(
@ -30,7 +31,7 @@ export const paginated = async <T>(
options?: PaginatedRequest, options?: PaginatedRequest,
): Promise<T[]> => { ): Promise<T[]> => {
const maxPerPage = 199; const maxPerPage = 199;
const queryParams = options ?? {}; const queryParams = options ?? ({} as PaginatedRequest);
queryParams.query = queryParams.query ?? {}; queryParams.query = queryParams.query ?? {};
queryParams.query.page_size = maxPerPage; queryParams.query.page_size = maxPerPage;
queryParams.query.page = 1; queryParams.query.page = 1;
@ -55,6 +56,7 @@ export const paginated = async <T>(
interface Request { interface Request {
client?: Client; client?: Client;
url: string;
} }
interface InterceptorOptions { interface InterceptorOptions {

View File

@ -1,6 +1,7 @@
import { paginated } from "#core:utils/api"; import { paginated } from "#core:utils/api";
import { History, initialUrlParams, updateQueryString } from "#core:utils/history"; import { History, initialUrlParams, updateQueryString } from "#core:utils/history";
import { import {
type AlbumFetchAlbumData,
type AlbumSchema, type AlbumSchema,
type PictureSchema, type PictureSchema,
type PicturesFetchPicturesData, type PicturesFetchPicturesData,
@ -77,7 +78,7 @@ document.addEventListener("alpine:init", () => {
this.albums = await paginated(albumFetchAlbum, { this.albums = await paginated(albumFetchAlbum, {
// biome-ignore lint/style/useNamingConvention: API is snake_case // biome-ignore lint/style/useNamingConvention: API is snake_case
query: { parent_id: this.config.parentId }, query: { parent_id: this.config.parentId },
}); } as AlbumFetchAlbumData);
this.loading = false; this.loading = false;
}, },
})); }));

View File

@ -3,8 +3,8 @@
"outDir": "./staticfiles/generated/bundled/", "outDir": "./staticfiles/generated/bundled/",
"sourceMap": true, "sourceMap": true,
"noImplicitAny": true, "noImplicitAny": true,
"module": "es6", "module": "esnext",
"target": "es6", "target": "es2022",
"allowJs": true, "allowJs": true,
"moduleResolution": "node", "moduleResolution": "node",
"experimentalDecorators": true, "experimentalDecorators": true,
@ -12,7 +12,6 @@
"esModuleInterop": true, "esModuleInterop": true,
"resolveJsonModule": true, "resolveJsonModule": true,
"types": ["jquery", "alpinejs"], "types": ["jquery", "alpinejs"],
"lib": ["es7"],
"paths": { "paths": {
"#openapi": ["./staticfiles/generated/openapi/index.ts"], "#openapi": ["./staticfiles/generated/openapi/index.ts"],
"#core:*": ["./core/static/bundled/*"], "#core:*": ["./core/static/bundled/*"],