Switch follow/unfollow/endorse to server APIs so notifications fire

cgen-295023c025ae4bbd9f2937b51bd579cb
This commit is contained in:
Builder.io 2025-10-18 03:00:09 +00:00
parent 8303a18100
commit 3ce65bfd7b

View file

@ -53,26 +53,21 @@ export const aethexSocialService = {
}, },
async followUser(followerId: string, followingId: string): Promise<void> { async followUser(followerId: string, followingId: string): Promise<void> {
const { error } = await supabase.from("user_follows").insert({ const resp = await fetch("/api/social/follow", {
follower_id: followerId, method: "POST",
following_id: followingId, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ follower_id: followerId, following_id: followingId }),
}); });
if (!resp.ok) throw new Error(await resp.text());
if (error) {
throw new Error(error.message || "Unable to follow user");
}
}, },
async unfollowUser(followerId: string, followingId: string): Promise<void> { async unfollowUser(followerId: string, followingId: string): Promise<void> {
const { error } = await supabase const resp = await fetch("/api/social/unfollow", {
.from("user_follows") method: "POST",
.delete() headers: { "Content-Type": "application/json" },
.eq("follower_id", followerId) body: JSON.stringify({ follower_id: followerId, following_id: followingId }),
.eq("following_id", followingId); });
if (!resp.ok) throw new Error(await resp.text());
if (error) {
throw new Error(error.message || "Unable to unfollow user");
}
}, },
async sendInvite(inviterId: string, email: string, message?: string | null) { async sendInvite(inviterId: string, email: string, message?: string | null) {
@ -150,11 +145,11 @@ export const aethexSocialService = {
}, },
async endorseSkill(endorserId: string, endorsedId: string, skill: string) { async endorseSkill(endorserId: string, endorsedId: string, skill: string) {
const payload = { endorser_id: endorserId, endorsed_id: endorsedId, skill }; const resp = await fetch("/api/social/endorse", {
const { error } = await supabase method: "POST",
.from("endorsements") headers: { "Content-Type": "application/json" },
.insert(payload as any); body: JSON.stringify({ endorser_id: endorserId, endorsed_id: endorsedId, skill }),
if (error) throw new Error(error.message || "Unable to endorse"); });
await this.applyReward(endorsedId, "endorsement_received", 2); if (!resp.ok) throw new Error(await resp.text());
}, },
}; };