From e2391f8a9206499325b55b4ebbe3f9e112dc717e Mon Sep 17 00:00:00 2001 From: "Builder.io" Date: Thu, 13 Nov 2025 06:39:52 +0000 Subject: [PATCH] completionId: cgen-c6bc0203da95435489b851b7f28c816f cgen-c6bc0203da95435489b851b7f28c816f --- api/community/posts.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/api/community/posts.ts b/api/community/posts.ts index 97f7fc82..c1e88236 100644 --- a/api/community/posts.ts +++ b/api/community/posts.ts @@ -100,8 +100,45 @@ export default async function handler(req: any, res: any) { return res.status(500).json({ error: error.message }); } + const createdPost = data?.[0]; + + // Publish activity event for post creation + try { + await fetch("http://localhost:3000/api/activity/publish", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + actor_id: author_id, + verb: "created", + object_type: "post", + object_id: createdPost?.id, + metadata: { + summary: `Posted to ${arm_affiliation}`, + title: title.substring(0, 100), + }, + }), + }).catch((err) => console.error("Activity publish error:", err)); + } catch (error) { + console.error("Failed to publish activity:", error); + } + + // Apply rewards for post creation + try { + await fetch("http://localhost:3000/api/rewards/apply", { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + user_id: author_id, + action: "post_created", + amount: 25, + }), + }).catch((err) => console.error("Rewards apply error:", err)); + } catch (error) { + console.error("Failed to apply rewards:", error); + } + return res.status(201).json({ - post: data?.[0], + post: createdPost, }); } catch (error: any) { console.error("[Community Posts API POST] Unexpected error:", error);