diff --git a/supabase/functions/process_scheduled_notifications/index.ts b/supabase/functions/process_scheduled_notifications/index.ts index acbaeefb..e14588c0 100644 --- a/supabase/functions/process_scheduled_notifications/index.ts +++ b/supabase/functions/process_scheduled_notifications/index.ts @@ -197,6 +197,33 @@ async function processBatch() { data.navigate_to = '/announcements' break } + case 'day_sheet_digest': { + const { count, error: countErr } = await supabase + .from('programmer_day_sheets') + .select('id', { count: 'exact', head: true }) + .eq('status', 'pending') + + if (countErr) { + console.error('Failed to count pending day sheets', countErr) + throw countErr + } + + const n = count ?? 0 + if (n === 0) { + // No pending sheets; mark processed and skip sending + await supabase + .from('scheduled_notifications') + .update({ processed: true, processed_at: new Date().toISOString() }) + .eq('id', rowId) + console.log('Day sheet digest: no pending sheets, skipped', rowId) + continue + } + + title = 'Day sheets awaiting review' + body = `${n} day sheet${n === 1 ? ' is' : 's are'} awaiting your review.` + data.navigate_to = '/programmer-tasks?tab=approvals' + break + } default: title = 'Reminder' body = 'You have a pending notification.'