a
This commit is contained in:
parent
61488977e6
commit
b912abe399
@ -28,9 +28,18 @@ function send(header, body) {
|
|||||||
}],
|
}],
|
||||||
"Subject": header.subject,
|
"Subject": header.subject,
|
||||||
},
|
},
|
||||||
body
|
|
||||||
|
(!header.bcc) ? {} : {
|
||||||
|
"Bcc": [{
|
||||||
|
"Email": header.bcc,
|
||||||
|
"Name": header.bccName
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
|
||||||
|
body,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
//console.log('PARAAAAAAAAAAAAAAAAAAAAMSSS MAILLL>', params);
|
||||||
const mailjet = require('node-mailjet')
|
const mailjet = require('node-mailjet')
|
||||||
.connect(mailjet_public, mailjet_private)
|
.connect(mailjet_public, mailjet_private)
|
||||||
const request = mailjet
|
const request = mailjet
|
||||||
@ -112,6 +121,28 @@ function sendListaEspera(header, values) {
|
|||||||
return send(header, body);
|
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) {
|
function sendCancelacion(header, values) {
|
||||||
|
|
||||||
const body = {
|
const body = {
|
||||||
@ -165,5 +196,6 @@ module.exports = {
|
|||||||
sendTicket,
|
sendTicket,
|
||||||
sendListaEspera,
|
sendListaEspera,
|
||||||
sendCancelacion,
|
sendCancelacion,
|
||||||
|
sendReservationCode,
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -69,7 +69,7 @@ const extraControllers = {
|
|||||||
const reservationId = params.params.id;
|
const reservationId = params.params.id;
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
try {
|
try {
|
||||||
const reservation = await eventReservationService._getReservaWithEntityAndEventById(reservationId);
|
const reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(reservationId);
|
||||||
if (!reservation)
|
if (!reservation)
|
||||||
return handleResultResponse("Reserva no encontrada", null, params, res, httpStatus.NOT_FOUND);
|
return handleResultResponse("Reserva no encontrada", null, params, res, httpStatus.NOT_FOUND);
|
||||||
|
|
||||||
@ -91,15 +91,16 @@ 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 type = params.params.type;
|
||||||
const user = req.user;
|
const user = req.user;
|
||||||
try {
|
try {
|
||||||
const reservations = await eventReservationService._getReservaByEvent(eventId);
|
const reservations = await eventReservationService._getReservasByEventAndType(eventId, type);
|
||||||
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(reservation.reservation_code);
|
// 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));
|
||||||
});
|
});
|
||||||
@ -111,7 +112,7 @@ const extraControllers = {
|
|||||||
return handleResultResponse(null, null, params, res, httpStatus.OK);
|
return handleResultResponse(null, null, params, res, httpStatus.OK);
|
||||||
|
|
||||||
} catch (error) {
|
} 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);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@ -28,14 +28,14 @@ const extraMethods = {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_getReservaWithEntityAndEventById: (Id) => {
|
_getReservaByIdWithEntityAndEvent: (Id) => {
|
||||||
return models.EventReservation.findOne({
|
return models.EventReservation.findOne({
|
||||||
where: { id: Id },
|
where: { id: Id },
|
||||||
include: [{ model: models.Event }, { model: models.Entity }]
|
include: [{ model: models.Event }, { model: models.Entity }]
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
_getReservaByEvent: (eventId, type) => {
|
_getReservasByEventAndType: (eventId, type) => {
|
||||||
return models.EventReservation.findAll({
|
return models.EventReservation.findAll({
|
||||||
where: { eventId: eventId },
|
where: { eventId: eventId },
|
||||||
include: [{
|
include: [{
|
||||||
@ -45,6 +45,7 @@ const extraMethods = {
|
|||||||
model: models.Entity,
|
model: models.Entity,
|
||||||
include: [{ model: models.EntityType, as: 'types', where: getWhereTypeEntity(type) }]
|
include: [{ model: models.EntityType, as: 'types', where: getWhereTypeEntity(type) }]
|
||||||
}],
|
}],
|
||||||
|
order: [['entityId', 'asc']],
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user