teqo-backup/src/utilities/municipality/municipalityRevalidation.ts
Francisco Ignácio Fontoura Solla 4806c417c8 Engineering Pass 3: consolidate patterns and lock them with guards.
Fold duplicated campanha access, loaders, list/filter/form shells, and scripts into shared modules; reorganize utilities by domain; stabilize e2e; and document prevention-first audit workflow so the same smells cannot creep back in.
2026-07-29 06:11:29 -03:00

35 lines
989 B
TypeScript

import 'server-only'
import { revalidatePath } from 'next/cache'
// The cache tag moved to `municipalityCatalogCache.ts` (P3-E) — import it from
// there; this module owns only the revalidatePath side.
type MunicipalityListRevalidateScope = 'list' | 'detail' | 'both'
const municipalitySlugPathPattern = /^[a-z0-9]+(?:-[a-z0-9]+)*$/
type RevalidateMunicipalityListPathsOptions = {
slug?: string
scope?: MunicipalityListRevalidateScope
}
export const revalidateMunicipalityListPaths = ({
slug,
scope = 'both',
}: RevalidateMunicipalityListPathsOptions = {}) => {
const detailSlug = slug && municipalitySlugPathPattern.test(slug) ? slug : undefined
if (scope === 'list' || scope === 'both') {
revalidatePath('/campanha/municipios', 'page')
}
if (scope === 'detail' || scope === 'both') {
if (detailSlug) {
revalidatePath(`/campanha/municipios/${detailSlug}`, 'page')
return
}
revalidatePath('/campanha/municipios/[slug]', 'page')
}
}