a
This commit is contained in:
parent
907fa90d24
commit
30d231af37
@ -41,7 +41,6 @@ const localEmailOptions = {
|
||||
passport.use('local-email', new LocalStrategy(localEmailOptions, async (email, password, done) => {
|
||||
try {
|
||||
let user = await authService.extraMethods.findUser({ email });
|
||||
|
||||
if (_.isNull(user)) {
|
||||
return done(null, false, { message: 'User not found' })
|
||||
} else {
|
||||
|
||||
@ -9,10 +9,11 @@ const assetsUrl = config.cdn.hostname;
|
||||
const CDN_PATHS = {
|
||||
BLOG: "blog/",
|
||||
CITIES: "cities/",
|
||||
EVENT: "events/",
|
||||
EVENT: "events/",
|
||||
PROFILE: "profile/",
|
||||
SPEAKERS: "speakers/",
|
||||
WALLPAPERS: "wallpapers/"
|
||||
WALLPAPERS: "wallpapers/",
|
||||
XLSX: "xlsx/",
|
||||
};
|
||||
|
||||
const sanitizeFilename = (filename) => safename(sanitize(filename, { replacement: "_" }));
|
||||
@ -50,7 +51,11 @@ const getCDNPath = (type = '') => {
|
||||
case 'post':
|
||||
cdnPath = CDN_PATHS.BLOG;
|
||||
break;
|
||||
|
||||
|
||||
case 'xlsx':
|
||||
cdnPath = CDN_PATHS.XLSX;
|
||||
break;
|
||||
|
||||
default:
|
||||
var _date = new Date();
|
||||
cdnPath = _date.getFullYear() + '/' + (_date.getMonth() + 1) + '/';
|
||||
|
||||
@ -3,6 +3,7 @@ const httpStatus = require('http-status');
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const QRHelper = require('../../helpers/qr.helper');
|
||||
const emailHelper = require('../../helpers/mail.helper');
|
||||
const path = require("path");
|
||||
const messages = require('../../helpers/messages.json');
|
||||
const eventService = require('./event.service');
|
||||
const eventReservationService = require('./events_reservations.service');
|
||||
@ -117,11 +118,8 @@ const extraControllers = {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
try {
|
||||
const result = await eventReservationService._getPartners(params.params.id);
|
||||
console.log('xxxxxx2');
|
||||
console.log(result)
|
||||
return handleResultResponse(result, result.count, params, res, httpStatus.OK);
|
||||
} catch (error) {
|
||||
console.log('xxxxxxxx3');
|
||||
return handleErrorResponse(MODULE_NAME, 'findPartners', error, res)
|
||||
}
|
||||
},
|
||||
@ -461,7 +459,26 @@ console.log(mailOptions);
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
getReservationsExcel: async (req, res, next) => {
|
||||
console.log('exxxxxxxxxxxxxxxcel');
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const inscriptionId = params.params.id;
|
||||
const userId = req.user.id;
|
||||
|
||||
const inscription = await eventReservationService._getReservationsExcel(req.user, params.params.id, null, 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);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -317,25 +317,30 @@ routes.get('/admin/events/:id',
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/partners',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
eventController.findPartners,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:id/reservations/excel',
|
||||
isAdministratorUser,
|
||||
eventController.getReservationsExcel,
|
||||
);
|
||||
|
||||
routes.get('/admin/events/:eventId/partners/:entityId/reservations',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
eventReservationController.find(),
|
||||
);
|
||||
|
||||
|
||||
routes.post('/admin/reservations',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
//SchemaValidator(eventValidation.ReservationInputType, true),
|
||||
eventReservationController.create(),
|
||||
|
||||
);
|
||||
|
||||
routes.get('/admin/reservations/:id',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
//SchemaValidator(eventValidation.ReservationInputType, true),
|
||||
(req, res, next) => {
|
||||
return eventReservationController.findOne({
|
||||
@ -346,19 +351,19 @@ routes.get('/admin/reservations/:id',
|
||||
);
|
||||
|
||||
routes.put('/admin/reservations/:id',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
//SchemaValidator(eventValidation.ReservationInputType, true),
|
||||
eventReservationController.update(),
|
||||
);
|
||||
|
||||
// Borrar reserva
|
||||
routes.delete('/admin/reservations/:id',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
eventReservationController.delete()
|
||||
);
|
||||
|
||||
routes.get('/inscriptions',
|
||||
// isAdministratorUser,
|
||||
isAdministratorUser,
|
||||
//SchemaValidator(eventValidation.ReservationInputType, true),
|
||||
(req, res, next) => {
|
||||
return eventInscriptionController.find({
|
||||
|
||||
@ -192,6 +192,7 @@ const extraMethods = {
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
@ -121,5 +121,6 @@ module.exports = function (sequelize, DataTypes) {
|
||||
}]
|
||||
}
|
||||
});
|
||||
|
||||
return EventReservation;
|
||||
};
|
||||
@ -2,9 +2,14 @@
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const moment = require('moment');
|
||||
const Sequelize = require('sequelize');
|
||||
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
||||
const models = require('../../core/models');
|
||||
const xlsx = require("node-xlsx");
|
||||
const fs = require("fs");
|
||||
const cdnHelper = require('../../helpers/cdn.helper');
|
||||
|
||||
|
||||
const extraMethods = {
|
||||
|
||||
@ -65,6 +70,110 @@ const extraMethods = {
|
||||
});
|
||||
},
|
||||
|
||||
_getReservationsExcel: (user, eventId, partnerId, callback) => {
|
||||
models.EventReservation.findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
},
|
||||
include: [{
|
||||
model: models.Event,
|
||||
attributes: ['id', 'name'],
|
||||
}, {
|
||||
model: models.Entity,
|
||||
},
|
||||
{
|
||||
model: models.EventInscription,
|
||||
as: 'inscriptions',
|
||||
required: false,
|
||||
}],
|
||||
|
||||
order: [
|
||||
[{ model: models.Entity}, 'name', 'ASC'],
|
||||
['reservation_code', 'ASC'],
|
||||
[{ model: models.EventInscription, as: 'inscriptions'}, 'date', 'ASC']
|
||||
]
|
||||
|
||||
}).then(function (reservations) {
|
||||
if (reservations.length) {
|
||||
var data = [];
|
||||
|
||||
data.push(["Congreso: " + reservations[0].Event.name]);
|
||||
data.push(["Fecha del listado: " + moment().toString()]);
|
||||
data.push([]);
|
||||
data.push(["Nombre", "Apellidos", "Email", "Válido", "Vía", "N. entrada"]);
|
||||
|
||||
var currentReservation = '';
|
||||
var currentPartner = '';
|
||||
reservations.forEach(function(reserva) {
|
||||
|
||||
if (currentPartner != reserva.Entity.name) {
|
||||
currentPartner = reserva.Entity.name;
|
||||
data.push([]);
|
||||
data.push([]);
|
||||
};
|
||||
|
||||
if (currentReservation != reserva.reservation_code) {
|
||||
currentReservation = reserva.reservation_code;
|
||||
data.push([]);
|
||||
data.push(["Partner: " + reserva.Entity.name + " CÓDIGO: " + reserva.reservation_code, "Tipo: " + reserva.description, "Reservadas: " + reserva.confirmed, "Aforo: " + reserva.assistants]);
|
||||
|
||||
data.push(["Nombre", "Apellidos", "Email", "Válido", "Vía", "N. entrada"]);
|
||||
};
|
||||
|
||||
reserva.inscriptions.forEach(function (inscription) {
|
||||
data.push([inscription.user.name, inscription.user.surname, inscription.user.email, inscription.validated ? "Confirmado" : "En lista de espera", inscription.source, inscription.code_ticket]);
|
||||
});
|
||||
});
|
||||
|
||||
var buffer = xlsx.build([{
|
||||
name: reservations[0].Event.name,
|
||||
data: data,
|
||||
}], {
|
||||
'!cols': [{ wch: 15 }, { wch: 25 }, { wch: 30 }, { wch: 10 }, { wch: 20 }, { wch: 20 }, { wch: 5 }]
|
||||
});
|
||||
|
||||
var fileName = cdnHelper.sanitizeFilename(reservations[0].Event.name + "-invitaciones.xlsx");
|
||||
var xlsxPath = cdnHelper.getCDNPath('xlsx') + fileName;
|
||||
var wstream = fs.createWriteStream(xlsxPath);
|
||||
wstream.write(buffer);
|
||||
wstream.end();
|
||||
|
||||
wstream.on("close", function () {
|
||||
return callback({
|
||||
messenger: {
|
||||
success: true,
|
||||
message: 'Ok',
|
||||
code: 'S99001'
|
||||
},
|
||||
data: {
|
||||
path: xlsxPath,
|
||||
name: fileName
|
||||
}
|
||||
}, 200);
|
||||
});
|
||||
} else {
|
||||
return callback({
|
||||
messenger: {
|
||||
success: true,
|
||||
message: 'Ok',
|
||||
code: 'S99002'
|
||||
}
|
||||
}, 200);
|
||||
}
|
||||
}).catch(function (error) {
|
||||
console.log(error);
|
||||
return callback({
|
||||
messenger: {
|
||||
success: false,
|
||||
message: 'Database error getting invitations.',
|
||||
code: 'E01004'
|
||||
}
|
||||
}, 500);
|
||||
});
|
||||
},
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateService(models.EventReservation, extraMethods);
|
||||
@ -50,6 +50,7 @@
|
||||
"mysql2": "^1.6.5",
|
||||
"node-fetch": "^2.3.0",
|
||||
"node-mailjet": "^3.3.1",
|
||||
"node-xlsx": "^0.15.0",
|
||||
"os": "^0.1.1",
|
||||
"passport": "^0.4.0",
|
||||
"passport-custom": "^1.0.5",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user