fix: remove default sort=-updated from listOne to prevent PocketBase 400 errors
Collections without an 'updated' field (books, user_sessions, user_settings, user_library) were returning 400 because listOne always sent sort=-updated. Changed default to empty string since we only fetch 1 record (no ordering needed).
This commit is contained in:
@@ -197,8 +197,9 @@ async function countCollection(collection: string, filter = ''): Promise<number>
|
|||||||
return (data as { totalItems: number }).totalItems ?? 0;
|
return (data as { totalItems: number }).totalItems ?? 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function listOne<T>(collection: string, filter: string, sort = '-updated'): Promise<T | null> {
|
async function listOne<T>(collection: string, filter: string, sort = ''): Promise<T | null> {
|
||||||
const params = new URLSearchParams({ perPage: '1', filter, sort });
|
const params = new URLSearchParams({ perPage: '1', filter });
|
||||||
|
if (sort) params.set('sort', sort);
|
||||||
const data = await pbGet<PBList<T>>(
|
const data = await pbGet<PBList<T>>(
|
||||||
`/api/collections/${collection}/records?${params.toString()}`
|
`/api/collections/${collection}/records?${params.toString()}`
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user