Prettier
This commit is contained in:
parent
7124b06d67
commit
44ca51675b
@ -343,6 +343,7 @@ routes.delete(
|
||||
// Imagen del código QR de una inscripción
|
||||
routes.get("/inscriptions/:id/qrimage", eventController.getQRCodeImage);
|
||||
|
||||
// Comprobar el código de invitación
|
||||
routes.get(
|
||||
"/events/:id/reservations/:encodedInvitationCode",
|
||||
isLoggedUser,
|
||||
|
||||
@ -17,7 +17,7 @@ const {
|
||||
} = require("../../helpers/controller.helper");
|
||||
const emailHelper = require("../../helpers/mail.helper");
|
||||
const path = require("path");
|
||||
const responseTime = require("response-time");
|
||||
const responseTime = require("response-time");
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = "[eventReservation.controller]";
|
||||
@ -28,12 +28,10 @@ const controllerOptions = { MODULE_NAME };
|
||||
* Devuelve la reserva pasada por parametro publicada (publish) o null en el caso de error
|
||||
*/
|
||||
async function activeReservation(reservation) {
|
||||
if (!reservation)
|
||||
throw new Error("activeReservation: reservation should be an object");
|
||||
if (!reservation) throw new Error("activeReservation: reservation should be an object");
|
||||
|
||||
//En el caso de ya estar publicada no hacemos nada se devuelve tal cual
|
||||
if (reservation.state === 'publish')
|
||||
return reservation;
|
||||
//En el caso de ya estar publicada no hacemos nada se devuelve tal cual
|
||||
if (reservation.state === "publish") return reservation;
|
||||
|
||||
await eventService._updateAforoOfEventReservation(reservation, reservation.assistants);
|
||||
|
||||
@ -47,26 +45,28 @@ async function activeReservation(reservation) {
|
||||
reservation.state = "publish";
|
||||
|
||||
//Finalmente hay que validar la inscripción del tutor en el caso de aquellos centros que no son aliados
|
||||
if ((await eventInscriptionService._validateInscriptionTutorOfReservation(reservation.id, reservation.userId)) <= 0) {
|
||||
if (
|
||||
(await eventInscriptionService._validateInscriptionTutorOfReservation(reservation.id, reservation.userId)) <= 0
|
||||
) {
|
||||
//En el caso de ser un centro aliado no se puede validar la inscripcion ya que se hace a posteriori por lo tanto no se hace nada
|
||||
// console.log("No se ha podido validar la inscripción del tutor por ser de un centro aliado se hace a posteriori en este caso");
|
||||
// return null;
|
||||
// console.log("No se ha podido validar la inscripción del tutor por ser de un centro aliado se hace a posteriori en este caso");
|
||||
// return null;
|
||||
}
|
||||
|
||||
console.log('reservation.userId>>>>>> ', reservation.userId);
|
||||
console.log("reservation.userId>>>>>> ", reservation.userId);
|
||||
//Mandamos el código de reserva para que registra a sus alumnos
|
||||
const user = await userService._getUserById(reservation.userId);
|
||||
reservation.contact_email = user.email;
|
||||
reservation.contact_name = user.name;
|
||||
console.log('reservation.userId>>>>>> ', user.email);
|
||||
console.log('reservation.userId>>>>>> ', user.email);
|
||||
console.log("reservation.userId>>>>>> ", user.email);
|
||||
console.log("reservation.userId>>>>>> ", user.email);
|
||||
|
||||
try {
|
||||
console.log('envio correo>>>>>>>>>>> ', user);
|
||||
console.log("envio correo>>>>>>>>>>> ", user);
|
||||
mailService.sendReservationCollegeEmail(reservation);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
};
|
||||
}
|
||||
|
||||
return reservation;
|
||||
}
|
||||
@ -75,8 +75,8 @@ async function activeReservation(reservation) {
|
||||
async function activeReservationById(id) {
|
||||
//Buscar reserva con evento y entidad
|
||||
let reservation = await eventReservationService._getReservaByIdWithEntityAndEvent(id);
|
||||
if (await activeReservation(reservation) === null) {
|
||||
console.log("Error activeReservationById")
|
||||
if ((await activeReservation(reservation)) === null) {
|
||||
console.log("Error activeReservationById");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -111,16 +111,14 @@ const extraControllers = {
|
||||
const eventId = params.params.id;
|
||||
const userId = req.user.id;
|
||||
let entityType = null;
|
||||
let entityId = null
|
||||
let entityId = null;
|
||||
// console.log('params.params.typeOrId>>>>++++++++++++++++++++++++++ 1 ', params.params.typeOrId);
|
||||
//typeOrId puede ser college, partner o el id de la entidad de la reserva
|
||||
const typeOrId = params.params.typeOrId;
|
||||
if (typeOrId !== null) {
|
||||
if ((typeOrId === "colleges") || (params.params.typeOrId === "partners"))
|
||||
entityType = typeOrId
|
||||
else
|
||||
entityId = typeOrId;
|
||||
};
|
||||
if (typeOrId === "colleges" || params.params.typeOrId === "partners") entityType = typeOrId;
|
||||
else entityId = typeOrId;
|
||||
}
|
||||
// console.log('params.params.typeOrId>>>>++++++++++++++++++++++++++ 2 ', entityId);
|
||||
// console.log('params.params.typeOrId>>>>++++++++++++++++++++++++++ 3 ', entityType);
|
||||
|
||||
@ -153,7 +151,10 @@ const extraControllers = {
|
||||
|
||||
try {
|
||||
if (reservation.Entity.contact_email)
|
||||
emailHelper.sendReservationCode(mailService.generateHeaderMailReservation(reservation), mailService.generateBodyMailReservation(reservation));
|
||||
emailHelper.sendReservationCode(
|
||||
mailService.generateHeaderMailReservation(reservation),
|
||||
mailService.generateBodyMailReservation(reservation)
|
||||
);
|
||||
} catch (error) {
|
||||
// console.log(error);
|
||||
console.log("No se ha podido mandar email con los códigos de invitación");
|
||||
@ -186,7 +187,10 @@ const extraControllers = {
|
||||
console.log("mando correo: ", reservation.Entity.name);
|
||||
if (reservation.Entity.contact_email && reservation.Entity.contact_email.length !== 0) {
|
||||
console.log("correo: ", reservation.Entity.contact_email);
|
||||
emailHelper.sendReservationCode(mailService.generateHeaderMailReservation(reservation), mailService.generateBodyMailReservation(reservation));
|
||||
emailHelper.sendReservationCode(
|
||||
mailService.generateHeaderMailReservation(reservation),
|
||||
mailService.generateBodyMailReservation(reservation)
|
||||
);
|
||||
result =
|
||||
result +
|
||||
"Invitación con código " +
|
||||
@ -270,7 +274,6 @@ const extraControllers = {
|
||||
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",
|
||||
@ -278,14 +281,14 @@ const extraControllers = {
|
||||
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: "orange",
|
||||
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,
|
||||
@ -303,10 +306,16 @@ const extraControllers = {
|
||||
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);
|
||||
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.
|
||||
@ -318,8 +327,7 @@ const extraControllers = {
|
||||
dataInscription.reservation = dataInscription.reservation.toJSON();
|
||||
res.locals.dataInscription = dataInscription;
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>RESERVATION CREADA", dataInscription.reservation);
|
||||
}
|
||||
else console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>no hago nada");
|
||||
} else console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>no hago nada");
|
||||
next();
|
||||
},
|
||||
|
||||
@ -341,14 +349,15 @@ 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") {
|
||||
@ -361,9 +370,10 @@ const extraControllers = {
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND);
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
else dataInscription.reservation = reservationPublicada;
|
||||
};
|
||||
}
|
||||
|
||||
next();
|
||||
},
|
||||
@ -378,9 +388,12 @@ const extraControllers = {
|
||||
let result = await activeReservationById(idResevation);
|
||||
return handleResultResponse(result, null, params, res, httpStatus.OK);
|
||||
} catch (error) {
|
||||
console.log('********************************************************************************************', error);
|
||||
console.log(
|
||||
"********************************************************************************************",
|
||||
error
|
||||
);
|
||||
//return handleResultResponse("Error al buscar las reservas", null, params, res, httpStatus.NOT_FOUND);
|
||||
return handleErrorResponse('activarReservation', 'methodName', error.stack, res);
|
||||
return handleErrorResponse("activarReservation", "methodName", error.stack, res);
|
||||
}
|
||||
},
|
||||
|
||||
@ -390,29 +403,28 @@ const extraControllers = {
|
||||
if (!idResevation)
|
||||
return handleResultResponse("Error id de reservation necesario", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
const eventReservation = await eventReservationService._getReservaById(idResevation);
|
||||
const eventReservation = await eventReservationService._getReservaById(idResevation);
|
||||
if (!eventReservation)
|
||||
return handleResultResponse("Error reserva no existente", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
try {
|
||||
//Antes de borrar una reserva debemos borrar todas las inscripciones asociadas.
|
||||
eventInscriptionService._deleteInscriptionsByReservation(eventReservation.id);
|
||||
if (eventReservation.state === 'publish'){
|
||||
if (eventReservation.state === "publish") {
|
||||
const cantidad = -1 * eventReservation.assistants;
|
||||
eventService._updateAforoOfEventReservation(eventReservation, cantidad);
|
||||
}
|
||||
|
||||
let result = eventReservationService._deleteReservation(eventReservation.id);
|
||||
let result = eventReservationService._deleteReservation(eventReservation.id);
|
||||
return handleResultResponse(result, null, params, res, httpStatus.OK);
|
||||
|
||||
} catch (error) {
|
||||
return handleResultResponse("Error al eliminar la reserva", null, params, res, httpStatus.NOT_FOUND);
|
||||
}
|
||||
},
|
||||
|
||||
/**** Modifica una reserva, si está publicada, actualiza la diferenecia de los asistentes, en el caso de ser modificado, en el aforo del evento (assitants).
|
||||
*/
|
||||
checkAssitantsUpdate: async (req, res, next) => {
|
||||
/**** Modifica una reserva, si está publicada, actualiza la diferenecia de los asistentes, en el caso de ser modificado, en el aforo del evento (assitants).
|
||||
*/
|
||||
checkAssitantsUpdate: async (req, res, next) => {
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const idResevation = params.params.id;
|
||||
const NewReservarionAssistants = req.body.assistants;
|
||||
@ -425,23 +437,27 @@ const extraControllers = {
|
||||
return handleResultResponse("Error reserva no existente", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
try {
|
||||
if (eventReservation.state === 'publish' && eventReservation.assistants != NewReservarionAssistants) {
|
||||
if (eventReservation.state === "publish" && eventReservation.assistants != NewReservarionAssistants) {
|
||||
if (NewReservarionAssistants < eventReservation.confirmed) {
|
||||
return handleResultResponse(
|
||||
"Error el número de asistentes no puede ser menor que el de confirmados",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
}
|
||||
|
||||
if (NewReservarionAssistants < eventReservation.confirmed) {
|
||||
return handleResultResponse("Error el número de asistentes no puede ser menor que el de confirmados", null, params, res, httpStatus.NOT_FOUND);
|
||||
};
|
||||
|
||||
const cantidad = (NewReservarionAssistants - eventReservation.assistants);
|
||||
await eventService._updateAforoOfEventReservation(eventReservation, cantidad);
|
||||
const cantidad = NewReservarionAssistants - eventReservation.assistants;
|
||||
await eventService._updateAforoOfEventReservation(eventReservation, cantidad);
|
||||
}
|
||||
|
||||
next();
|
||||
|
||||
} catch (error) {
|
||||
//console.log('checkAssitantsUpdate >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', error.stack);
|
||||
return handleErrorResponse('controllerName', 'methodName', error.stack, res);
|
||||
return handleErrorResponse("controllerName", "methodName", error.stack, res);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
//Esta función se llama desde APP y desde WEB
|
||||
@ -486,10 +502,13 @@ const extraControllers = {
|
||||
) {
|
||||
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')
|
||||
if (
|
||||
dataInscription.type === "online" ||
|
||||
dataInscription.type === "online group" ||
|
||||
dataInscription.reservation.state === "publish"
|
||||
)
|
||||
dataInscription.validated = true;
|
||||
|
||||
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", dataInscription.type);
|
||||
//Actualizamos aforo de la lista de espera de la reserva y creamos inscripcion en la lista de espera de la reserva
|
||||
if (
|
||||
@ -570,16 +589,19 @@ const extraControllers = {
|
||||
...Result,
|
||||
};
|
||||
|
||||
|
||||
// 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(Result, null, params, res, httpStatus.CREATED);
|
||||
} catch (error) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user