Skip to content

Commit

Permalink
day five - validations
Browse files Browse the repository at this point in the history
  • Loading branch information
christyanbrayan committed Mar 31, 2020
1 parent 5fb6684 commit 40f64a9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
Binary file modified backend/src/database/db.sqlite
Binary file not shown.
4 changes: 3 additions & 1 deletion backend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
const express = require('express')
const cors = require('cors')
const { errors } = require('celebrate')
const routes = require('./routes')

const app = express()

app.use(cors())
app.use(express.json())
app.use(routes)
app.use(errors())

app.listen(3333)
app.listen(3333)
33 changes: 28 additions & 5 deletions backend/src/routes.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express')
const { celebrate, Segments, Joi } = require('celebrate')

const OngController = require('./controllers/OngController')
const IncidentController = require('./controllers/IncidentController')
Expand All @@ -10,12 +11,34 @@ const routes = express.Router()
routes.post('/sessions', SessionController.create)

routes.get('/ongs', OngController.index)
routes.post('/ongs', OngController.create)
routes.post('/ongs', celebrate({
[Segments.BODY]: Joi.object().keys({
name: Joi.string().required(),
email: Joi.string().required().email(),
whatsapp: Joi.number().required().min(10).max(11),
city: Joi.string().required(),
uf: Joi.string().required().length(2),
})
}), OngController.create)

routes.get('/profile', ProfileController.index)
routes.get('/profile', celebrate({
[Segments.HEADERS]: Joi.object({
authorization: Joi.string().required(),
}).unknown(),
}), ProfileController.index)

routes.get('/incidents', celebrate({
[Segments.QUERY]: Joi.object().keys({
page: Joi.number(),
})
}), IncidentController.index)

routes.get('/incidents', IncidentController.index)
routes.post('/incidents', IncidentController.create)
routes.delete('/incidents/:id', IncidentController.delete)

module.exports = routes
routes.delete('/incidents/:id', celebrate({
[Segments.PARAMS]: Joi.object().keys({
id: Joi.number().required(),
})
}), IncidentController.delete)

module.exports = routes

0 comments on commit 40f64a9

Please sign in to comment.