. repaso exportacion excel reservations
This commit is contained in:
parent
07f39194aa
commit
02cac75ff9
@ -457,9 +457,8 @@ routes.get(
|
||||
eventController.syncronizeMarketingList
|
||||
);
|
||||
|
||||
|
||||
routes.get(
|
||||
"/admin/events/:id/reservations/:type/excel",
|
||||
"/admin/events/:id/reservations/:typeOrId/excel",
|
||||
isAdministratorUser,
|
||||
eventReservationController.getReservationsExcel
|
||||
);
|
||||
|
||||
@ -42,9 +42,48 @@ async function _addConfirmedToEvent(confirmed, event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
async function activeReservation(reservation) {
|
||||
if (!reservation)
|
||||
throw new Error("activeReservation: reservation should be an object");
|
||||
console.log('>>>>>>> ', reservation);
|
||||
//La reserva puede estar asociada a la lista de espera es de donde se quitará aforo, si no al evento
|
||||
const eventToDiscountAssistants = reservation.overflowEventId
|
||||
? await eventService._getEvent(reservation.overflowEventId)
|
||||
: reservation.event;
|
||||
|
||||
console.log(eventToDiscountAssistants);
|
||||
return true;
|
||||
}
|
||||
|
||||
async function activeReservationById(id) {
|
||||
//Buscar reserva con evento y entidad
|
||||
let reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(id);
|
||||
return activeReservation(reservation);
|
||||
|
||||
const plazasDisponibles = eventToDiscountAssistants.assistants - eventToDiscountAssistants.confirmed;
|
||||
if (plazasDisponibles < dataInscription.reservation.assistants)
|
||||
return handleResultResponse("Aforo lleno no es posible efectuar la reserva", null, params, res, httpStatus.NOT_FOUND)
|
||||
|
||||
|
||||
|
||||
//Modificamos los asistentes de evento (AFORO) para quitar los de la reserva
|
||||
if (!(await eventService._updateAssistantsEvent(reservation.eventId, newAforo)))
|
||||
return handleResultResponse(
|
||||
"No se ha podido actualizar el aforo del evento, para reservar las plazas solicitadas",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
//Si se ha llenado ponemos el evento en SOLD_OUT
|
||||
if (eventToDiscountAssistants.confirmed >= newAforo)
|
||||
await eventService._updateSoldOutEvent(eventToDiscountAssistants.id, true);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (await _addConfirmedToEvent(reservation.assistants, reservation.Event))
|
||||
if (!(await eventReservationService._updatePublishReservation(id))) {
|
||||
console.log("No se ha podido publicar la reserva del evento");
|
||||
@ -80,14 +119,24 @@ 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;
|
||||
let entityType = null;
|
||||
let entityId = null
|
||||
|
||||
//typeOrId puede ser college, partner o el id de la entidad de la reserva
|
||||
const typeOrId = params.params.typeOrId;
|
||||
if (!typeOrId) {
|
||||
if ((typeOrId === "colleges") || (params.params.typeOrId !== "partners"))
|
||||
entityType = typeOrId
|
||||
else
|
||||
entityId = entityType;
|
||||
};
|
||||
|
||||
const reservations = await eventReservationService._getReservationsExcel(
|
||||
req.user,
|
||||
eventId,
|
||||
null,
|
||||
type,
|
||||
entityId,
|
||||
entityType,
|
||||
function (result, status) {
|
||||
if (result.messenger.code == "S99001") {
|
||||
console.log(result);
|
||||
|
||||
@ -10,10 +10,10 @@ const xlsx = require("node-xlsx");
|
||||
const fs = require("fs");
|
||||
const cdnHelper = require("../../helpers/cdn.helper");
|
||||
|
||||
function getWhereTypeEntity(type) {
|
||||
function getWhereTypeEntity(entityType) {
|
||||
var whereType = {};
|
||||
if (type == "partners") whereType = { alias: "partner" };
|
||||
else if (type == "colleges") whereType = { alias: "college" };
|
||||
if (entityType == "partners") whereType = { alias: "partner" };
|
||||
else if (entityType == "colleges") whereType = { alias: "college" };
|
||||
return whereType;
|
||||
}
|
||||
|
||||
@ -168,7 +168,7 @@ const extraMethods = {
|
||||
return result.toUpperCase();
|
||||
},
|
||||
|
||||
_deleteReservation: (id) => {
|
||||
_deleteReservation: (id) => {
|
||||
//habria que poner el idusuario para asegurar que otro usuario no borra una inscripcion de otro
|
||||
|
||||
return models.EventReservation.destroy({
|
||||
@ -178,13 +178,22 @@ const extraMethods = {
|
||||
});
|
||||
},
|
||||
|
||||
_getReservationsExcel: (user, eventId, partnerId, type, callback) => {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>><consulta con type:", type);
|
||||
_getReservationsExcel: (user, eventId, entityId, entityType, callback) => {
|
||||
console.log("DESCARGA EXCEL>>>>>>>> ");
|
||||
console.log(">>>>>>>>>>>>>>>>>>>><consulta con eventId:", eventId);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>><consulta con type:", entityType);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>><consulta con entityId:", entityId);
|
||||
|
||||
const where = {
|
||||
eventId: eventId
|
||||
};
|
||||
|
||||
if (entityId) {
|
||||
where['entityId'] = entityId;
|
||||
};
|
||||
|
||||
models.EventReservation.findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
},
|
||||
where,
|
||||
include: [
|
||||
{
|
||||
model: models.Event,
|
||||
@ -192,7 +201,7 @@ const extraMethods = {
|
||||
},
|
||||
{
|
||||
model: models.Entity,
|
||||
include: [{ model: models.EntityType, as: "types", where: getWhereTypeEntity(type) }],
|
||||
include: [{ model: models.EntityType, as: "types", where: getWhereTypeEntity(entityType) }],
|
||||
},
|
||||
{
|
||||
model: models.EventInscription,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user