Skip to content

Commit dcff048

Browse files
committed
Rota p/ PUT (Update)
Criada a rota para o PUT e adicionado o teste no arquivo das rotas
1 parent 4930817 commit dcff048

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

app.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,18 @@ app.post(`${baseUrl}`, async (req, res) => {
3636
})
3737

3838
//Rota para o put (update) dos alunos
39-
app.put(`${baseUrl}/:id`, (req, res) => {
40-
res.send('Aqui é o put dos alunos')
39+
app.put(`${baseUrl}/:id`, async (req, res) => {
40+
const { id } = req.params; // Capturando o ID diretamente dos parâmetros da URL
41+
42+
const updatedStudent = await prisma.students.update({
43+
where: {id: id},
44+
data: {
45+
name: req.body.name,
46+
email: req.body.email,
47+
age: req.body.age
48+
}
49+
})
50+
res.json(updatedStudent)
4151
})
4252

4353
//Rota para o delete dos alunos

prisma/dev.db

0 Bytes
Binary file not shown.

rotas.http

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,14 @@ Content-Type: application/json
1414

1515
###
1616

17-
PUT http://localhost:3000/api/students/1
17+
PUT http://localhost:3000/api/students/62fe2543-7752-41a9-a7ad-1194656c2fde
18+
Content-Type: application/json
19+
20+
{
21+
"name": "Atualizando o nome"
22+
23+
}
24+
1825

1926
###
2027

0 commit comments

Comments
 (0)