Skip to content

Commit

Permalink
refactor: add getWorkshopMetadata for metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Raphico committed Jun 28, 2024
1 parent bc1a60e commit c542a66
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
13 changes: 2 additions & 11 deletions src/app/(app)/workshop/[workshopId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@ import * as React from "react"
import type { Metadata } from "next"
import { notFound, redirect } from "next/navigation"
import { env } from "@/env"
import { eq } from "drizzle-orm"

import { redirects } from "@/config/constants"
import { getWorkshopRegistrants } from "@/server/data/registration"
import { getUserSession } from "@/server/data/user"
import { getWorkshop } from "@/server/data/workshop"
import { db } from "@/server/db"
import { workshops } from "@/server/db/schema"
import { getWorkshop, getWorkshopMetadata } from "@/server/data/workshop"
import { getExactScheduled } from "@/utils/format-scheduled-date"
import { Button } from "@/components/ui/button"
import { Separator } from "@/components/ui/separator"
Expand All @@ -35,13 +32,7 @@ export async function generateMetadata({
}: WorkshopPageProps): Promise<Metadata> {
const workshopId = decodeURIComponent(params.workshopId)

const workshop = await db.query.workshops.findFirst({
columns: {
title: true,
description: true,
},
where: eq(workshops.id, workshopId),
})
const workshop = await getWorkshopMetadata(workshopId)

if (!workshop) {
return {}
Expand Down
14 changes: 14 additions & 0 deletions src/server/data/workshop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ export async function getWorkshop(workshopId: string) {
}
}

export async function getWorkshopMetadata(workshopId: string) {
try {
return db.query.workshops.findFirst({
columns: {
title: true,
description: true,
},
where: eq(workshops.id, workshopId),
})
} catch (err) {
return null
}
}

export async function getUserWorkshops(userId: string) {
return await cache(
async () => {
Expand Down

0 comments on commit c542a66

Please sign in to comment.