Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 19f3931

Browse files
committedFeb 8, 2024
cria get poll
1 parent 2c69192 commit 19f3931

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
+2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import fastify from "fastify";
22
import { PrismaClient } from "@prisma/client";
33
import { createPoll } from "./routes/create-poll";
4+
import { getPoll } from "./routes/get-poll";
45

56
const app = fastify()
67

78
app.register(createPoll)
9+
app.register(getPoll)
810

911
app.listen({port: 3333})
1012
.then(() => {console.log('listening on port 3333')})

0 commit comments

Comments
 (0)
Please sign in to comment.