Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bun.lockb
Binary file not shown.
9 changes: 7 additions & 2 deletions src/routes/api/webhooks/google-sheets/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const POST = async ({ request }) => {
);

const existingPostsSet = new Set<string>();
const allPostKeywordsToInsert: { post_id: number; keyword_id: number }[] = [];

if (titles.length > 0 && contacts.length > 0) {
const { data: existingPosts } = await supabaseAdmin
Expand Down Expand Up @@ -147,8 +148,8 @@ export const POST = async ({ request }) => {
}

if (keywordIdsToInsert.length > 0) {
await supabaseAdmin.from('postkeyword').insert(
keywordIdsToInsert.map((keywordId) => ({
allPostKeywordsToInsert.push(
...keywordIdsToInsert.map((keywordId) => ({
post_id: postData.id,
keyword_id: keywordId
}))
Expand All @@ -157,6 +158,10 @@ export const POST = async ({ request }) => {
}
}

if (allPostKeywordsToInsert.length > 0) {
await supabaseAdmin.from('postkeyword').insert(allPostKeywordsToInsert);
}

return json({ success: true, insertedCount, skippedCount, errors });
} catch (error) {
console.error('Webhook error:', error);
Expand Down
Loading