-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
55 lines (48 loc) · 1.24 KB
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import cors from 'cors'
import express from 'express'
import { PrismaClient } from '@prisma/client'
const app = express()
const prisma = new PrismaClient()
app.listen(3000)
app.use(cors())
app.use(express.json())
//LIST USERS
app.get('/usuarios', async(req, res) =>{
const users = await prisma.user.findMany()
res.status(200).json(users)
})
//CREATE USERS
app.post('/usuarios', async (req, res) => {
const user = await prisma.user.create({
data:{
email: req.body.email,
age: req.body.age,
name: req.body.name
}
})
console.log(user)
res.status(201).json(user)
})
//EDIT USERS
app.put('/usuarios/:id', async (req, res) => {
const user = await prisma.user.update({
where: {
id: req.params.id
},
data:{
email: req.body.email,
age: req.body.age,
name: req.body.name
}
})
console.log(user)
res.status(201).json(user)
})
app.delete('/usuarios/:id',async (req, res) => {
await prisma.user.delete({
where:{
id: req.params.id
}
})
res.status(200).json( {message: "Usuarios deletado com sucesso"})
})