98 lines
2.9 KiB
TypeScript
98 lines
2.9 KiB
TypeScript
import { apiFetch } from "@/app/lib/api-client";
|
|
|
|
export interface PublicProfile {
|
|
id: string;
|
|
userId?: string;
|
|
name?: string;
|
|
age?: number;
|
|
location?: string;
|
|
citySlug?: string;
|
|
gender?: string;
|
|
single?: string;
|
|
tags?: string[];
|
|
bio?: string;
|
|
photo?: string;
|
|
lookingFor?: string[];
|
|
}
|
|
|
|
export interface DiscussionReply {
|
|
id: string;
|
|
discussionId?: string;
|
|
userId?: string;
|
|
author?: string;
|
|
body: string;
|
|
created?: string;
|
|
}
|
|
|
|
export async function fetchPublicProfile(profileId: string): Promise<PublicProfile | null> {
|
|
try {
|
|
const data = await apiFetch<{ profile?: PublicProfile }>(`/api/profiles/${profileId}`);
|
|
return data.profile || null;
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export async function rsvpMeetup(meetupId: string): Promise<{ rsvp: boolean; meetup?: Record<string, unknown> }> {
|
|
return apiFetch(`/api/meetups/${meetupId}/rsvp`, { method: "POST", body: JSON.stringify({}) });
|
|
}
|
|
|
|
export async function cancelMeetupRsvp(meetupId: string): Promise<{ rsvp: boolean; meetup?: Record<string, unknown> }> {
|
|
return apiFetch(`/api/meetups/${meetupId}/rsvp`, { method: "DELETE" });
|
|
}
|
|
|
|
export async function fetchMeetupRsvpStatus(meetupId: string): Promise<boolean> {
|
|
try {
|
|
const data = await apiFetch<{ rsvp?: boolean }>(`/api/meetups/${meetupId}/rsvp`);
|
|
return Boolean(data.rsvp);
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
export async function fetchDiscussion(discussionId: string) {
|
|
return apiFetch<{ item: Record<string, unknown> }>(`/api/discussions/${discussionId}`);
|
|
}
|
|
|
|
export async function fetchDiscussionReplies(discussionId: string): Promise<DiscussionReply[]> {
|
|
const data = await apiFetch<{ items: DiscussionReply[] }>(`/api/discussions/${discussionId}/replies`);
|
|
return data.items || [];
|
|
}
|
|
|
|
export async function postDiscussionReply(discussionId: string, body: string): Promise<DiscussionReply> {
|
|
const data = await apiFetch<{ reply: DiscussionReply }>(`/api/discussions/${discussionId}/replies`, {
|
|
method: "POST",
|
|
body: JSON.stringify({ body }),
|
|
});
|
|
return data.reply;
|
|
}
|
|
|
|
export async function toggleDiscussionLike(
|
|
discussionId: string
|
|
): Promise<{ liked: boolean; likes: number; item?: Record<string, unknown> }> {
|
|
return apiFetch(`/api/discussions/${discussionId}/like`, {
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
});
|
|
}
|
|
|
|
export async function toggleDiscussionPin(
|
|
discussionId: string
|
|
): Promise<{ pinned: boolean; item?: Record<string, unknown> }> {
|
|
return apiFetch(`/api/discussions/${discussionId}/pin`, {
|
|
method: "POST",
|
|
body: JSON.stringify({}),
|
|
});
|
|
}
|
|
|
|
export async function fetchMeetupSocialSuggestions(meetupId: string): Promise<{
|
|
items: Array<PublicProfile & { rsvpAttendee?: boolean }>;
|
|
city: string;
|
|
}> {
|
|
const data = await apiFetch<{
|
|
items: Array<PublicProfile & { rsvpAttendee?: boolean }>;
|
|
city: string;
|
|
}>(`/api/meetups/${meetupId}/social-suggestions`);
|
|
return { items: data.items || [], city: data.city || "" };
|
|
}
|