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() .select()
.single(); .single();
if (insertProfileError) throw insertProfileError; if (insertProfileError) throw insertProfileError;
seededUsers.push(insertProfileError ? null : insertedProfile); seededUsers.push(insertedProfile);
} else { } else {
seededUsers.push(existingProfile); seededUsers.push(existingProfile);
} }
@ -254,7 +254,7 @@ export default async function handler(req: VercelRequest, res: VercelResponse) {
) )
.single(); .single();
if (insertPostError) throw insertPostError; if (insertPostError) throw insertPostError;
seededPosts.push(insertPostError ? null : insertedPost); seededPosts.push(insertedPost);
} }
const followRows = FOLLOW_PAIRS.flatMap(({ followerEmail, followingEmail }) => { 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 const { error: followError } = await admin
.from("user_follows") .from("user_follows")
.upsert(followRows, { .upsert(followRows, {
onConflict: "follower_id,following_id" as any, onConflict: "follower_id,following_id",
ignoreDuplicates: true as any, } as any);
});
if (followError) throw followError; if (followError) throw followError;
} }
const sanitizedUsers = seededUsers.filter(Boolean); const sanitizedUsers = Array.from(
const sanitizedPosts = seededPosts.filter(Boolean); 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({ return res.status(200).json({
ok: true, ok: true,