From 985e2052322d401425ed8ad771f340ced50c51d1 Mon Sep 17 00:00:00 2001 From: nzambello Date: Wed, 1 Mar 2023 01:32:05 +0100 Subject: [PATCH] fix: update duration on save time entry --- app/models/timeEntry.server.ts | 2 +- app/routes/reports.tsx | 12 ++++++------ app/routes/time-entries/$timeEntryId.tsx | 3 +++ 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/app/models/timeEntry.server.ts b/app/models/timeEntry.server.ts index 2e530b0..26c5c73 100644 --- a/app/models/timeEntry.server.ts +++ b/app/models/timeEntry.server.ts @@ -154,7 +154,7 @@ export async function updateDuration(userId: User['id']) { } }); - Promise.all( + return Promise.all( timeEntriesWithoutDuration.map( async (entry) => await prisma.timeEntry.update({ diff --git a/app/routes/reports.tsx b/app/routes/reports.tsx index 3378232..5163f92 100644 --- a/app/routes/reports.tsx +++ b/app/routes/reports.tsx @@ -40,11 +40,11 @@ export async function loader({ request }: LoaderArgs) { const url = new URL(request.url); const dateFrom = url.searchParams.get('dateFrom') - ? dayjs(url.searchParams.get('dateFrom')).toDate() - : dayjs().startOf('month').toDate(); + ? dayjs(url.searchParams.get('dateFrom')).startOf('day').toDate() + : dayjs().startOf('month').startOf('day').toDate(); const dateTo = url.searchParams.get('dateTo') - ? dayjs(url.searchParams.get('dateTo')).toDate() - : dayjs().endOf('month').toDate(); + ? dayjs(url.searchParams.get('dateTo')).endOf('day').toDate() + : dayjs().endOf('month').endOf('day').toDate(); await updateDuration(userId); @@ -62,8 +62,8 @@ export default function ReportPage() { const reports = useFetcher(); const [dateRange, setDateRange] = useState([ - dayjs().startOf('month').toDate(), - dayjs().endOf('month').toDate() + dayjs().startOf('month').startOf('day').toDate(), + dayjs().endOf('month').endOf('day').toDate() ]); useEffect(() => { diff --git a/app/routes/time-entries/$timeEntryId.tsx b/app/routes/time-entries/$timeEntryId.tsx index 5f64b83..576e91b 100644 --- a/app/routes/time-entries/$timeEntryId.tsx +++ b/app/routes/time-entries/$timeEntryId.tsx @@ -35,6 +35,7 @@ import invariant from 'tiny-invariant'; import { deleteTimeEntry, getTimeEntry, + updateDuration, updateTimeEntry } from '~/models/timeEntry.server'; import { requireUserId } from '~/session.server'; @@ -160,6 +161,8 @@ export async function action({ request, params }: ActionArgs) { }); } + updateDuration(userId); + return redirect('/time-entries'); }