2019-07-09 08:51:00 +00:00
|
|
|
const routes = require('express').Router();
|
|
|
|
|
|
|
|
|
|
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
|
|
|
|
|
const SchemaValidator = require('../../middlewares/schemaValidator');
|
|
|
|
|
|
2019-07-09 16:56:22 +00:00
|
|
|
const PaginateMiddleware = require('../../middlewares/paginate');
|
|
|
|
|
const FieldMiddleware = require('../../middlewares/fields');
|
|
|
|
|
const SortMiddleware = require('../../middlewares/sort');
|
2019-07-09 08:51:00 +00:00
|
|
|
|
|
|
|
|
//const entityValidation = require('./entity.validations');
|
|
|
|
|
const eventController = require('./event.controller');
|
2019-07-16 18:18:28 +00:00
|
|
|
const eventValidation = require('./event.validations');
|
2019-07-09 08:51:00 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
const generalInvalidFields = [
|
|
|
|
|
'userId', 'createdAt', 'updatedAt',
|
2019-07-21 20:58:41 +00:00
|
|
|
'assistants', 'confirmed', 'allow_multiple', 'overflow_eventId',
|
|
|
|
|
'state', 'confirmed',
|
2019-07-17 12:07:35 +00:00
|
|
|
'multiple_limit', 'allow_overflow', 'marketing_list',
|
|
|
|
|
];
|
|
|
|
|
|
2019-07-09 15:48:29 +00:00
|
|
|
routes.get('/events',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-17 12:07:35 +00:00
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
|
|
|
|
}),
|
2019-07-09 16:56:22 +00:00
|
|
|
PaginateMiddleware.middleware(),
|
2019-07-18 11:23:43 +00:00
|
|
|
SortMiddleware.middleware({ default: "-init_date" }),
|
|
|
|
|
eventController.find({
|
2019-07-18 18:13:07 +00:00
|
|
|
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias'],
|
2019-07-18 11:23:43 +00:00
|
|
|
}),
|
2019-07-09 15:48:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.get('/events/next',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-11 18:05:06 +00:00
|
|
|
FieldMiddleware.middleware({
|
2019-07-17 12:07:35 +00:00
|
|
|
invalidFields: generalInvalidFields
|
2019-07-11 18:05:06 +00:00
|
|
|
}),
|
2019-07-09 16:56:22 +00:00
|
|
|
PaginateMiddleware.middleware(),
|
2019-07-10 08:42:03 +00:00
|
|
|
SortMiddleware.middleware({ default: "init_available_date" }),
|
2019-07-17 12:07:35 +00:00
|
|
|
eventController.find({
|
2019-07-18 16:13:27 +00:00
|
|
|
scopes: ['defaultScope', 'next', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
|
2019-07-17 12:07:35 +00:00
|
|
|
}),
|
2019-07-09 15:48:29 +00:00
|
|
|
);
|
2019-07-23 09:09:19 +00:00
|
|
|
|
2019-07-23 11:35:20 +00:00
|
|
|
routes.get('/events/past',
|
|
|
|
|
isLoggedUser,
|
2019-07-23 09:09:19 +00:00
|
|
|
FieldMiddleware.middleware({
|
2019-07-23 11:35:20 +00:00
|
|
|
invalidFields: generalInvalidFields
|
|
|
|
|
}),
|
|
|
|
|
PaginateMiddleware.middleware(),
|
|
|
|
|
SortMiddleware.middleware({ default: "-init_date" }),
|
2019-07-23 09:09:19 +00:00
|
|
|
eventController.find({
|
2019-07-23 11:35:20 +00:00
|
|
|
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
|
2019-07-23 09:09:19 +00:00
|
|
|
}),
|
|
|
|
|
);
|
2019-07-09 15:48:29 +00:00
|
|
|
|
2019-07-23 11:35:20 +00:00
|
|
|
routes.get('/events/today',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-17 12:07:35 +00:00
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
2019-07-23 11:35:20 +00:00
|
|
|
}),
|
2019-07-09 17:39:52 +00:00
|
|
|
PaginateMiddleware.middleware(),
|
2019-07-23 11:35:20 +00:00
|
|
|
SortMiddleware.middleware({ default: "-init_date" }),
|
2019-07-17 15:13:55 +00:00
|
|
|
eventController.find({
|
2019-07-23 11:35:20 +00:00
|
|
|
scopes: ['defaultScope', 'today', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
|
2019-07-17 15:13:55 +00:00
|
|
|
}),
|
2019-07-09 15:48:29 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
routes.get('/events/current',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-17 12:07:35 +00:00
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
|
|
|
|
}),
|
2019-07-09 17:39:52 +00:00
|
|
|
PaginateMiddleware.middleware(),
|
2019-07-18 11:23:43 +00:00
|
|
|
SortMiddleware.middleware({ default: "-init_date" }),
|
2019-07-17 15:34:54 +00:00
|
|
|
eventController.find({
|
2019-07-18 18:13:07 +00:00
|
|
|
scopes: ['defaultScope', 'current', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
|
2019-07-17 15:34:54 +00:00
|
|
|
}),
|
2019-07-09 15:48:29 +00:00
|
|
|
);
|
|
|
|
|
|
2019-07-09 17:39:52 +00:00
|
|
|
routes.get('/events/:id',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-17 12:07:35 +00:00
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
invalidFields: generalInvalidFields
|
2019-07-21 18:48:19 +00:00
|
|
|
}),
|
2019-07-21 17:53:07 +00:00
|
|
|
(req, res, next) => {
|
|
|
|
|
console.log(req.user.id);
|
|
|
|
|
return eventController.findOne({
|
|
|
|
|
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeSpeakers', { method: ['includeInscription', req.user.id] }]
|
2019-07-21 18:48:19 +00:00
|
|
|
})(req, res, next)
|
2019-07-21 17:53:07 +00:00
|
|
|
}
|
2019-07-09 17:39:52 +00:00
|
|
|
);
|
|
|
|
|
|
2019-07-09 18:34:39 +00:00
|
|
|
// Comentarios
|
|
|
|
|
|
2019-07-09 17:39:52 +00:00
|
|
|
routes.get('/events/:id/comments',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-12 11:19:15 +00:00
|
|
|
(req, res, next) => {
|
|
|
|
|
req.params.association = 'Comments';
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
eventController.find,
|
|
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Multimedias
|
|
|
|
|
routes.get('/events/:id/multimedias',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-12 11:19:15 +00:00
|
|
|
(req, res, next) => {
|
|
|
|
|
req.params.association = 'Multimedias';
|
|
|
|
|
next();
|
|
|
|
|
},
|
|
|
|
|
eventController.find,
|
2019-07-09 17:39:52 +00:00
|
|
|
);
|
2019-07-09 15:48:29 +00:00
|
|
|
|
2019-07-09 15:37:56 +00:00
|
|
|
|
2019-07-09 18:34:39 +00:00
|
|
|
// Inscripciones
|
2019-07-21 20:58:41 +00:00
|
|
|
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
|
2019-07-09 18:34:39 +00:00
|
|
|
routes.get('/events/:id/inscriptions',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-21 20:58:41 +00:00
|
|
|
eventController.getInscription,
|
2019-07-09 18:34:39 +00:00
|
|
|
);
|
|
|
|
|
|
2019-07-19 17:39:19 +00:00
|
|
|
// Hacer una inscripción
|
2019-07-09 18:34:39 +00:00
|
|
|
routes.post('/events/:id/inscriptions',
|
2019-07-21 13:30:49 +00:00
|
|
|
isLoggedUser,
|
2019-07-22 09:50:30 +00:00
|
|
|
SchemaValidator(eventValidation.InscriptionInputType, true),
|
2019-07-12 09:48:04 +00:00
|
|
|
eventController.createInscription
|
2019-07-09 18:34:39 +00:00
|
|
|
);
|
|
|
|
|
|
2019-07-25 16:39:18 +00:00
|
|
|
// Borrar una inscripción
|
|
|
|
|
routes.delete('/inscriptions/:id',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-25 16:39:18 +00:00
|
|
|
//SchemaValidator(eventValidation.InscriptionInputType, true),
|
|
|
|
|
eventController.deleteInscription
|
2019-07-09 18:34:39 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
routes.get('/events/:id/reservations/:encodedInvitationCode',
|
2019-07-21 14:15:22 +00:00
|
|
|
isLoggedUser,
|
2019-07-09 18:34:39 +00:00
|
|
|
//eventController.findComments
|
2019-07-19 19:36:20 +00:00
|
|
|
eventController.checkReservationCode
|
2019-07-09 18:34:39 +00:00
|
|
|
);
|
|
|
|
|
|
2019-07-23 11:35:20 +00:00
|
|
|
|
|
|
|
|
//WEB
|
|
|
|
|
|
|
|
|
|
//Eventos con inscripciones abiertas para la web
|
|
|
|
|
routes.get('/web/events',
|
|
|
|
|
// isLoggedUser,
|
|
|
|
|
FieldMiddleware.middleware({
|
|
|
|
|
validFields: ['id', 'name']
|
|
|
|
|
}),
|
|
|
|
|
// PaginateMiddleware.middleware(),
|
|
|
|
|
// SortMiddleware.middleware({ default: "init_available_date" }),
|
|
|
|
|
eventController.find({
|
|
|
|
|
scopes: ['defaultScope', 'withOpenInscriptions']
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
|
2019-07-23 11:52:14 +00:00
|
|
|
// Hacer una inscripción por la web
|
|
|
|
|
routes.post('/web/events/:id/inscriptions',
|
|
|
|
|
//SchemaValidator(eventValidation.webInscriptionInputType, true),
|
|
|
|
|
eventController.createInscription
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2019-07-21 17:36:25 +00:00
|
|
|
/*
|
|
|
|
|
routes.get('/tickets/:id/',
|
|
|
|
|
isLoggedUser,
|
|
|
|
|
eventController.findComments
|
|
|
|
|
);
|
|
|
|
|
*/
|
2019-07-09 18:34:39 +00:00
|
|
|
|
2019-07-09 08:51:00 +00:00
|
|
|
//routes.get('/venues', isLoggedUser, SortMiddleware.middleware({ default: "name" }), venueController.find);
|
|
|
|
|
//routes.get('/venues/:id', isLoggedUser, venueController.findOne);
|
|
|
|
|
|
|
|
|
|
//routes.post('/entity/', SchemaValidator(VenueValidation.VenueInputType, true), venueController.create);
|
|
|
|
|
//routes.put('/venues/:id', isAdministratorUser, venueController.update);
|
|
|
|
|
//routes.delete('/venues/:id', isAdministratorUser, venueController.delete);
|
|
|
|
|
|
|
|
|
|
module.exports = routes;
|