"use server"; import { revalidatePath } from "next/cache"; import { auth } from "@/auth"; import { prisma } from "@/lib/db/prisma"; import { markAllNotificationsRead, markNotificationRead } from "@/services/notifications/notification.service"; export interface MarkReadActionResult { success: boolean; error?: string; } /** * Shared across all three notification-centre pages (customer/staff/owner) * — ownership is enforced by recipientUserId matching the session, exactly * the same rule regardless of which role is asking (see * NotificationService.markNotificationRead's own scoped WHERE clause), so * one action file covers all of them rather than three near-identical * copies. */ export async function markNotificationReadAction(notificationId: string): Promise { const session = await auth(); if (!session?.user) return { success: false, error: "You must be signed in." }; await markNotificationRead(prisma, { notificationId, userId: session.user.id }); revalidatePath("/notifications"); revalidatePath("/staff/notifications"); revalidatePath("/owner/notifications"); return { success: true }; } export async function markAllNotificationsReadAction(): Promise { const session = await auth(); if (!session?.user) return { success: false, error: "You must be signed in." }; await markAllNotificationsRead(prisma, session.user.id); revalidatePath("/notifications"); revalidatePath("/staff/notifications"); revalidatePath("/owner/notifications"); return { success: true }; }