Merge branch 'master' of wopr.rodax-software.com:lqdvi/app2-api
This commit is contained in:
commit
73f90217d4
@ -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,
|
||||
|
||||
};
|
||||
@ -737,24 +737,6 @@ console.log('Mandamos mail con entrada>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
}
|
||||
},
|
||||
|
||||
getReservationsExcel: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const eventId = params.params.id;
|
||||
const type = params.params.type;
|
||||
const userId = req.user.id;
|
||||
|
||||
const reservations = await eventReservationService._getReservationsExcel(req.user, eventId, null, type, function(result, status){
|
||||
if (result.messenger.code == "S99001") {
|
||||
console.log(result);
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=' + result.data.name);
|
||||
res.attachment(result.data.name);
|
||||
res.download(path.resolve(result.data.path), result.data.name);
|
||||
} else {
|
||||
res.status(status).json(result);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
getInscripcionsExcel: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
|
||||
@ -835,12 +835,12 @@ routes.get('/admin/events/:id/colleges',
|
||||
|
||||
routes.get('/admin/events/:id/reservations/excel',
|
||||
isAdministratorUser,
|
||||
eventController.getReservationsExcel,
|
||||
eventReservationController.getReservationsExcel,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/reservations/:type/excel',
|
||||
isAdministratorUser,
|
||||
eventController.getReservationsExcel,
|
||||
eventReservationController.getReservationsExcel,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/inscriptions/excel',
|
||||
@ -848,6 +848,17 @@ routes.get('/admin/events/:id/inscriptions/excel',
|
||||
eventController.getInscripcionsExcel,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/reservations/:type/mail',
|
||||
isAdministratorUser,
|
||||
eventReservationController.sendMailReservationsEvent,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/entity/:entityId/reservations/mail',
|
||||
isAdministratorUser,
|
||||
eventReservationController.sendMailReservationsEvent,
|
||||
);
|
||||
|
||||
|
||||
routes.get('/admin/events/:eventId/partners/:entityId/reservations',
|
||||
isAdministratorUser,
|
||||
eventReservationController.find(),
|
||||
@ -880,6 +891,11 @@ routes.get('/admin/inscriptions/:id/mail',
|
||||
eventController.sendMailTicket,
|
||||
);
|
||||
|
||||
routes.get('/admin/reservations/:id/mail',
|
||||
isAdministratorUser,
|
||||
eventReservationController.sendMailReservation,
|
||||
);
|
||||
|
||||
|
||||
routes.post('/admin/reservations',
|
||||
isAdministratorUser,
|
||||
|
||||
@ -1,14 +1,132 @@
|
||||
'use strict';
|
||||
|
||||
const moment = require('moment');
|
||||
const httpStatus = require('http-status');
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const eventReservationService = require('./events_reservations.service');
|
||||
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
|
||||
const emailHelper = require('../../helpers/mail.helper');
|
||||
const path = require("path");
|
||||
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = '[eventReservation.controller]';
|
||||
|
||||
const controllerOptions = { MODULE_NAME };
|
||||
const extraControllers = {};
|
||||
|
||||
function generateHeaderMail(reservation) {
|
||||
let headerMail = null;
|
||||
if (reservation) {
|
||||
headerMail = {
|
||||
to: reservation.Entity.contact_email,
|
||||
name: reservation.Entity.name,
|
||||
bcc: "rbrrbr2000@gmail.com",
|
||||
bccName: "Carolina Barrantes",
|
||||
subject: 'Códigos de invitación para congreso LQDVI'
|
||||
}
|
||||
};
|
||||
return headerMail;
|
||||
}
|
||||
|
||||
function generateBodyMail(reservation) {
|
||||
let bodyMail = null;
|
||||
if (reservation) {
|
||||
bodyMail = {
|
||||
entityName: reservation.Entity.name,
|
||||
eventName: reservation.Event.name,
|
||||
dateEvent: moment(reservation.Event.init_date).format('D [de] MMMM [de] YYYY'),
|
||||
reservationCode: reservation.reservation_code,
|
||||
reservationDescription: reservation.description,
|
||||
}
|
||||
};
|
||||
return bodyMail;
|
||||
}
|
||||
|
||||
const extraControllers = {
|
||||
|
||||
getReservationsExcel: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const eventId = params.params.id;
|
||||
const type = params.params.type;
|
||||
const userId = req.user.id;
|
||||
|
||||
const reservations = await eventReservationService._getReservationsExcel(req.user, eventId, null, type, function (result, status) {
|
||||
if (result.messenger.code == "S99001") {
|
||||
console.log(result);
|
||||
res.setHeader('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename=' + result.data.name);
|
||||
res.attachment(result.data.name);
|
||||
res.download(path.resolve(result.data.path), result.data.name);
|
||||
} else {
|
||||
res.status(status).json(result);
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
sendMailReservation: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const reservationId = params.params.id;
|
||||
const user = req.user;
|
||||
try {
|
||||
const reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(reservationId);
|
||||
if (!reservation)
|
||||
return handleResultResponse("Reserva no encontrada", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
try {
|
||||
if (reservation.Entity.contact_email)
|
||||
emailHelper.sendReservationCode(generateHeaderMail(reservation), generateBodyMail(reservation));
|
||||
} 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);
|
||||
|
||||
} catch (error) {
|
||||
return handleResultResponse("Error al buscar la reserva", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
},
|
||||
|
||||
sendMailReservationsEvent: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const eventId = params.params.id;
|
||||
const entityId = params.params.entityId;
|
||||
const type = params.params.type;
|
||||
const user = req.user;
|
||||
let reservations = null;
|
||||
let result = "";
|
||||
|
||||
try {
|
||||
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) {
|
||||
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_email + '\n'
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
// console.log(error);
|
||||
console.log('No se ha podido mandar email con los códigos de invitación');
|
||||
};
|
||||
|
||||
return handleResultResponse(result, null, params, res, httpStatus.OK);
|
||||
|
||||
} catch (error) {
|
||||
return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateControllers(eventReservationService, extraControllers, controllerOptions);
|
||||
|
||||
|
||||
@ -10,6 +10,15 @@ const xlsx = require("node-xlsx");
|
||||
const fs = require("fs");
|
||||
const cdnHelper = require('../../helpers/cdn.helper');
|
||||
|
||||
function getWhereTypeEntity(type) {
|
||||
var whereType = {};
|
||||
if (type == 'partners')
|
||||
whereType = { alias: 'partner' }
|
||||
else if (type == 'colleges')
|
||||
whereType = { alias: 'college' };
|
||||
return whereType;
|
||||
}
|
||||
|
||||
|
||||
const extraMethods = {
|
||||
|
||||
@ -19,6 +28,34 @@ const extraMethods = {
|
||||
})
|
||||
},
|
||||
|
||||
_getReservaByIdWithEntityAndEvent: (Id) => {
|
||||
return models.EventReservation.findOne({
|
||||
where: { id: Id },
|
||||
include: [{ model: models.Event }, { model: models.Entity }]
|
||||
})
|
||||
},
|
||||
|
||||
_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 },
|
||||
include: [{
|
||||
model: models.Event,
|
||||
},
|
||||
{
|
||||
model: models.Entity,
|
||||
include: [{ model: models.EntityType, as: 'types', where: getWhereTypeEntity(type) }]
|
||||
}],
|
||||
order: [['entityId', 'asc']],
|
||||
})
|
||||
},
|
||||
|
||||
_getReservaByCode: (eventId, code) => {
|
||||
return models.EventReservation.findOne({
|
||||
where: { reservation_code: code, eventId: eventId },
|
||||
@ -88,12 +125,6 @@ const extraMethods = {
|
||||
_getReservationsExcel: (user, eventId, partnerId, type, callback) => {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>><consulta con type:', type);
|
||||
|
||||
var whereType = {};
|
||||
if (type == 'partners')
|
||||
whereType = { alias: 'partner'}
|
||||
else if (type == 'colleges')
|
||||
whereType = { alias: 'college' };
|
||||
|
||||
models.EventReservation.findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
@ -103,7 +134,7 @@ const extraMethods = {
|
||||
attributes: ['id', 'name'],
|
||||
}, {
|
||||
model: models.Entity,
|
||||
include: [{ model: models.EntityType, as: 'types', where: whereType }]
|
||||
include: [{ model: models.EntityType, as: 'types', where: getWhereTypeEntity(type) }]
|
||||
},
|
||||
{
|
||||
model: models.EventInscription,
|
||||
@ -195,9 +226,7 @@ const extraMethods = {
|
||||
}, 500);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateService(models.EventReservation, extraMethods);
|
||||
Loading…
Reference in New Issue
Block a user