a tool for shared writing and social publishing
1"use server";
2
3import { cookies } from "next/headers";
4import { supabaseServerClient } from "supabase/serverClient";
5
6export async function getRSVPData(entity_sets: string[]) {
7 const token = (await cookies()).get("phone_auth_token");
8
9 let authToken: {
10 id: string;
11 created_at: string;
12 confirmed: boolean;
13 confirmation_code: string;
14 phone_number: string;
15 country_code: string;
16 } | null = null;
17 if (token) {
18 let { data } = await supabaseServerClient
19 .from("phone_number_auth_tokens")
20 .select("*")
21 .eq("id", token.value)
22 .single();
23 authToken = data;
24 }
25
26 const { data: rsvps } = await supabaseServerClient
27 .from("phone_rsvps_to_entity")
28 .select(
29 `
30 *,
31 entities!inner(*)
32 `,
33 )
34 .in("entities.set", entity_sets);
35
36 return {
37 authToken,
38 rsvps:
39 rsvps?.map((rsvp) => {
40 if (
41 rsvp.phone_number === authToken?.phone_number &&
42 rsvp.country_code === authToken.country_code
43 )
44 return {
45 phone_number: rsvp.phone_number,
46 country_code: rsvp.country_code,
47 name: rsvp.name,
48 entity: rsvp.entities.id,
49 status: rsvp.status,
50 plus_ones: rsvp.plus_ones,
51 };
52 else
53 return {
54 name: rsvp.name,
55 entity: rsvp.entities.id,
56 status: rsvp.status,
57 plus_ones: rsvp.plus_ones,
58 };
59 }) || [],
60 };
61}