new website beginning

This commit is contained in:
alex 3
2023-10-22 04:40:50 -04:00
parent 7dd999700e
commit b08637ea2a
35 changed files with 6010 additions and 93 deletions
+54
View File
@@ -0,0 +1,54 @@
import { z } from "zod";
import {
createTRPCRouter,
protectedProcedure,
publicProcedure,
} from "@/server/api/trpc";
export const postRouter = createTRPCRouter({
create: protectedProcedure
.input(
z.object({
name: z.string().min(1),
reviewContents: z.string().min(1),
type: z.string().min(1),
image: z.string().min(1)
})
)
.mutation(async ({ ctx, input }) => {
// simulate a slow db call
await new Promise((resolve) => setTimeout(resolve, 1000));
return ctx.db.post.create({
data: {
name: input.name,
reviewContents: input.reviewContents,
type: input.type,
image: input.image,
createdBy: { connect: { id: ctx.session.user.id } },
},
});
}),
getOne: publicProcedure
.input(String)
.query(({ ctx, input }) => {
return ctx.db.post.findFirst({
where: { name: input },
});
}),
getAll: publicProcedure
.query(({ctx}) => {
return ctx.db.post.findMany()
}),
getAllOfType: publicProcedure
.input(String)
.query(({ctx, input}) => {
return ctx.db.post.findMany({
where: { type: input }
})
})
});