This commit is contained in:
David Arranz 2019-10-15 16:18:17 +02:00
parent b912abe399
commit f9f272917a
3 changed files with 26 additions and 4 deletions

View File

@ -853,6 +853,11 @@ routes.get('/admin/events/:id/reservations/:type/mail',
eventReservationController.sendMailReservationsEvent, eventReservationController.sendMailReservationsEvent,
); );
routes.get('/admin/events/:id/entity/:entityId/reservations/mail',
isAdministratorUser,
eventReservationController.sendMailReservationsEvent,
);
routes.get('/admin/events/:eventId/partners/:entityId/reservations', routes.get('/admin/events/:eventId/partners/:entityId/reservations',
isAdministratorUser, isAdministratorUser,

View File

@ -91,25 +91,35 @@ const extraControllers = {
sendMailReservationsEvent: async (req, res, next) => { sendMailReservationsEvent: async (req, res, next) => {
const params = extractParamsFromRequest(req, res, {}); const params = extractParamsFromRequest(req, res, {});
const eventId = params.params.id; const eventId = params.params.id;
const entityId = params.params.entityId;
const type = params.params.type; const type = params.params.type;
const user = req.user; const user = req.user;
let reservations = null;
let result = "";
try { try {
const reservations = await eventReservationService._getReservasByEventAndType(eventId, type); if (!entityId)
reservations = await eventReservationService._getReservasByEventAndType(eventId, type);
else
reservations = await eventReservationService._getReservasByEventAndEntity(eventId, entityId);
if (!reservations) if (!reservations)
return handleResultResponse("Reservas no encontradas", null, params, res, httpStatus.NOT_FOUND); return handleResultResponse("Reservas no encontradas", null, params, res, httpStatus.NOT_FOUND);
try { try {
reservations.forEach(function (reservation) { reservations.forEach(function (reservation) {
// console.log('mando correo: ', reservation.Entity.name); // console.log('mando correo: ', reservation.Entity.name);
if (reservation.Entity.contact_email) if (reservation.Entity.contact_email) {
emailHelper.sendReservationCode(generateHeaderMail(reservation), generateBodyMail(reservation)); emailHelper.sendReservationCode(generateHeaderMail(reservation), generateBodyMail(reservation));
result = result + 'Invitación con código ' + reservation.reservation_code + ' enviada a ' + reservation.Entity.Name + ' al destinatario ' + reservation.Entity.contact_mail + '/n'
}
}); });
} catch (error) { } catch (error) {
// console.log(error); // console.log(error);
console.log('No se ha podido mandar email con los códigos de invitación'); console.log('No se ha podido mandar email con los códigos de invitación');
}; };
return handleResultResponse(null, null, params, res, httpStatus.OK); return handleResultResponse(result, null, params, res, httpStatus.OK);
} catch (error) { } catch (error) {
return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND); return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND);

View File

@ -35,6 +35,13 @@ const extraMethods = {
}) })
}, },
_getReservasByEventAndEntity: (eventId, entityId) => {
return models.EventReservation.findAll({
where: { eventId: eventId, entityId: entityId },
include: [{ model: models.Event }, { model: models.Entity }]
})
},
_getReservasByEventAndType: (eventId, type) => { _getReservasByEventAndType: (eventId, type) => {
return models.EventReservation.findAll({ return models.EventReservation.findAll({
where: { eventId: eventId }, where: { eventId: eventId },