1.3.3
This commit is contained in:
parent
80f3449839
commit
d5c445fd74
@ -139,7 +139,7 @@ const extraControllers = {
|
||||
}
|
||||
},
|
||||
|
||||
//Funcion que devuelve:
|
||||
//Funcion que devuelve:
|
||||
//1. Todas las inscripciones online de un evento, cuando el usuario es administrador
|
||||
getInscriptionsOnline: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
@ -147,24 +147,24 @@ const extraControllers = {
|
||||
const userId = req.user.id;
|
||||
var result = null;
|
||||
|
||||
//console.log(params, req.user.level);
|
||||
if (!eventId)
|
||||
return handleResultResponse("Es necesario el ID del evento", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
|
||||
try {
|
||||
if (req.user.level === 8) result = await eventInscriptionService._getInscriptionByEvent(eventId);
|
||||
else result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
||||
//console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', params, req.user.level);
|
||||
if (!eventId)
|
||||
return handleResultResponse("Es necesario el ID del evento", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
|
||||
try {
|
||||
if (req.user.level === 8) result = await eventInscriptionService._getInscriptionByEvent(eventId);
|
||||
else result = await eventInscriptionService._getInscriptionByEventAndUser(eventId, userId);
|
||||
|
||||
return handleResultResponse(result, null, params, res, result === null ? httpStatus.NOT_FOUND : httpStatus.OK);
|
||||
} catch (error) {
|
||||
return handleErrorResponse(MODULE_NAME, "getInscriptions", error, res);
|
||||
}
|
||||
|
||||
|
||||
return handleResultResponse(result, null, params, res, result === null ? httpStatus.NOT_FOUND : httpStatus.OK);
|
||||
} catch (error) {
|
||||
return handleErrorResponse(MODULE_NAME, "getInscriptions", error, res);
|
||||
}
|
||||
|
||||
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
getInscriptionsOfNextEventsCount: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
@ -180,7 +180,7 @@ const extraControllers = {
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
findPartners: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
@ -282,7 +282,7 @@ const extraControllers = {
|
||||
var member = generateMemberInscription(inscription.user, inscription, inscription.reservation);
|
||||
member.marketing_memberId = await eventInscriptionService._addMember(marketingListIdEvent, member);
|
||||
eventInscriptionService._updateMarketingMemberOfInscription(inscription.id, member.marketing_memberId);
|
||||
member.qrConfig = generateQRConfig(member);
|
||||
member.qrConfig = QRHelper.generateQRConfig(member);
|
||||
member.qrCode = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
||||
member.qrCodeUrl = QRHelper.getInscriptionQRCodeUrl(inscription.id);
|
||||
console.log(
|
||||
@ -320,7 +320,7 @@ const extraControllers = {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><syncronizeMarketingList");
|
||||
|
||||
if (marketingListService.syncronizeEventWithMarketingList(eventId))
|
||||
return handleResultResponse("La sincronización se ha realizado correctamente", null, params, res, httpStatus.DELETEOK);
|
||||
return handleResultResponse("La sincronización se ha realizado correctamente", null, params, res, httpStatus.DELETEOK);
|
||||
|
||||
},
|
||||
|
||||
|
||||
@ -8,25 +8,20 @@ const eventService = require("./event.service");
|
||||
const mailService = require("./mail.service");
|
||||
const marketingListService = require("./marketing_list.service");
|
||||
const QRHelper = require("../../helpers/qr.helper");
|
||||
const { extractParamsFromRequest, handleResultResponse } = require("../../helpers/controller.helper");
|
||||
const { extractParamsFromRequest, handleResultResponse, handleErrorResponse } = require("../../helpers/controller.helper");
|
||||
const { data } = require("../../core/logger");
|
||||
const lodash = require("lodash");
|
||||
const userService = require("../auth/user.service");
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = "[eventInscription.controller]";
|
||||
const controllerOptions = { MODULE_NAME };
|
||||
|
||||
|
||||
async function refreshConfirmed (inscription){
|
||||
async function refreshConfirmed(inscription) {
|
||||
|
||||
if (!inscription){
|
||||
return handleResultResponse(
|
||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
if (!inscription) {
|
||||
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada");
|
||||
};
|
||||
|
||||
if (inscription.type === "online")
|
||||
@ -34,24 +29,24 @@ async function refreshConfirmed (inscription){
|
||||
|
||||
//En caso de inscripciones
|
||||
const EventOrReservationChangeId = inscription.reservationId
|
||||
? inscription.reservationId
|
||||
: inscription.overflowEventId
|
||||
? inscription.overflowEventId
|
||||
: inscription.eventId;
|
||||
|
||||
? inscription.reservationId
|
||||
: inscription.overflowEventId
|
||||
? inscription.overflowEventId
|
||||
: inscription.eventId;
|
||||
|
||||
let NewConfirmed = 0;
|
||||
|
||||
//Si la inscripción viene por una reserva modificamos los confirmados de la reserva
|
||||
if (inscription.reservationId != null) {
|
||||
console.log("Tengo reservation>>>>>>>>>>>>>>>>>>", inscription.reservationId);
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithReservation(
|
||||
EventOrReservationChangeId
|
||||
EventOrReservationChangeId
|
||||
);
|
||||
//No se tienen en cuenta los marketinglist de las otras estructuras si lo tuviera seria esto
|
||||
// marketingListId = (await eventReservationService._getReservaById(EventOrReservationChangeId))
|
||||
// .marketing_list;
|
||||
|
||||
//Inscripcion de lista de espera bien de reserva o de evento de lista de espera
|
||||
//Inscripcion de lista de espera bien de reserva o de evento de lista de espera
|
||||
} else if (inscription.overflowEventId != null) {
|
||||
console.log("Tengo overflow>>>>>>>>>>>>>>>>>>", inscription.overflowEventId);
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithOverflowEventId(
|
||||
@ -60,40 +55,30 @@ async function refreshConfirmed (inscription){
|
||||
//No se tienen en cuenta los marketinglist de las otras estructuras si lo tuviera seria esto
|
||||
/// marketingListId = (await eventService._getEvent(EventOrReservationChangeId)).marketing_list;
|
||||
|
||||
//Inscripción al evento (ni reserva ni lista de espera)
|
||||
//Inscripción al evento (ni reserva ni lista de espera)
|
||||
} else if (inscription.eventId != null) {
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithoutReservationAndOverflow(
|
||||
EventOrReservationChangeId
|
||||
);
|
||||
|
||||
//No se tienen en cuenta los marketinglist de las otras estructuras si lo tuviera seria esto
|
||||
//marketingListId = (await eventService._getEvent(EventOrReservationChangeId)).marketing_list;
|
||||
//marketingListId = (await eventService._getEvent(EventOrReservationChangeId)).marketing_list;
|
||||
};
|
||||
|
||||
//Actualizamos aforo del evento o de la reserva
|
||||
if (inscription.reservationId != null) {
|
||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo reserva", EventOrReservationChangeId);
|
||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||
if (!(await eventReservationService._updateConfirmedReservation(EventOrReservationChangeId, NewConfirmed)))
|
||||
return handleResultResponse(
|
||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
} else {
|
||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo evento", EventOrReservationChangeId);
|
||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||
if (!(await eventService._updateConfirmedEvent(EventOrReservationChangeId, NewConfirmed)))
|
||||
return handleResultResponse(
|
||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
};
|
||||
//Actualizamos aforo del evento o de la reserva
|
||||
if (inscription.reservationId != null) {
|
||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo reserva", EventOrReservationChangeId);
|
||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||
if (!(await eventReservationService._updateConfirmedReservation(EventOrReservationChangeId, NewConfirmed))) {
|
||||
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada");
|
||||
}
|
||||
} else {
|
||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo evento", EventOrReservationChangeId);
|
||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||
if (!(await eventService._updateConfirmedEvent(EventOrReservationChangeId, NewConfirmed))) {
|
||||
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const extraControllers = {
|
||||
@ -104,15 +89,15 @@ const extraControllers = {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
|
||||
//Si no viene type es porque es una inscripción con la app antigua y el valor por defecto es onsite
|
||||
let typeInscription = "onsite";
|
||||
let typeInscription = "onsite";
|
||||
if ((req.body.type) && (req.body.type === "online"))
|
||||
typeInscription = "online";
|
||||
|
||||
typeInscription = "online";
|
||||
|
||||
//Si viene code es la appa antigua o la nueva
|
||||
if (((req.body.code) && (req.body.code !==""))
|
||||
|| ((req.body.group_size) && (req.body.group_size > 1)))
|
||||
typeInscription = typeInscription + " group";
|
||||
|
||||
if (((req.body.code) && (req.body.code !== ""))
|
||||
|| ((req.body.group_size) && (req.body.group_size > 1)))
|
||||
typeInscription = typeInscription + " group";
|
||||
|
||||
let dataInscription = {
|
||||
eventId: params.params.id,
|
||||
reservationCode: req.user ? req.body.code : Buffer.from(req.body.code, "base64").toString("ascii"),
|
||||
@ -128,19 +113,19 @@ const extraControllers = {
|
||||
};
|
||||
|
||||
try {
|
||||
dataInscription.event = await eventService._getEvent(dataInscription.eventId);
|
||||
if (dataInscription.event) {
|
||||
dataInscription.event = await dataInscription.event.toJSON();
|
||||
} else {
|
||||
// No se ha encontrado
|
||||
return handleResultResponse("Evento no encontrado", null, params, res, httpStatus.NOT_FOUND);
|
||||
dataInscription.event = await eventService._getEvent(dataInscription.eventId);
|
||||
if (dataInscription.event) {
|
||||
dataInscription.event = await dataInscription.event.toJSON();
|
||||
} else {
|
||||
// No se ha encontrado
|
||||
return handleResultResponse("Evento no encontrado", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
} catch (error) {
|
||||
return handleErrorResponse(MODULE_NAME, "encontrado", error, res);
|
||||
}
|
||||
|
||||
|
||||
res.locals.dataInscription = dataInscription;
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> prepareDataInscription", dataInscription.type);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> prepareDataInscription", dataInscription.type);
|
||||
next();
|
||||
},
|
||||
|
||||
@ -182,40 +167,40 @@ const extraControllers = {
|
||||
);
|
||||
|
||||
//Si la inscripcion no tiene reserva o la tiene y es la misma de la insripcion devuelvo la inscripcion
|
||||
if ((!dataInscription.inscription.reservationId)
|
||||
|| ((dataInscription.reservation) && (dataInscription.inscription.reservationId == dataInscription.reservation.id)))
|
||||
return handleResultResponse(dataInscription.inscription, null, params, res, httpStatus.OK);
|
||||
if ((!dataInscription.inscription.reservationId)
|
||||
|| ((dataInscription.reservation) && (dataInscription.inscription.reservationId == dataInscription.reservation.id)))
|
||||
return handleResultResponse(dataInscription.inscription, null, params, res, httpStatus.OK);
|
||||
|
||||
|
||||
//En caso contrario devuelvo la plaza a la reserva que tenia la inscripción anterior y apunto la inscripción a la nueva reserva
|
||||
//ACTUALIZAMOS LA RESERVA DE LA INSCRIPCION CON LA NUEVA Y CAMBIAMOS COMFIRMADOS DEVOLVIENDO LA INSCRIPCIÓN CON LA NUEVA RESERVA
|
||||
let CountConfirmedOldReservation = await eventInscriptionService._getCountInscriptionsWithReservation(
|
||||
dataInscription.inscription.reservationId
|
||||
dataInscription.inscription.reservationId
|
||||
);
|
||||
console.log("actualizo confirmados de la reserva anterior");
|
||||
await eventReservationService._updateConfirmedReservation(
|
||||
dataInscription.inscription.reservationId,
|
||||
--CountConfirmedOldReservation
|
||||
dataInscription.inscription.reservationId,
|
||||
--CountConfirmedOldReservation
|
||||
);
|
||||
|
||||
let CountConfirmedNewReservation = await eventInscriptionService._getCountInscriptionsWithReservation(
|
||||
dataInscription.reservation.id
|
||||
dataInscription.reservation.id
|
||||
);
|
||||
console.log("actualizo confirmados de la nueva reserva");
|
||||
await eventReservationService._updateConfirmedReservation(
|
||||
dataInscription.reservation.id,
|
||||
++CountConfirmedNewReservation
|
||||
dataInscription.reservation.id,
|
||||
++CountConfirmedNewReservation
|
||||
);
|
||||
await eventInscriptionService._updateReservationOfInscription(
|
||||
dataInscription.inscription.id,
|
||||
dataInscription.reservation.id
|
||||
dataInscription.inscription.id,
|
||||
dataInscription.reservation.id
|
||||
);
|
||||
|
||||
dataInscription.inscription = await eventInscriptionService._getInscriptionById(dataInscription.inscription.id);
|
||||
return handleResultResponse(dataInscription.inscription, null, params, res, httpStatus.OK);
|
||||
};
|
||||
|
||||
} catch(error){
|
||||
} catch (error) {
|
||||
return handleResultResponse("Error checkInscriptionByUser", error, params, res, httpStatus.NOT_FOUND);
|
||||
};
|
||||
next();
|
||||
@ -235,14 +220,14 @@ const extraControllers = {
|
||||
}
|
||||
//console.log("inscripcion encontrada>>>>>>>>>>>>>>>>>>>>>>>>>>>", inscription);
|
||||
inscription = await inscription.toJSON();
|
||||
// console.log(">>>>>>>voy a dar inscription>>><", inscription.user);
|
||||
// console.log(">>>>>>>voy a dar inscription>>><", inscription.user);
|
||||
var member = marketingListService._generateMarketingDTO(inscription);
|
||||
member.qrConfig = QRHelper.generateQRConfig(member);
|
||||
inscription.code_ticket_qr = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
||||
|
||||
//Si el usuario de la inscripción no es tutor limpiamos la información de la reserva
|
||||
if (inscription.user.profile !== 'tutor')
|
||||
if (inscription.reservation) inscription.reservation.assistants = null;
|
||||
if (inscription.reservation) inscription.reservation.assistants = null;
|
||||
|
||||
console.log(">>>>>>>voy a dar inscription", inscription);
|
||||
return handleResultResponse(inscription, null, params, res, httpStatus.OK);
|
||||
@ -281,7 +266,7 @@ const extraControllers = {
|
||||
createInscription: async (req, res, next) => {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> createInscription (event_inscriptions.controller)");
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
|
||||
|
||||
let dataInscription = res.locals.dataInscription;
|
||||
if (!dataInscription || !dataInscription.event)
|
||||
return handleResultResponse(
|
||||
@ -305,13 +290,13 @@ const extraControllers = {
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
try {
|
||||
try {
|
||||
|
||||
//ONLINE
|
||||
//Si es una inscripcion online no se validan aforos se crea inscripción y ya esta
|
||||
if (dataInscription.type === "online" || dataInscription.type === "online group") {
|
||||
//creamos inscripcion
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.userResult.user.id,
|
||||
dataInscription.type,
|
||||
@ -322,7 +307,7 @@ const extraControllers = {
|
||||
);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>ENTRADA ONLINE", dataInscription.inscription);
|
||||
};
|
||||
|
||||
|
||||
//ONSITE INDIVIDUAL
|
||||
if (!dataInscription.inscription) {
|
||||
|
||||
@ -336,115 +321,115 @@ const extraControllers = {
|
||||
dataInscription.event.sold_out == 0 &&
|
||||
dataInscription.event.assistants >= inscriptionsWithoutReservationAndOverflowCount
|
||||
) {
|
||||
dataInscription.validated = true;
|
||||
console.log('actualizamos afoorooo>>>');
|
||||
//Actualizamos aforo del evento y creamos inscripcion
|
||||
if (
|
||||
await eventService._updateConfirmedEvent(
|
||||
dataInscription.event.id,
|
||||
inscriptionsWithoutReservationAndOverflowCount
|
||||
)
|
||||
){
|
||||
try{
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.id,
|
||||
dataInscription.type,
|
||||
dataInscription.validated,
|
||||
dataInscription.source,
|
||||
null,
|
||||
null
|
||||
)
|
||||
}catch(error){console.log('SSSSSSSSSSSSSSSSSSSSSSSSS',error)}
|
||||
}
|
||||
else
|
||||
return handleResultResponse(
|
||||
"No se ha podido actualizar el aforo del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
|
||||
//Ponemos el evento en SOLD_OUT
|
||||
if (dataInscription.event.assistants == inscriptionsWithoutReservationAndOverflowCount)
|
||||
await eventService._updateSoldOutEvent(dataInscription.event.id, true);
|
||||
dataInscription.validated = true;
|
||||
console.log('actualizamos afoorooo>>>');
|
||||
//Actualizamos aforo del evento y creamos inscripcion
|
||||
if (
|
||||
await eventService._updateConfirmedEvent(
|
||||
dataInscription.event.id,
|
||||
inscriptionsWithoutReservationAndOverflowCount
|
||||
)
|
||||
) {
|
||||
try {
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.id,
|
||||
dataInscription.type,
|
||||
dataInscription.validated,
|
||||
dataInscription.source,
|
||||
null,
|
||||
null
|
||||
)
|
||||
} catch (error) { console.log('SSSSSSSSSSSSSSSSSSSSSSSSS', error) }
|
||||
}
|
||||
|
||||
else
|
||||
return handleResultResponse(
|
||||
"No se ha podido actualizar el aforo del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
|
||||
//Ponemos el evento en SOLD_OUT
|
||||
if (dataInscription.event.assistants == inscriptionsWithoutReservationAndOverflowCount)
|
||||
await eventService._updateSoldOutEvent(dataInscription.event.id, true);
|
||||
}
|
||||
|
||||
// APUNTARSE A la lista de espera si se puede
|
||||
else {
|
||||
dataInscription.validated = false;
|
||||
dataInscription.validated = false;
|
||||
|
||||
if (dataInscription.event.allow_overflow === false) {
|
||||
console.log("Aforo completo y no hay lista de espera");
|
||||
return handleResultResponse(
|
||||
"Aforo completo y no hay lista de espera",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
};
|
||||
if (dataInscription.event.allow_overflow === false) {
|
||||
console.log("Aforo completo y no hay lista de espera");
|
||||
return handleResultResponse(
|
||||
"Aforo completo y no hay lista de espera",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
};
|
||||
|
||||
//recuperamos la cantidad de apuntados al evento overflow (lista de espera)
|
||||
let ConfirmedWaitList = await eventInscriptionService._getCountInscriptionsWithOverflowEventId(
|
||||
//recuperamos la cantidad de apuntados al evento overflow (lista de espera)
|
||||
let ConfirmedWaitList = await eventInscriptionService._getCountInscriptionsWithOverflowEventId(
|
||||
dataInscription.event.overflow_eventId
|
||||
);
|
||||
//recuperamos aforo de la lista de espera
|
||||
dataInscription.overflow_event = await eventService._getEvent(dataInscription.event.overflow_eventId);
|
||||
console.log("cantidad apuntados a lista de espera asociado, aforo >>>>>>>>>>>>>>>>>>>>>",
|
||||
ConfirmedWaitList, dataInscription.overflow_event.assistants
|
||||
);
|
||||
|
||||
//Si no hay espacio a lista de espera damos el mismo error que no hay lista de espera
|
||||
if (dataInscription.overflow_event.assistants < ++ConfirmedWaitList) {
|
||||
console.log("Aforo completo de lista de espera");
|
||||
return handleResultResponse(
|
||||
"Aforo completo y no hay lista de espera",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
};
|
||||
|
||||
//Creamos inscripción a lista de espera
|
||||
if (
|
||||
await eventService._updateConfirmedEvent(dataInscription.event.overflow_eventId, ConfirmedWaitList)
|
||||
) {
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.userResult.user.id,
|
||||
dataInscription.type,
|
||||
dataInscription.validated,
|
||||
dataInscription.source,
|
||||
null,
|
||||
dataInscription.event.overflow_eventId
|
||||
);
|
||||
//recuperamos aforo de la lista de espera
|
||||
dataInscription.overflow_event = await eventService._getEvent(dataInscription.event.overflow_eventId);
|
||||
console.log("cantidad apuntados a lista de espera asociado, aforo >>>>>>>>>>>>>>>>>>>>>",
|
||||
ConfirmedWaitList, dataInscription.overflow_event.assistants
|
||||
} else {
|
||||
console.log("No se ha podido actualizar el aforo de la lista de espera del evento");
|
||||
return handleResultResponse(
|
||||
"o se ha podido actualizar el aforo de la lista de espera del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
//Si no hay espacio a lista de espera damos el mismo error que no hay lista de espera
|
||||
if (dataInscription.overflow_event.assistants < ++ConfirmedWaitList) {
|
||||
console.log("Aforo completo de lista de espera");
|
||||
return handleResultResponse(
|
||||
"Aforo completo y no hay lista de espera",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
};
|
||||
|
||||
//Creamos inscripción a lista de espera
|
||||
if (
|
||||
await eventService._updateConfirmedEvent(dataInscription.event.overflow_eventId, ConfirmedWaitList)
|
||||
) {
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.userResult.user.id,
|
||||
dataInscription.type,
|
||||
dataInscription.validated,
|
||||
dataInscription.source,
|
||||
null,
|
||||
dataInscription.event.overflow_eventId
|
||||
);
|
||||
} else {
|
||||
console.log("No se ha podido actualizar el aforo de la lista de espera del evento");
|
||||
return handleResultResponse(
|
||||
"o se ha podido actualizar el aforo de la lista de espera del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
}
|
||||
} //FIN APUNTARSE A la lista de espera si se puede
|
||||
}
|
||||
} //FIN APUNTARSE A la lista de espera si se puede
|
||||
};
|
||||
|
||||
dataInscription.inscription = await dataInscription.inscription.toJSON();
|
||||
//Incluimos correo en sendinblue
|
||||
try {
|
||||
marketingListService.addMarketingList(dataUser, dataInscription);
|
||||
} catch(error){ console.log('Se ha producido un error al añadir a SenINBlue>>>>>>>>>>>>>>>>><<', error);}
|
||||
} catch (error) { console.log('Se ha producido un error al añadir a SenINBlue>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
//Mandamos correo con entrada o lista de espera
|
||||
try {
|
||||
mailService.sendEmailConfirm(dataUser, dataInscription);
|
||||
} catch(error){ console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error);}
|
||||
} catch (error) { console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
|
||||
return handleResultResponse(await dataInscription.inscription, null, params, res, httpStatus.CREATED);
|
||||
@ -459,7 +444,7 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const user = req.user;
|
||||
const inscriptionId = params.params.id;
|
||||
let marketingListId = null;
|
||||
let marketingListId = null;
|
||||
|
||||
try {
|
||||
const inscription = await eventInscriptionService._getInscriptionById(inscriptionId);
|
||||
@ -475,45 +460,45 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
|
||||
//En el caso de ser una inscripción grupal y el tutor se quiere quitar, se podrá hacer solo en el caso de que en la reserva no haya ya confirmados
|
||||
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed > 1)
|
||||
return handleResultResponse("No se pudo eliminar inscripción por ser tutor de grupo y tener alumnos apuntados, pongase en contacto con nosotros", null, params, res, httpStatus.NOT_FOUND)
|
||||
return handleResultResponse("No se pudo eliminar inscripción por ser tutor de grupo y tener alumnos apuntados, pongase en contacto con nosotros", null, params, res, httpStatus.NOT_FOUND)
|
||||
|
||||
//Borramos inscripción
|
||||
if ((await eventInscriptionService._deleteInscription(inscription.id)) > 0) {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada");
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada");
|
||||
|
||||
//Actualizamos confirmados asistentes
|
||||
refreshConfirmed (inscription);
|
||||
//Actualizamos confirmados asistentes
|
||||
refreshConfirmed(inscription);
|
||||
|
||||
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed === 1) {
|
||||
//Eliminamos la reserva hecha del centro aliado
|
||||
if (!((await eventReservationService._deleteReservation(inscription.reservation.id)) > 0))
|
||||
return handleResultResponse("No se pudo eliminar inscripción por ser tutor de grupo online y tener alumnos apuntados, pongase en contacto con nosotros", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
if (lodash.words(inscription.type).includes("onsite")) {
|
||||
const eventOfReservation = await eventService._getEvent(inscription.reservation.eventId);
|
||||
//Modificamos los asistentes de evento (AFORO) para añadir las plazas de la reserva eliminada
|
||||
const newAforo = eventOfReservation.assistants + inscription.reservation.assistants;
|
||||
if (!(await eventService._updateAssistantsEvent(eventOfReservation.id, newAforo)))
|
||||
return handleResultResponse("No se ha podido actualizar el aforo del evento, para reservar las plazas solicitadas", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
};
|
||||
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed === 1) {
|
||||
//Eliminamos la reserva hecha del centro aliado
|
||||
if (!((await eventReservationService._deleteReservation(inscription.reservation.id)) > 0))
|
||||
return handleResultResponse("No se pudo eliminar inscripción por ser tutor de grupo online y tener alumnos apuntados, pongase en contacto con nosotros", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
if (lodash.words(inscription.type).includes("onsite")) {
|
||||
const eventOfReservation = await eventService._getEvent(inscription.reservation.eventId);
|
||||
//Modificamos los asistentes de evento (AFORO) para añadir las plazas de la reserva eliminada
|
||||
const newAforo = eventOfReservation.assistants + inscription.reservation.assistants;
|
||||
if (!(await eventService._updateAssistantsEvent(eventOfReservation.id, newAforo)))
|
||||
return handleResultResponse("No se ha podido actualizar el aforo del evento, para reservar las plazas solicitadas", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
return handleResultResponse("No se pudo eliminar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
|
||||
else
|
||||
return handleResultResponse("No se pudo eliminar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
|
||||
//Quitamos correo en sendinblue
|
||||
try {
|
||||
marketingListService._deleteMember(marketingListId, inscription.user.email);
|
||||
} catch(error){ console.log('Se ha producido un error al eliminar de SenINBlue>>>>>>>>>>>>>>>>><<', error);}
|
||||
} catch (error) { console.log('Se ha producido un error al eliminar de SenINBlue>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
//Mandamos correo de confirmación de eliminación
|
||||
try {
|
||||
mailService.sendEmailCancelate(inscription);
|
||||
} catch(error){ console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error);}
|
||||
} catch (error) { console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
console.log(">>>>>>>>>>>>>>Inscripcion eliminada con todos los pasos");
|
||||
return handleResultResponse("Inscripción eliminada", null, params, res, httpStatus.DELETEOK);
|
||||
console.log(">>>>>>>>>>>>>>Inscripcion eliminada con todos los pasos");
|
||||
return handleResultResponse("Inscripción eliminada", null, params, res, httpStatus.DELETEOK);
|
||||
|
||||
} catch (error) {
|
||||
console.log("eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrrrorrrr", error);
|
||||
|
||||
@ -59,14 +59,6 @@ const extraMethods = {
|
||||
});
|
||||
},
|
||||
|
||||
_getInscriptionByEvent: (eventId) => {
|
||||
return models.EventInscription.scope("defaultScope").findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
_getInscriptionByEventAndValidated: (eventId, validated) => {
|
||||
return models.EventInscription.scope("defaultScope").findAll({
|
||||
where: {
|
||||
@ -223,13 +215,13 @@ const extraMethods = {
|
||||
},
|
||||
|
||||
_getInscriptionsWithoutMemberId: (eventId) => {
|
||||
return models.EventInscription.scope(["includeEventAndVenue", "includeReservation", "defaultScope"]).findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
marketing_memberId: null
|
||||
},
|
||||
});
|
||||
},
|
||||
return models.EventInscription.scope(["includeEventAndVenue", "includeReservation", "defaultScope"]).findAll({
|
||||
where: {
|
||||
eventId: eventId,
|
||||
marketing_memberId: null
|
||||
},
|
||||
});
|
||||
},
|
||||
|
||||
_getInscriptionsExcel: (user, eventId, callback) => {
|
||||
models.EventInscription.findAll({
|
||||
|
||||
@ -180,8 +180,8 @@ const extraControllers = {
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> recuperateReservationByCode", dataInscription.type);
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> recuperateReservationByCode", dataInscription.type);
|
||||
|
||||
//SI VIENE CODIGO DE RESERVA, RECUPERAMOS LA RESERVA Y EL EVENTO
|
||||
if (dataInscription.reservationCode) {
|
||||
try {
|
||||
@ -226,24 +226,25 @@ const extraControllers = {
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> createReservationToEntity>>>>>>", dataInscription.type);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> createReservationToEntity>>>>>>", dataInscription.type);
|
||||
//Si viene group_size crearemos un código de reserva
|
||||
if (dataInscription.groupSize > 1) {
|
||||
|
||||
|
||||
if (!dataUser.entityId) {
|
||||
return handleResultResponse(
|
||||
"Error No es posible crear reserva grupal si no pertences a una entidad educativa",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
)};
|
||||
|
||||
"Error No es posible crear reserva grupal si no pertences a una entidad educativa",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
)
|
||||
};
|
||||
|
||||
const reservationData = {
|
||||
reservation_code: eventReservationService._generateReservatioCode(dataInscription.event, dataUser.entityName),
|
||||
state: "draft", //sin confirmar, publish es cuando se descuenta del aforo del evento
|
||||
color: "gray",
|
||||
description: (dataInscription.type === 'online group')? 'Incripción online en grupo' : 'Reserva',
|
||||
description: (dataInscription.type === 'online group') ? 'Incripción online en grupo' : 'Reserva',
|
||||
init_available_date: dataInscription.event.init_available_date,
|
||||
end_available_date: dataInscription.event.end_available_date,
|
||||
entityId: dataUser.entityId,
|
||||
@ -256,15 +257,15 @@ const extraControllers = {
|
||||
};
|
||||
|
||||
//Comprobamos aforo si no es online, si no es posible apuntarse iria a lista de espera
|
||||
if (dataInscription.type !== "online" && dataInscription.type !== "online group"){
|
||||
const plazasDisponibles = dataInscription.event.assistants - dataInscription.event.confirmed;
|
||||
if (plazasDisponibles < reservationData.assistants)
|
||||
if (dataInscription.event.allow_overflow){
|
||||
reservationData.overflowEventId = dataInscription.event.overflow_eventId;
|
||||
reservationData.description = reservationData.description + ' en lista de espera'
|
||||
console.log('Asigno lista de espera>>>>>>>>>>>>>>>>>>>>>>>',reservationData.eventId);
|
||||
}
|
||||
else return handleResultResponse("Aforo lleno no es posible efectuar la reserva", null, params, res, httpStatus.NOT_FOUND);
|
||||
if (dataInscription.type !== "online" && dataInscription.type !== "online group") {
|
||||
const plazasDisponibles = dataInscription.event.assistants - dataInscription.event.confirmed;
|
||||
if (plazasDisponibles < reservationData.assistants)
|
||||
if (dataInscription.event.allow_overflow) {
|
||||
reservationData.overflowEventId = dataInscription.event.overflow_eventId;
|
||||
reservationData.description = reservationData.description + ' en lista de espera'
|
||||
console.log('Asigno lista de espera>>>>>>>>>>>>>>>>>>>>>>>', reservationData.eventId);
|
||||
}
|
||||
else return handleResultResponse("Aforo lleno no es posible efectuar la reserva", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
///Aqui podríamos validar si ya hay reserva y dar error ya que no pueden meter codigo de reserva y darnos un group_size superior a 1.
|
||||
@ -276,7 +277,7 @@ const extraControllers = {
|
||||
dataInscription.reservation = dataInscription.reservation.toJSON();
|
||||
res.locals.dataInscription = dataInscription;
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>RESERVATION CREADA", dataInscription.reservation);
|
||||
}
|
||||
}
|
||||
else console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>no hago nada");
|
||||
next();
|
||||
},
|
||||
@ -299,26 +300,26 @@ const extraControllers = {
|
||||
console.log(">> No se aplica descuento de aforo");
|
||||
next();
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
//En caso de ser una inscripción normal o una reserva ya publicada no descontamos ningun aforo al evento
|
||||
if (!dataInscription.reservation || (dataInscription.reservation.state === 'publish')){ // || (!dataInscription.reservationCode) || (dataInscription.reservationCode === "")) {
|
||||
if (!dataInscription.reservation || (dataInscription.reservation.state === 'publish')) { // || (!dataInscription.reservationCode) || (dataInscription.reservationCode === "")) {
|
||||
console.log(">> No se aplica descuento de aforo ya que es una reserva publicada");
|
||||
next();
|
||||
return;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
//Si es centro aliado
|
||||
if (dataUser.entityLevel === "aliado") {
|
||||
//La reserva puede estar asociada a la lista de espera es de donde se quitará aforo, si no al evento
|
||||
const eventToDiscountAssistants = dataInscription.reservation.overflowEventId
|
||||
? await eventService._getEvent(dataInscription.reservation.overflowEventId)
|
||||
: dataInscription.event;
|
||||
const eventToDiscountAssistants = dataInscription.reservation.overflowEventId
|
||||
? await eventService._getEvent(dataInscription.reservation.overflowEventId)
|
||||
: dataInscription.event;
|
||||
|
||||
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)
|
||||
if (plazasDisponibles < dataInscription.reservation.assistants)
|
||||
return handleResultResponse("Aforo lleno no es posible efectuar la reserva", null, params, res, httpStatus.NOT_FOUND)
|
||||
|
||||
const newAforo = eventToDiscountAssistants.assistants - dataInscription.reservation.assistants;
|
||||
//Modificamos los asistentes de evento (AFORO) para quitar los de la reserva
|
||||
@ -329,33 +330,33 @@ const extraControllers = {
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
);
|
||||
|
||||
//Si se ha llenado ponemos el evento en SOLD_OUT
|
||||
if (eventToDiscountAssistants.confirmed == newAforo)
|
||||
//Si se ha llenado ponemos el evento en SOLD_OUT
|
||||
if (eventToDiscountAssistants.confirmed >= newAforo)
|
||||
await eventService._updateSoldOutEvent(eventToDiscountAssistants.id, true);
|
||||
|
||||
//Finalmente publicamos la reserva solo si no está asociada a la lista de espera
|
||||
if (!dataInscription.reservation.overflowEventId) {
|
||||
if (!(await eventReservationService._updatePublishReservation(dataInscription.reservation.id)))
|
||||
return handleResultResponse(
|
||||
"No se ha podido publicar la reserva del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
dataInscription.reservation.state = "publish";
|
||||
return handleResultResponse(
|
||||
"No se ha podido publicar la reserva del evento",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
dataInscription.reservation.state = "publish";
|
||||
|
||||
//Mandamos el código de reserva para que registra a sus alumnos
|
||||
dataInscription.reservation.contact_email = dataUser.email;
|
||||
dataInscription.reservation.contact_name = dataUser.name;
|
||||
dataInscription.reservation.event = dataInscription.event;
|
||||
console.log('MANDAMOS CODIO RESERVA>>>>>>',dataInscription.reservation);
|
||||
console.log('MANDAMOS CODIO RESERVA>>>>>>', dataInscription.reservation);
|
||||
|
||||
try{
|
||||
try {
|
||||
mailService.sendReservationEmail(dataInscription.reservation);
|
||||
}catch(error){
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
@ -385,7 +386,7 @@ const extraControllers = {
|
||||
createInscriptionReservation: async (req, res, next) => {
|
||||
console.log(">>>>>>>>>>>>>>>>>>>> createInscriptionReservation (event_reservations.controller)");
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
|
||||
|
||||
let dataInscription = res.locals.dataInscription;
|
||||
if (!dataInscription || !dataInscription.event || !dataInscription.reservation)
|
||||
return handleResultResponse(
|
||||
@ -395,7 +396,7 @@ const extraControllers = {
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
|
||||
|
||||
let dataUser = res.locals.dataUser;
|
||||
if (!dataUser)
|
||||
return handleResultResponse("Error getOrCreateUser requerida", null, params, res, httpStatus.NOT_FOUND);
|
||||
@ -418,10 +419,10 @@ const extraControllers = {
|
||||
dataInscription.reservation.sold_out == 0 &&
|
||||
dataInscription.reservation.assistants >= dataInscription.inscriptionsWithReservationCount
|
||||
) {
|
||||
dataInscription.validated = false;
|
||||
dataInscription.validated = false;
|
||||
//Es la inscripción automática del tutor o alguien que tiene el código y eso no puede ser
|
||||
if (dataInscription.type === "online" || dataInscription.type === "online group" || dataInscription.reservation.state === 'publish')
|
||||
dataInscription.validated = true;
|
||||
dataInscription.validated = true;
|
||||
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", dataInscription.type);
|
||||
@ -505,15 +506,15 @@ const extraControllers = {
|
||||
};
|
||||
|
||||
|
||||
// Incluimos correo en sendinblue
|
||||
// Incluimos correo en sendinblue
|
||||
try {
|
||||
// marketingListService.addMarketingList(dataUser, dataInscription);
|
||||
} catch(error){ console.log('Se ha producido un error al añadir a SenINBlue>>>>>>>>>>>>>>>>><<', error);}
|
||||
// marketingListService.addMarketingList(dataUser, dataInscription);
|
||||
} catch (error) { console.log('Se ha producido un error al añadir a SenINBlue>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
//Mandamos correo con entrada o lista de espera
|
||||
try {
|
||||
mailService.sendEmailConfirm(dataUser, dataInscription);
|
||||
} catch(error){ console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error);}
|
||||
} catch (error) { console.log('Se ha producido un error al enviar mail>>>>>>>>>>>>>>>>><<', error); }
|
||||
|
||||
return handleResultResponse(Result, null, params, res, httpStatus.CREATED);
|
||||
} catch (error) {
|
||||
|
||||
@ -125,8 +125,9 @@ module.exports = function (sequelize, DataTypes) {
|
||||
required: false,
|
||||
include: [{
|
||||
model: sequelize.models.MultimediaFile,
|
||||
as: "multimediaFile"
|
||||
}]
|
||||
as: "multimediaFile",
|
||||
order: [['createdAt', 'DESC']],
|
||||
}]
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lqdvi-api3",
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.3",
|
||||
"description": "",
|
||||
"author": "Rodax Software",
|
||||
"license": "ISC",
|
||||
@ -72,4 +72,4 @@
|
||||
"vm": "^0.1.0",
|
||||
"winston": "^3.2.1"
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user