a
This commit is contained in:
parent
631cded9b6
commit
7ae05f30c4
@ -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 params = extractParamsFromRequest(req, res, {});
|
||||||
const eventId = params.params.id;
|
const eventId = params.params.id;
|
||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
|
|
||||||
try {
|
//req.user.rol Administrador ......
|
||||||
const result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
|
||||||
handleResultResponse(result, null, params, res, (result === null) ? httpStatus.NOT_FOUND : httpStatus.OK);
|
//req.user.rol normal ......
|
||||||
} catch (error) {
|
|
||||||
handleErrorResponse(MODULE_NAME, 'getInscription', error, res)
|
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) => {
|
deleteInscription: async (req, res, next) => {
|
||||||
|
|||||||
@ -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
|
// 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',
|
routes.get('/events/:id/inscriptions',
|
||||||
isLoggedUser,
|
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
|
// Esto da todas las inscripciones de un usuario
|
||||||
routes.get('/inscriptions/:id/inscriptions',
|
routes.get('/me/inscriptions',
|
||||||
isLoggedUser,
|
isLoggedUser,
|
||||||
eventController.getInscription,
|
eventController.getInscriptions,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hacer una inscripción
|
// Hacer una inscripción
|
||||||
|
|||||||
@ -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
|
//Nos devuelve el número de inscripciones confirmadas para ese evento sin tener en cuenta reservas
|
||||||
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
|
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
|
||||||
return models.EventInscription.count({
|
return models.EventInscription.count({
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user