From 5a78e32b71341fbd3fead02eff5246c78e071256 Mon Sep 17 00:00:00 2001 From: sadmann7 Date: Mon, 27 May 2024 22:06:37 +0600 Subject: [PATCH] feat: revalidate --- src/db/seed.ts | 6 ++---- src/lib/actions/seed.ts | 8 +++++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/db/seed.ts b/src/db/seed.ts index fa9ff960..e564175f 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -1,6 +1,6 @@ import { + revalidate, seedCategories, - seedProducts, seedSubcategories, } from "@/lib/actions/seed" @@ -13,9 +13,7 @@ async function runSeed() { await seedSubcategories() - await seedProducts({ - storeId: "Dawqq1CClHUW", - }) + await revalidate() const end = Date.now() diff --git a/src/lib/actions/seed.ts b/src/lib/actions/seed.ts index 5fd8d13f..cda4ffdf 100644 --- a/src/lib/actions/seed.ts +++ b/src/lib/actions/seed.ts @@ -14,6 +14,11 @@ import { productConfig } from "@/config/product" import { generateId } from "@/lib/id" import { absoluteUrl, slugify } from "@/lib/utils" +export async function revalidate() { + console.log("🔄 Revalidating...") + await fetch(absoluteUrl("/api/revalidate")) +} + export async function seedCategories() { const data: Omit[] = productConfig.categories.map((category) => ({ @@ -27,7 +32,6 @@ export async function seedCategories() { await db.delete(categories) console.log(`📝 Inserting ${data.length} categories`) await db.insert(categories).values(data) - await fetch(absoluteUrl("/api/revalidate")) } export async function seedSubcategories() { @@ -62,7 +66,6 @@ export async function seedSubcategories() { await db.delete(subcategories) console.log(`📝 Inserting ${data.length} subcategories`) await db.insert(subcategories).values(data) - await fetch(absoluteUrl("/api/revalidate")) } export async function seedProducts({ @@ -110,5 +113,4 @@ export async function seedProducts({ await db.delete(products).where(eq(products.storeId, storeId)) console.log(`📝 Inserting ${data.length} products`) await db.insert(products).values(data) - await fetch(absoluteUrl("/api/revalidate")) }