File tree 2 files changed +36
-0
lines changed
nextLevelWeek/expert/src/http
2 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+
2
+ import { z } from 'zod'
3
+
4
+ import { prisma } from '../../lib/prisma'
5
+ import { FastifyInstance } from 'fastify'
6
+
7
+ export async function getPoll ( app : FastifyInstance ) {
8
+ app . get ( '/polls/:id' , async ( request , reply ) => {
9
+
10
+ const getPollParams = z . object ( {
11
+ id : z . string ( ) . uuid ( ) ,
12
+ } )
13
+
14
+ const { id } = getPollParams . parse ( request . params )
15
+
16
+ const poll = await prisma . poll . findUnique ( {
17
+ where : {
18
+ id
19
+ } ,
20
+ include : {
21
+ options : {
22
+ select : {
23
+ title : true
24
+ }
25
+ }
26
+ }
27
+ } )
28
+
29
+ return reply . status ( 200 ) . send ( { poll } )
30
+ } )
31
+
32
+
33
+ }
34
+
Original file line number Diff line number Diff line change 1
1
import fastify from "fastify" ;
2
2
import { PrismaClient } from "@prisma/client" ;
3
3
import { createPoll } from "./routes/create-poll" ;
4
+ import { getPoll } from "./routes/get-poll" ;
4
5
5
6
const app = fastify ( )
6
7
7
8
app . register ( createPoll )
9
+ app . register ( getPoll )
8
10
9
11
app . listen ( { port : 3333 } )
10
12
. then ( ( ) => { console . log ( 'listening on port 3333' ) } )
You can’t perform that action at this time.
0 commit comments