@@ -19,7 +19,7 @@ import { LibrarySelector } from '@/components/dashboard/LibrarySelector'
1919import { DateRangeSelector } from '@/components/dashboard/DateRangeSelector'
2020import { IsLoggedIn } from '@/lib/firebase/firebase'
2121import { redirect , RedirectType } from 'next/navigation'
22- import { format , subMonths , parse } from 'date-fns'
22+ import { format , subMonths , parse , startOfDay , endOfDay } from 'date-fns'
2323import { getListLibraries } from '@/lib/api/library'
2424import { DateRange } from 'react-day-picker'
2525
@@ -41,14 +41,6 @@ export default async function DashboardPage({
4141 const claims = await IsLoggedIn ( )
4242 if ( ! claims ) redirect ( '/login?from=/dashboard' )
4343
44- const {
45- library_id,
46- from,
47- to,
48- // limit = 5,
49- // skip,
50- } = await searchParams
51-
5244 if (
5345 claims . librarease . role === 'USER' &&
5446 ! claims . librarease . admin_libs . length &&
@@ -57,10 +49,12 @@ export default async function DashboardPage({
5749 redirect ( '/' , RedirectType . replace )
5850 }
5951
52+ const { library_id, from, to, limit = 5 , skip = 0 } = await searchParams
53+
6054 if ( ! to || ! from ) {
6155 const now = new Date ( )
6256 const to = format ( now , 'dd-MM-yyyy' )
63- const from = format ( subMonths ( now , 4 ) , 'dd-MM-yyyy' )
57+ const from = format ( subMonths ( now , 1 ) , 'dd-MM-yyyy' )
6458 const libID = claims . librarease . admin_libs . concat (
6559 claims . librarease . staff_libs
6660 )
@@ -76,10 +70,10 @@ export default async function DashboardPage({
7670
7771 const [ res , libsRes ] = await Promise . all ( [
7872 getAnalysis ( {
79- skip : 0 ,
80- limit : 5 ,
81- from : parse ( from , 'dd-MM-yyyy' , new Date ( ) ) . toJSON ( ) ,
82- to : parse ( to , 'dd-MM-yyyy' , new Date ( ) ) . toJSON ( ) ,
73+ skip,
74+ limit,
75+ from : startOfDay ( parse ( from , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
76+ to : endOfDay ( parse ( to , 'dd-MM-yyyy' , new Date ( ) ) ) . toJSON ( ) ,
8377 library_id,
8478 } ) ,
8579 getListLibraries ( { limit : 5 } ) ,
0 commit comments