Improved getPaginationLinks readability

This commit is contained in:
Florian Sylvain
2023-02-24 12:53:26 +01:00
parent 904d039308
commit f495ebd5f3
+5 -4
View File
@@ -11,10 +11,11 @@ export const queryPaginationParser = z.object({
})
export function getPaginationLinks(query: Pagination, routeName: string): object {
const nextStart = query.skip + query.take
const prevStart = Math.max(0, query.skip - query.take)
return {
next: `/v1/${routeName}?start=${query.skip + query.take}&per_page=${query.take}`,
prev: `/v1/${routeName}?start=${Math.max(0, query.skip - query.take)}&per_page=${
query.take
}`,
next: `/v1/${routeName}?start=${nextStart}&per_page=${query.take}`,
prev: `/v1/${routeName}?start=${prevStart}&per_page=${query.take}`,
}
}