Skip to content

Commit

Permalink
fix: tag schema
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierniki committed Nov 9, 2023
1 parent 190e1f3 commit 3c747df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/app/api/webhook/publish/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ async function handleAlgoliaPublishWebhook(req: NextRequestWithValidBody<Publish
if (!isArticle(article)) return NextResponse.json({ result: "success" }, { status: 200 })

const indexingResults = await Promise.allSettled(
article.localizations.map(async ({ locale: hygraphLocale, title, content, slug, tags }) => {
article.localizations.map(async ({ locale: hygraphLocale, title, content, slug }) => {
const locale = hygraphLocaleToStandardNotation(hygraphLocale)
const index = algoliaClient.initIndex(`articles-${locale}`)
index.setSettings({
Expand All @@ -26,7 +26,9 @@ async function handleAlgoliaPublishWebhook(req: NextRequestWithValidBody<Publish
title,
content: slateToText(content),
slug,
tags: tags.map(({ tag }) => tag),
tags: article.tags
.map((tag) => tag.localizations.find((localization) => localization.locale === hygraphLocale)?.tag)
.filter((tag) => tag !== undefined),
})

return { title, locale }
Expand Down Expand Up @@ -55,9 +57,9 @@ const articleSchema = z.object({
title: z.string(),
locale: z.string(),
slug: z.string(),
tags: z.array(z.object({ tag: z.string() })),
})
),
tags: z.array(z.object({ localizations: z.array(z.object({ tag: z.string(), locale: z.string() })) })),
id: z.string(),
})

Expand Down

0 comments on commit 3c747df

Please sign in to comment.