-
Notifications
You must be signed in to change notification settings - Fork 0
/
events.js
41 lines (34 loc) · 1.06 KB
/
events.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
// Events routes / Events
// host + /api/events
import { Router } from 'express';
import { check } from 'express-validator';
const router = Router();
import { createEvent, deleteEvent, getEvents, updateEvent } from '../controllers/events.js';
import { isDate } from '../helpers/isDateValidator.js';
import { validateFields } from '../middlewares/fieldsValidator.js';
import { validateJWT } from '../middlewares/jwtValidator.js';
// High order middleware, all the routes use it
router.use(validateJWT);
router.post(
'/',
[
check('title', 'Title is necessary').not().isEmpty(),
check('start', 'Start date is not valid').custom(isDate),
check('end', 'End date is not valid').custom(isDate),
validateFields,
],
createEvent
);
router.get('/', getEvents);
router.put(
'/:id',
[
check('title', 'Title is necessary').not().isEmpty(),
check('start', 'Start date is not valid').custom(isDate),
check('end', 'End date is not valid').custom(isDate),
validateFields,
],
updateEvent
);
router.delete('/:id', deleteEvent);
export default router;