implemented pagination

This commit is contained in:
2024-01-10 15:53:46 +01:00
parent c0e4c364d4
commit ccb628aadb
4 changed files with 191 additions and 22 deletions

View File

@@ -89,22 +89,23 @@ export const updateOrAddLocation = withUser(async (user:AuthenticatedUser, locat
});
export const fetchAllLocations = withUser(async (user:AuthenticatedUser, pageIx:number=0, pageSize:number=2000) => {
export const fetchAllLocations = withUser(async (user:AuthenticatedUser, year:number) => {
const dbClient = await getDbClient();
const { id: userId } = user;
// fetch `pageSize` locations for the given page index
// fetch all locations for the given year
const locations = await dbClient.collection<BillingLocation>("lokacije")
.find({ userId })
.find({
userId,
"yearMonth.year": year,
})
.sort({
"yearMonth.year": -1,
"yearMonth.month": -1,
name: 1,
})
.skip(pageIx * pageSize)
.limit(pageSize)
.toArray();
return(locations);