feat: complete dashboard mvp

This commit is contained in:
Rotimi Best
2023-10-22 09:47:13 +01:00
parent 5c8571e571
commit 5e9c5ba545
19 changed files with 241 additions and 246 deletions
+28 -6
View File
@@ -1,19 +1,41 @@
import type { UserLessonDataType } from '$lib/utils/types';
import { supabase } from '$lib/utils/functions/supabase';
function getFirstAndLastDayOfMonth(): { firstDay: string; lastDay: string } {
const date = new Date();
const year = date.getFullYear();
const month = date.getMonth();
// Create a date object for the first day of the month
const firstDay = new Date(year, month, 1).toISOString();
// Find the last day of the next month and subtract one day to get the last day of the current month
const nextMonth: any = new Date(year, month + 1, 1);
const lastDay = new Date(nextMonth - 1).toISOString();
return {
firstDay,
lastDay
};
}
export async function fetchUserUpcomingData(
profileId: string | null
profileId: string | null,
orgId: string
): Promise<UserLessonDataType[] | []> {
if (!profileId) {
return [];
}
const { data: userUpcomingData } = await supabase.rpc(
'get_user_upcoming_lessons',
{
const { lastDay, firstDay } = getFirstAndLastDayOfMonth();
const { data: userUpcomingData } = await supabase
.rpc('get_user_upcoming_lessons', {
profile_id_arg: profileId,
}
);
org_id_arg: orgId
})
.filter('lesson_at', 'gte', firstDay)
.filter('lesson_at', 'lte', lastDay);
console.log(`userUpcomingData`, userUpcomingData);