This commit is contained in:
David Arranz 2019-08-20 17:37:53 +02:00
parent e3976cb516
commit 0c59d2a2fc
4 changed files with 43 additions and 29 deletions

View File

@ -40,21 +40,22 @@ const extraControllers = {
},
//Funcion que devuelve:
//1. Todas las inscripciones de un evento, cuando el usuario es administrador (SIN HACER)
//1. Todas las inscripciones de un evento, cuando el usuario es administrador
//2. Todas las inscripciones de un usuario, cuando no nos llega ningun param con id
getInscriptions: async (req, res, next) => {
const params = extractParamsFromRequest(req, res, {});
const eventId = params.params.id;
const userId = req.user.id;
var result = null;
//req.user.rol Administrador ......
//req.user.rol normal ......
console.log(params);
if (eventId) {
try {
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
if (req.user.level = 8)
result = await eventInscriptionService._getInscriptionByEvent(eventId)
else
result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
return handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
} catch (error) {
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
@ -62,7 +63,7 @@ const extraControllers = {
}
else{
try {
const result = await eventInscriptionService._getInscriptionsUser(userId);
result = await eventInscriptionService._getInscriptionsUser(userId);
return handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
} catch (error) {
return handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
@ -464,10 +465,10 @@ console.log(mailOptions);
getReservationsExcel: async (req, res, next) => {
console.log('exxxxxxxxxxxxxxxcel');
const params = extractParamsFromRequest(req, res, {});
const inscriptionId = params.params.id;
const eventId = params.params.id;
const userId = req.user.id;
const inscription = await eventReservationService._getReservationsExcel(req.user, params.params.id, null, function(result, status){
const inscription = await eventReservationService._getReservationsExcel(req.user, eventId, null, function(result, status){
if (result.messenger.code == "S99001") {
console.log(result);
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');

View File

@ -196,11 +196,13 @@ module.exports = function (sequelize, DataTypes) {
});
Event.associate = function (models) {
// Event.OverflowEvent = Event.belongsTo(models.Event, {
// as: 'overflowEvent',
// foreignKey: 'overflow_eventId',
// required: false });
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
Event.OverflowEvent = Event.belongsTo(models.Event, {
as: 'overflowEvent',
foreignKey: 'overflow_eventId',
required: false });
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
Event.UserCreate = Event.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId', as: "venue",
required: false,
@ -270,6 +272,13 @@ module.exports = function (sequelize, DataTypes) {
}
});
Event.addScope('includeOverflowEvent', () => {
return {
include: [
{ model: sequelize.models.Event, as: 'overflowEvent', required: false}
]
}
});
Event.addScope('includeDetails', () => {
return {

View File

@ -134,14 +134,14 @@ routes.get('/events/:id/multimedias',
eventController.find,
);
// Inscripciones
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
// Esto da las inscripciones de un usuario
routes.get('/events/:id/inscriptions',
isLoggedUser,
isLoggedUser,
eventController.getInscriptions,
);
// Esto da todas las inscripciones de un usuario
routes.get('/me/inscriptions/count',
isLoggedUser,
@ -262,6 +262,13 @@ routes.get('/tickets/:id/',
* ADMINISTRACIÓN
*********************************************************************************************************
*/
// Inscripciones
// Esto da las inscripciones de un evento
routes.get('/admin/events/:id/inscriptions',
isAdministratorUser,
PaginateMiddleware.middleware(),
eventController.getInscriptions,
);
// Todos los ponentes
routes.get('/admin/events',
@ -311,7 +318,7 @@ routes.get('/admin/events/:id',
isAdministratorUser,
(req, res, next) => {
return eventController.findOne({
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeDetails']
scopes: ['defaultScope', 'includeVenue', 'includeMultimedias', 'includeOverflowEvent', 'includeDetails']
})(req, res, next)
}
);
@ -362,15 +369,4 @@ routes.delete('/admin/reservations/:id',
eventReservationController.delete()
);
routes.get('/inscriptions',
isAdministratorUser,
//SchemaValidator(eventValidation.ReservationInputType, true),
(req, res, next) => {
return eventInscriptionController.find({
scopes: ['defaultScope']
})(req, res, next)
},
);
module.exports = routes;

View File

@ -51,6 +51,14 @@ const extraMethods = {
})
},
_getInscriptionByEvent: (eventId) => {
return models.EventInscription.scope('defaultScope').findAll({
where: {
eventId: eventId,
},
})
},
_getInscriptionsUser: (userId) => {
return models.EventInscription.scope('includeEventAndVenue').findAll({
attributes: {