|
|
|
```
|
|
|
|
const express = require('express')
|
|
|
|
const server = express()
|
|
|
|
const bodyParser = require('body-parser')
|
|
|
|
const mongoose = require('mongoose')
|
|
|
|
|
|
|
|
server.use(bodyParser.urlencoded({ extended: false }))
|
|
|
|
server.use(bodyParser.json())
|
|
|
|
|
|
|
|
mongoose.connect('mongodb://localhost:27017/test');
|
|
|
|
|
|
|
|
const menorModel = mongoose.model('Menor',
|
|
|
|
{
|
|
|
|
tipo: String,
|
|
|
|
nome: String,
|
|
|
|
sexo: String,
|
|
|
|
familiares:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
tipo: String,
|
|
|
|
nome: String'
|
|
|
|
},
|
|
|
|
],
|
|
|
|
nacionalidade: String,
|
|
|
|
naturalidade:
|
|
|
|
{
|
|
|
|
cidade: String,
|
|
|
|
UF: String
|
|
|
|
},
|
|
|
|
abrigo:
|
|
|
|
{
|
|
|
|
id: Number,
|
|
|
|
nome: String
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
server.get('/', function(req, res, next) {
|
|
|
|
res.send('Its working')
|
|
|
|
res.end()
|
|
|
|
})
|
|
|
|
|
|
|
|
server.get('/abrigos', function(req, res, next) {
|
|
|
|
menorModel.find()
|
|
|
|
})
|
|
|
|
|
|
|
|
server.post('/menor', function(req, res, next) {
|
|
|
|
menor = new menorModel(req.body)
|
|
|
|
menor.save
|
|
|
|
res.send(200, 'Funcionou!')
|
|
|
|
res.end()
|
|
|
|
})
|
|
|
|
|
|
|
|
server.listen(8888, function() {
|
|
|
|
console.log('server listening on port 8888')
|
|
|
|
})
|
|
|
|
|
|
|
|
``` |
|
|
|
\ No newline at end of file |