super-fit-web-app / src / server / routers / trainer.ts
trainer.ts
Raw
import { z } from "zod";
import { procedure, router } from "../trpc";
import { db } from "@/db/PrismaClient";
import { TRPCError } from '@trpc/server';

export const trainerRouter = router({
  getFrontPageCoaches: procedure
  .query(async ({ ctx }) => {
    try{
      const coaches = await db.trainer.findMany({
        where: {
          frontPage: true
        },
        take: 3
      })

      console.log(coaches)

      return coaches;
    } catch (error) {
      console.log(error)
      if (error instanceof TRPCError) throw error;
      throw new TRPCError({
        code: 'INTERNAL_SERVER_ERROR',
        message: (error as Error).message,
        cause: error
      });
    }
  }),
})