This commit is contained in:
David Arranz 2019-07-25 20:43:03 +02:00
parent 631cded9b6
commit 7ae05f30c4
3 changed files with 37 additions and 10 deletions

View File

@ -35,17 +35,36 @@ const extraControllers = {
}
},
getInscription: async (req, res, next) => {
//Funcion que devuelve:
//1. Todas las inscripciones de un evento, cuando el usuario es administrador (SIN HACER)
//2. Todas las inscripciones de un usuario, cuando no nos llega ningun param con id
getInscriptions: async (req, res, next) => {
console.log('aaaaaaaaaaaaaaaaaaaaaaaa');
const params = extractParamsFromRequest(req, res, {});
const eventId = params.params.id;
const userId = req.user.id;
try {
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
} catch (error) {
handleErrorResponse(MODULE_NAME, 'getInscription', error, res)
//req.user.rol Administrador ......
//req.user.rol normal ......
if (eventId) {
try {
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
} catch (error) {
handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
}
}
else{
try {
const result = await eventInscriptionService._getInscriptionsUser(userId);
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
} catch (error) {
handleErrorResponse(MODULE_NAME, 'getInscriptions', error, res)
}
}
},
deleteInscription: async (req, res, next) => {

View File

@ -118,13 +118,13 @@ routes.get('/events/:id/multimedias',
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
routes.get('/events/:id/inscriptions',
isLoggedUser,
eventController.getInscription,
eventController.getInscriptions,
);
// Esto da las inscripciones (1) de un usuario pero si el usuario fuera el administrador podría todas las inscripciones de un evento
routes.get('/inscriptions/:id/inscriptions',
// Esto da todas las inscripciones de un usuario
routes.get('/me/inscriptions',
isLoggedUser,
eventController.getInscription,
eventController.getInscriptions,
);
// Hacer una inscripción

View File

@ -25,6 +25,14 @@ const extraMethods = {
})
},
_getInscriptionsUser: (userId) => {
return models.EventInscription.findAll({
where: {
userId: userId
},
})
},
//Nos devuelve el número de inscripciones confirmadas para ese evento sin tener en cuenta reservas
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
return models.EventInscription.count({