From 051a7f86d3fee61148b9c4d3ac86a1dea04a8d01 Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Mon, 10 Nov 2025 23:56:12 +0000 Subject: [PATCH] Backend notification utility for API endpoints cgen-c20fbebfac0d48579acc57e96d0f6700 --- api/_notifications.ts | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 api/_notifications.ts diff --git a/api/_notifications.ts b/api/_notifications.ts new file mode 100644 index 00000000..bae5517a --- /dev/null +++ b/api/_notifications.ts @@ -0,0 +1,39 @@ +import { getAdminClient } from "./_supabase"; + +export async function createNotification( + userId: string, + type: string, + title: string, + message: string, +): Promise { + try { + const admin = getAdminClient(); + await admin.from("notifications").insert({ + user_id: userId, + type, + title, + message, + }); + } catch (error) { + console.warn("Failed to create notification:", error); + // Non-blocking - don't throw + } +} + +export async function notifyAccountLinked(userId: string, provider: string): Promise { + await createNotification( + userId, + "success", + `🔗 Account Linked: ${provider}`, + `Your ${provider} account has been successfully linked.`, + ); +} + +export async function notifyOnboardingComplete(userId: string): Promise { + await createNotification( + userId, + "success", + "🎉 Welcome to AeThex!", + "You've completed your profile setup. Let's get started!", + ); +}