Phase 7
This commit is contained in:
189 files changed
+9873
-655
No files matched your search
@@ -0,0 +1,41 @@
|
||||
"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<MarkReadActionResult> {
|
||||
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<MarkReadActionResult> {
|
||||
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 };
|
||||
}
|
||||
Reference in new issue
Block a user