diff --git a/backend/src/database/db.sqlite b/backend/src/database/db.sqlite index f0c2283..f6a1695 100644 Binary files a/backend/src/database/db.sqlite and b/backend/src/database/db.sqlite differ diff --git a/backend/src/index.js b/backend/src/index.js index 2300704..7e767fd 100644 --- a/backend/src/index.js +++ b/backend/src/index.js @@ -1,5 +1,6 @@ const express = require('express'); const cors = require('cors'); +const { errors } = require('celebrate'); const routes = require('./routes'); const app = express(); @@ -7,4 +8,6 @@ app.use(cors()) app.use(express.json()); app.use(routes); +app.use(errors()); + app.listen(3333); \ No newline at end of file diff --git a/backend/src/routes.js b/backend/src/routes.js index da00d62..8e0c0aa 100644 --- a/backend/src/routes.js +++ b/backend/src/routes.js @@ -1,4 +1,5 @@ const express = require('express'); +const { celebrate, Segments, Joi} = require('celebrate'); const NgoController = require('./controllers/NgoController'); const IncidentsController = require('./controllers/IncidentController'); @@ -9,12 +10,44 @@ const routes = express.Router(); routes.post('/sessions', SessionController.create); routes.get('/ngos', NgoController.index); -routes.post('/ngos', NgoController.create); +routes.post('/ngos', 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().min(2).max(3), + country: Joi.string().required() + }) +}), NgoController.create); -routes.get('/profile', ProfileController.index); +routes.get('/profile', celebrate({ + [Segments.HEADERS]: Joi.object({ + authorization: Joi.string().required(), + }).unknown() +}),ProfileController.index); -routes.get('/incidents', IncidentsController.index); -routes.post('/incidents', IncidentsController.create); -routes.delete('/incidents/:id', IncidentsController.delete); +routes.get('/incidents', celebrate({ + [Segments.QUERY]: Joi.object().keys({ + page: Joi.number(), + }) +}),IncidentsController.index); + +routes.post('/incidents', celebrate({ + [Segments.HEADERS]: Joi.object({ + authorization: Joi.string().required(), + }).unknown(), + [Segments.BODY]: Joi.object().keys({ + title: Joi.string().required(), + description: Joi.string().required(), + value: Joi.number().required() + }) +}), IncidentsController.create); + +routes.delete('/incidents/:id', celebrate({ + [Segments.PARAMS]: Joi.object().keys({ + id: Joi.number().required(), + }) +}), IncidentsController.delete); module.exports = routes; \ No newline at end of file