Merged in fix/destination-city-page-cache-revalidate (pull request #2492)

Fix: destination city page invalidate cache in webhook

* Fix: destination city page invalidate cache in webhook

* Use correct uid


Approved-by: Joakim Jäderberg
This commit is contained in:
Linus Flood
2025-07-01 12:49:23 +00:00
parent be25be7bb5
commit 03b8d8eac6
2 changed files with 16 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ import { z } from "zod"
import { Lang } from "@scandic-hotels/common/constants/language" import { Lang } from "@scandic-hotels/common/constants/language"
import { getCacheClient } from "@scandic-hotels/common/dataCache" import { getCacheClient } from "@scandic-hotels/common/dataCache"
import { affix as breadcrumbsAffix } from "@scandic-hotels/trpc/routers/contentstack/breadcrumbs/utils" import { affix as breadcrumbsAffix } from "@scandic-hotels/trpc/routers/contentstack/breadcrumbs/utils"
import { destinationCityPageDestinationSettingsSchema } from "@scandic-hotels/trpc/routers/contentstack/destinationCityPage/output"
import { languageSwitcherAffix } from "@scandic-hotels/trpc/routers/contentstack/languageSwitcher/utils" import { languageSwitcherAffix } from "@scandic-hotels/trpc/routers/contentstack/languageSwitcher/utils"
import { affix as metadataAffix } from "@scandic-hotels/trpc/routers/contentstack/metadata/utils" import { affix as metadataAffix } from "@scandic-hotels/trpc/routers/contentstack/metadata/utils"
import { affix as pageSettingsAffix } from "@scandic-hotels/trpc/routers/contentstack/pageSettings/utils" import { affix as pageSettingsAffix } from "@scandic-hotels/trpc/routers/contentstack/pageSettings/utils"
@@ -40,6 +41,8 @@ const validateJsonBody = z.object({
hide_booking_widget: z.boolean(), hide_booking_widget: z.boolean(),
}) })
.optional(), .optional(),
destination_settings:
destinationCityPageDestinationSettingsSchema.optional(),
}), }),
}), }),
}) })
@@ -160,6 +163,18 @@ export async function POST(request: NextRequest) {
await cacheClient.deleteKey(pageSettingsTag, { fuzzy: true }) await cacheClient.deleteKey(pageSettingsTag, { fuzzy: true })
} }
if (content_type.uid === "destination_city_page") {
const cityIdentifier = entry.destination_settings?.city
if (cityIdentifier) {
const cityPageTag = generateTag(
entryLocale,
"city_list_data",
cityIdentifier
)
await cacheClient.deleteKey(cityPageTag, { fuzzy: true })
}
}
return Response.json({ revalidated: true, now: Date.now() }) return Response.json({ revalidated: true, now: Date.now() })
} catch (error) { } catch (error) {
console.error("Failed to revalidate tag(s)") console.error("Failed to revalidate tag(s)")

View File

@@ -21,7 +21,7 @@ import { systemSchema } from "../schemas/system"
import type { ImageVaultAsset } from "../../../types/imageVault" import type { ImageVaultAsset } from "../../../types/imageVault"
const destinationCityPageDestinationSettingsSchema = z export const destinationCityPageDestinationSettingsSchema = z
.object({ .object({
city_denmark: z.string().optional().nullable(), city_denmark: z.string().optional().nullable(),
city_finland: z.string().optional().nullable(), city_finland: z.string().optional().nullable(),