diff --git a/helpers/mail.helper.js b/helpers/mail.helper.js index 9ef5996..73cd18b 100644 --- a/helpers/mail.helper.js +++ b/helpers/mail.helper.js @@ -28,9 +28,18 @@ function send(header, body) { }], "Subject": header.subject, }, - body + + (!header.bcc) ? {} : { + "Bcc": [{ + "Email": header.bcc, + "Name": header.bccName + }] + }, + + body, ); +//console.log('PARAAAAAAAAAAAAAAAAAAAAMSSS MAILLL>', params); const mailjet = require('node-mailjet') .connect(mailjet_public, mailjet_private) const request = mailjet @@ -112,6 +121,28 @@ function sendListaEspera(header, values) { return send(header, body); }; +function sendReservationCode(header, values) { + + const body = { + "TemplateID": 1041673, + "TemplateLanguage": true, + "TemplateErrorDeliver": true, + "TemplateErrorReporting": { + "Email": "info@rodax-software.com", + "Name": "Air traffic control" + }, + "Variables": { + "entityName": values.entityName, + "eventName": values.eventName, + "dateEvent": values.dateEvent, + "reservationCode": values.reservationCode, + "reservationDescription": (values.reservationDescription) ? values.reservationDescription : '-', + } + }; + + return send(header, body); +}; + function sendCancelacion(header, values) { const body = { @@ -165,5 +196,6 @@ module.exports = { sendTicket, sendListaEspera, sendCancelacion, + sendReservationCode, }; \ No newline at end of file diff --git a/modules/events/events_reservations.controller.js b/modules/events/events_reservations.controller.js index d464496..3a277c1 100644 --- a/modules/events/events_reservations.controller.js +++ b/modules/events/events_reservations.controller.js @@ -69,7 +69,7 @@ const extraControllers = { const reservationId = params.params.id; const user = req.user; try { - const reservation = await eventReservationService._getReservaWithEntityAndEventById(reservationId); + const reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(reservationId); if (!reservation) return handleResultResponse("Reserva no encontrada", null, params, res, httpStatus.NOT_FOUND); @@ -91,15 +91,16 @@ const extraControllers = { sendMailReservationsEvent: async (req, res, next) => { const params = extractParamsFromRequest(req, res, {}); const eventId = params.params.id; + const type = params.params.type; const user = req.user; try { - const reservations = await eventReservationService._getReservaByEvent(eventId); + const reservations = await eventReservationService._getReservasByEventAndType(eventId, type); if (!reservations) return handleResultResponse("Reservas no encontradas", null, params, res, httpStatus.NOT_FOUND); try { reservations.forEach(function (reservation) { -// console.log(reservation.reservation_code); +// console.log('mando correo: ', reservation.Entity.name); if (reservation.Entity.contact_email) emailHelper.sendReservationCode(generateHeaderMail(reservation), generateBodyMail(reservation)); }); @@ -111,7 +112,7 @@ const extraControllers = { return handleResultResponse(null, null, params, res, httpStatus.OK); } catch (error) { - return handleResultResponse("Error al buscar la reserva", null, params, res, httpStatus.NOT_FOUND); + return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND); } }, diff --git a/modules/events/events_reservations.service.js b/modules/events/events_reservations.service.js index 1246e99..3f7d1f4 100644 --- a/modules/events/events_reservations.service.js +++ b/modules/events/events_reservations.service.js @@ -28,14 +28,14 @@ const extraMethods = { }) }, - _getReservaWithEntityAndEventById: (Id) => { + _getReservaByIdWithEntityAndEvent: (Id) => { return models.EventReservation.findOne({ where: { id: Id }, include: [{ model: models.Event }, { model: models.Entity }] }) - }, + }, - _getReservaByEvent: (eventId, type) => { + _getReservasByEventAndType: (eventId, type) => { return models.EventReservation.findAll({ where: { eventId: eventId }, include: [{ @@ -45,6 +45,7 @@ const extraMethods = { model: models.Entity, include: [{ model: models.EntityType, as: 'types', where: getWhereTypeEntity(type) }] }], + order: [['entityId', 'asc']], }) },