. repaso exportacion excel reservations
This commit is contained in:
parent
07f39194aa
commit
02cac75ff9
@ -457,9 +457,8 @@ routes.get(
|
|||||||
eventController.syncronizeMarketingList
|
eventController.syncronizeMarketingList
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
routes.get(
|
routes.get(
|
||||||
"/admin/events/:id/reservations/:type/excel",
|
"/admin/events/:id/reservations/:typeOrId/excel",
|
||||||
isAdministratorUser,
|
isAdministratorUser,
|
||||||
eventReservationController.getReservationsExcel
|
eventReservationController.getReservationsExcel
|
||||||
);
|
);
|
||||||
|
|||||||
@ -42,9 +42,48 @@ async function _addConfirmedToEvent(confirmed, event) {
|
|||||||
return true;
|
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) {
|
async function activeReservationById(id) {
|
||||||
//Buscar reserva con evento y entidad
|
//Buscar reserva con evento y entidad
|
||||||
let reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(id);
|
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 _addConfirmedToEvent(reservation.assistants, reservation.Event))
|
||||||
if (!(await eventReservationService._updatePublishReservation(id))) {
|
if (!(await eventReservationService._updatePublishReservation(id))) {
|
||||||
console.log("No se ha podido publicar la reserva del evento");
|
console.log("No se ha podido publicar la reserva del evento");
|
||||||
@ -80,14 +119,24 @@ const extraControllers = {
|
|||||||
getReservationsExcel: async (req, res, next) => {
|
getReservationsExcel: 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 userId = req.user.id;
|
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(
|
const reservations = await eventReservationService._getReservationsExcel(
|
||||||
req.user,
|
req.user,
|
||||||
eventId,
|
eventId,
|
||||||
null,
|
entityId,
|
||||||
type,
|
entityType,
|
||||||
function (result, status) {
|
function (result, status) {
|
||||||
if (result.messenger.code == "S99001") {
|
if (result.messenger.code == "S99001") {
|
||||||
console.log(result);
|
console.log(result);
|
||||||
|
|||||||
@ -10,10 +10,10 @@ const xlsx = require("node-xlsx");
|
|||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const cdnHelper = require("../../helpers/cdn.helper");
|
const cdnHelper = require("../../helpers/cdn.helper");
|
||||||
|
|
||||||
function getWhereTypeEntity(type) {
|
function getWhereTypeEntity(entityType) {
|
||||||
var whereType = {};
|
var whereType = {};
|
||||||
if (type == "partners") whereType = { alias: "partner" };
|
if (entityType == "partners") whereType = { alias: "partner" };
|
||||||
else if (type == "colleges") whereType = { alias: "college" };
|
else if (entityType == "colleges") whereType = { alias: "college" };
|
||||||
return whereType;
|
return whereType;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ const extraMethods = {
|
|||||||
return result.toUpperCase();
|
return result.toUpperCase();
|
||||||
},
|
},
|
||||||
|
|
||||||
_deleteReservation: (id) => {
|
_deleteReservation: (id) => {
|
||||||
//habria que poner el idusuario para asegurar que otro usuario no borra una inscripcion de otro
|
//habria que poner el idusuario para asegurar que otro usuario no borra una inscripcion de otro
|
||||||
|
|
||||||
return models.EventReservation.destroy({
|
return models.EventReservation.destroy({
|
||||||
@ -178,13 +178,22 @@ const extraMethods = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_getReservationsExcel: (user, eventId, partnerId, type, callback) => {
|
_getReservationsExcel: (user, eventId, entityId, entityType, callback) => {
|
||||||
console.log(">>>>>>>>>>>>>>>>>>>><consulta con type:", type);
|
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({
|
models.EventReservation.findAll({
|
||||||
where: {
|
where,
|
||||||
eventId: eventId,
|
|
||||||
},
|
|
||||||
include: [
|
include: [
|
||||||
{
|
{
|
||||||
model: models.Event,
|
model: models.Event,
|
||||||
@ -192,7 +201,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(entityType) }],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
model: models.EventInscription,
|
model: models.EventInscription,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user