diff --git a/apps/dashboard/src/lib/utils/services/newsfeed/index.ts b/apps/dashboard/src/lib/utils/services/newsfeed/index.ts index 3ff927bf..f72d87a2 100644 --- a/apps/dashboard/src/lib/utils/services/newsfeed/index.ts +++ b/apps/dashboard/src/lib/utils/services/newsfeed/index.ts @@ -109,8 +109,12 @@ export async function deleteNewsFeed(feedId: string) { return response; } -export async function getFeedForNotification(feedId: string, authorId: string) { - const { data, error } = await supabase +export async function getFeedForNotification(params: { + feedId: string; + authorId: string; + supabase: typeof supabase; +}) { + const { data, error } = await params.supabase .from('course_newsfeed') .select( ` @@ -126,7 +130,7 @@ export async function getFeedForNotification(feedId: string, authorId: string) { ) ` ) - .eq('id', feedId) + .eq('id', params.feedId) .limit(1) .returns< { @@ -169,7 +173,7 @@ export async function getFeedForNotification(feedId: string, authorId: string) { if (!feed) return; return { - id: feedId, + id: params.feedId, courseId: feed.course.id, courseTitle: feed.course.title, teacherName: feed.author?.profile?.fullname, @@ -177,7 +181,7 @@ export async function getFeedForNotification(feedId: string, authorId: string) { content: feed.content, org: feed.course.group?.organization, courseMembers: feed.course?.group?.members - ?.filter((member) => member.id !== authorId) + ?.filter((member) => member.id !== params.authorId) ?.map((member) => { return member.profile; }) diff --git a/apps/dashboard/src/routes/api/email/course/newsfeed/+server.ts b/apps/dashboard/src/routes/api/email/course/newsfeed/+server.ts index 47e190e8..d05c48bb 100644 --- a/apps/dashboard/src/routes/api/email/course/newsfeed/+server.ts +++ b/apps/dashboard/src/routes/api/email/course/newsfeed/+server.ts @@ -1,12 +1,17 @@ import { json } from '@sveltejs/kit'; -import { getSupabase } from '$lib/utils/functions/supabase'; +import { getServerSupabase } from '$lib/utils/functions/supabase.server'; import { getFeedForNotification } from '$lib/utils/services/newsfeed/index'; import sendEmail from '$mail/sendEmail'; -const supabase = getSupabase(); +const supabase = getServerSupabase(); const sendEmailNotification = async (feedId: string, authorId: string, comment?: string) => { - const feed = await getFeedForNotification(feedId, authorId); + const feed = await getFeedForNotification({ + supabase, + feedId, + authorId + }); + console.log({ feed }); if (!feed) return; const postLink = `https://${feed.org.siteName}.classroomio.com/courses/${feed.courseId}?feedId=${feed.id}`;