-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
70 lines (53 loc) · 1.36 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
const express = require('express')
const bodyparser = require('body-parser')
const app = express()
const port = 4100
app.use(bodyparser.urlencoded({extended:false}))
app.use(bodyparser.json())
const {person} = require('sequelize')
app.get('/persons',(req, res)=>{
person.findAll()
.then (persons =>{
res.send(persons)
})
})
app.post('/persons/nuevo', (req, res) =>{
console.log(req.body)
person.create({
FirstName:req.body.FirstName,
SecondName:req.body.SecondName,
Sex:req.body.Sex,
Telephone:req.body.Telephone
}).then (person =>{
res.send('Person Created')
})
})
app.get('/persons/:id', (req, res) =>{
let personId = req.body.id
person.findOne({where:{id:personId}})
.then(person =>{
res.json(person)
})
})
app.put('/persons/:id', (req, res) =>{
let personId = req.body.id
let nuevoDatos = req.body
person.findOne({where:{id:personId}})
.then(person =>{
person.update(nuevoDatos)
.then(nuevaperson =>{
res.json(nuevaperson)
})
})
})
app.delete('/persons/:id', (req, res) =>{
let personId = req.params.id
person.destroy({
where:{id:personId}
}).then(() =>{
res.send('Person Eliminated...')
})
})
app.listen(port, () =>{
console.log(`App listening at port ${port}`)
})