-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (33 loc) · 1.17 KB
/
index.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
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
const HTTP_OK_STATUS = 200;
const PORT = '3000';
const controllers = require('./controllers');
const middlewares = require('./middlewares');
const validationsLogin = [
middlewares.validatePassword,
middlewares.validateEmail,
];
const validationTalker = [
middlewares.validateToken,
middlewares.validateAge,
middlewares.validateName,
middlewares.validateTalk,
];
app.post('/login', validationsLogin, controllers.newlogin);
app.post('/talker', validationTalker, controllers.createTalker);
// não remova esse endpoint, e para o avaliador funcionar
app.get('/', (_request, response) => {
response.status(HTTP_OK_STATUS).send();
});
app.get('/talker', controllers.getTalkers);
app.get('/talker/search', [middlewares.validateToken], controllers.searchTalker);
app.get('/talker/:id', controllers.getTalkerById);
app.put('/talker/:id', validationTalker, controllers.editTalker);
app.delete('/talker/:id', [middlewares.validateToken], controllers.deleteTalker);
app.use(middlewares.errorHandler);
app.listen(PORT, () => {
console.log('Online');
});