implemented pagination
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -76,7 +76,13 @@ export const fetchAvailableYears = withUser(async (user:AuthenticatedUser) => {
|
||||
const dbClient = await getDbClient();
|
||||
|
||||
// query mnogodb for all `yearMonth` values
|
||||
const yearMonths = await dbClient.collection<BillingLocation>("lokacije").distinct("yearMonth.year", { userId });
|
||||
const years = await dbClient.collection<BillingLocation>("lokacije")
|
||||
.distinct("yearMonth.year", { userId })
|
||||
|
||||
return(yearMonths);
|
||||
// sort the years in descending order
|
||||
const sortedYears = years.sort((a, b) => b - a);
|
||||
|
||||
console.log("sortedYears", sortedYears);
|
||||
|
||||
return(sortedYears);
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user