Skip to content

Commit

Permalink
feat: revalidate
Browse files Browse the repository at this point in the history
  • Loading branch information
sadmann7 committed May 27, 2024
1 parent 008096f commit 5a78e32
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 2 additions & 4 deletions src/db/seed.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {
revalidate,
seedCategories,
seedProducts,
seedSubcategories,
} from "@/lib/actions/seed"

Expand All @@ -13,9 +13,7 @@ async function runSeed() {

await seedSubcategories()

await seedProducts({
storeId: "Dawqq1CClHUW",
})
await revalidate()

const end = Date.now()

Expand Down
8 changes: 5 additions & 3 deletions src/lib/actions/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Category, "createdAt" | "updatedAt">[] =
productConfig.categories.map((category) => ({
Expand All @@ -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() {
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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"))
}

0 comments on commit 5a78e32

Please sign in to comment.