mirror of
https://github.com/ae-utbm/sith.git
synced 2025-03-10 07:17:11 +00:00
Fix paginated TS interfaces
This commit is contained in:
parent
d284bea0eb
commit
58b7566e8f
@ -1,4 +1,4 @@
|
|||||||
import type { Client, Options, RequestResult } from "@hey-api/client-fetch";
|
import type { Client, Options, RequestResult, TDataShape } from "@hey-api/client-fetch";
|
||||||
import { client } from "#openapi";
|
import { client } from "#openapi";
|
||||||
|
|
||||||
export interface PaginatedResponse<T> {
|
export interface PaginatedResponse<T> {
|
||||||
@ -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;
|
||||||
@ -53,8 +54,9 @@ export const paginated = async <T>(
|
|||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
|
|
||||||
interface Request {
|
interface Request extends TDataShape {
|
||||||
client?: Client;
|
client?: Client;
|
||||||
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface InterceptorOptions {
|
interface InterceptorOptions {
|
||||||
|
@ -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;
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
|
@ -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/*"],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user