Files
web-core/src/api/query.ts
Beatrice Dellacà cbabf43584
All checks were successful
continuous-integration/drone/push Build is passing
update prettier
2026-02-23 14:23:46 +01:00

30 lines
638 B
TypeScript

type BuildListQueryOptions = {
q?: string;
page?: number;
pageSize?: number;
sort?: string;
defaultSort: string;
};
export function buildListQuery({
q,
page = 1,
pageSize = 10,
sort,
defaultSort,
}: BuildListQueryOptions): string {
const query = new URLSearchParams();
const normalizedQuery = q?.trim();
const normalizedSort = sort?.trim();
if (normalizedQuery) {
query.set('q', normalizedQuery);
}
query.set('page', String(page));
query.set('pageSize', String(pageSize));
query.set('sort', normalizedSort || defaultSort);
return query.toString();
}