a
This commit is contained in:
parent
b912abe399
commit
f9f272917a
@ -853,6 +853,11 @@ routes.get('/admin/events/:id/reservations/:type/mail',
|
||||
eventReservationController.sendMailReservationsEvent,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/entity/:entityId/reservations/mail',
|
||||
isAdministratorUser,
|
||||
eventReservationController.sendMailReservationsEvent,
|
||||
);
|
||||
|
||||
|
||||
routes.get('/admin/events/:eventId/partners/:entityId/reservations',
|
||||
isAdministratorUser,
|
||||
|
||||
@ -91,25 +91,35 @@ const extraControllers = {
|
||||
sendMailReservationsEvent: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const eventId = params.params.id;
|
||||
const type = params.params.type;
|
||||
const entityId = params.params.entityId;
|
||||
const type = params.params.type;
|
||||
const user = req.user;
|
||||
let reservations = null;
|
||||
let result = "";
|
||||
|
||||
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)
|
||||
return handleResultResponse("Reservas no encontradas", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
try {
|
||||
reservations.forEach(function (reservation) {
|
||||
// console.log('mando correo: ', reservation.Entity.name);
|
||||
if (reservation.Entity.contact_email)
|
||||
if (reservation.Entity.contact_email) {
|
||||
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) {
|
||||
// console.log(error);
|
||||
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) {
|
||||
return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
@ -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) => {
|
||||
return models.EventReservation.findAll({
|
||||
where: { eventId: eventId },
|
||||
|
||||
Loading…
Reference in New Issue
Block a user