From 34169eda41cfe782f4184f2a4ea6833d7f947b0d Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Sat, 18 Oct 2025 02:40:51 +0000 Subject: [PATCH] Add invites and rewards helpers to social service cgen-8af11d03f25543e2b996068c92e092c9 --- client/lib/aethex-social-service.ts | 42 +++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/client/lib/aethex-social-service.ts b/client/lib/aethex-social-service.ts index f0294bbb..36659d05 100644 --- a/client/lib/aethex-social-service.ts +++ b/client/lib/aethex-social-service.ts @@ -62,4 +62,46 @@ export const aethexSocialService = { throw new Error(error.message || "Unable to unfollow user"); } }, + + async sendInvite(inviterId: string, email: string, message?: string | null) { + const resp = await fetch("/api/invites", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ inviter_id: inviterId, invitee_email: email, message }), + }); + if (!resp.ok) { + const err = await resp.text(); + throw new Error(err || "Failed to send invite"); + } + return (await resp.json()) as { ok: boolean; inviteUrl: string; token: string }; + }, + + async listInvites(inviterId: string) { + const resp = await fetch(`/api/invites?inviter_id=${encodeURIComponent(inviterId)}`); + if (!resp.ok) return []; + return await resp.json(); + }, + + async acceptInvite(token: string, acceptorId: string) { + const resp = await fetch("/api/invites/accept", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ token, acceptor_id: acceptorId }), + }); + if (!resp.ok) { + const err = await resp.text(); + throw new Error(err || "Failed to accept invite"); + } + return await resp.json(); + }, + + async applyReward(userId: string, action: string, amount?: number) { + const resp = await fetch("/api/rewards/apply", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ user_id: userId, action, amount }), + }); + if (!resp.ok) return false; + return true; + }, };