Clean up demo seed API pushes and responses

cgen-baa1c9b9205745f5b68da56ce0294d76
This commit is contained in:
Builder.io 2025-10-14 02:57:56 +00:00
parent 3c499df528
commit 247aeca1c4

View file

@ -190,7 +190,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
.select()
.single();
if (insertProfileError) throw insertProfileError;
seededUsers.push(insertProfileError ? null : insertedProfile);
seededUsers.push(insertedProfile);
} else {
seededUsers.push(existingProfile);
}
@ -254,7 +254,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
)
.single();
if (insertPostError) throw insertPostError;
seededPosts.push(insertPostError ? null : insertedPost);
seededPosts.push(insertedPost);
}
const followRows = FOLLOW_PAIRS.flatMap(({ followerEmail, followingEmail }) => {
@ -274,14 +274,25 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
const { error: followError } = await admin
.from("user_follows")
.upsert(followRows, {
onConflict: "follower_id,following_id" as any,
ignoreDuplicates: true as any,
});
onConflict: "follower_id,following_id",
} as any);
if (followError) throw followError;
}
const sanitizedUsers = seededUsers.filter(Boolean);
const sanitizedPosts = seededPosts.filter(Boolean);
const sanitizedUsers = Array.from(
new Map(
seededUsers
.filter(Boolean)
.map((profile: any) => [profile.id, profile]),
).values(),
);
const sanitizedPosts = Array.from(
new Map(
seededPosts
.filter(Boolean)
.map((post: any) => [post.id, post]),
).values(),
);
return res.status(200).json({
ok: true,