Skip to content

Commit

Permalink
feat: handle unpublishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierniki committed Sep 5, 2023
1 parent 738c058 commit 6242eaf
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions app/api/algolia-webhook/unpublish/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,11 @@ async function handleAlgoliaWebhook(req: NextRequestWithValidBody<z.infer<typeof
const article = req.validBody.data

const indexingResults = await Promise.allSettled(
article.localizations.map(async ({ locale, title, content }) => {
article.localizations.map(async ({ locale }) => {
const index = client.initIndex(`articles-${locale}`)
await index.saveObject({
objectID: article.id,
title,
content: slateToText(content),
})
await index.deleteObject(article.id)

return { title, locale }
return { locale }
})
)

Expand All @@ -39,7 +35,7 @@ export async function POST(req: NextRequest) {

const bodySchema = z.object({
data: z.object({
localizations: z.array(z.object({ content: z.any(), title: z.string(), locale: z.string() })),
localizations: z.array(z.object({ locale: z.string() })),
id: z.string(),
}),
})

0 comments on commit 6242eaf

Please sign in to comment.