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,7 +147,7 @@ const extraControllers = {
|
||||
const userId = req.user.id;
|
||||
var result = null;
|
||||
|
||||
//console.log(params, req.user.level);
|
||||
//console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', params, req.user.level);
|
||||
if (!eventId)
|
||||
return handleResultResponse("Es necesario el ID del evento", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
@ -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(
|
||||
|
||||
@ -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")
|
||||
@ -74,25 +69,15 @@ async function refreshConfirmed (inscription){
|
||||
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
|
||||
);
|
||||
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)))
|
||||
return handleResultResponse(
|
||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion",
|
||||
null,
|
||||
params,
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
if (!(await eventService._updateConfirmedEvent(EventOrReservationChangeId, NewConfirmed))) {
|
||||
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -109,7 +94,7 @@ const extraControllers = {
|
||||
typeInscription = "online";
|
||||
|
||||
//Si viene code es la appa antigua o la nueva
|
||||
if (((req.body.code) && (req.body.code !==""))
|
||||
if (((req.body.code) && (req.body.code !== ""))
|
||||
|| ((req.body.group_size) && (req.body.group_size > 1)))
|
||||
typeInscription = typeInscription + " group";
|
||||
|
||||
@ -215,7 +200,7 @@ const extraControllers = {
|
||||
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,7 +220,7 @@ 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);
|
||||
@ -344,8 +329,8 @@ const extraControllers = {
|
||||
dataInscription.event.id,
|
||||
inscriptionsWithoutReservationAndOverflowCount
|
||||
)
|
||||
){
|
||||
try{
|
||||
) {
|
||||
try {
|
||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||
dataInscription.event.id,
|
||||
dataUser.id,
|
||||
@ -355,7 +340,7 @@ const extraControllers = {
|
||||
null,
|
||||
null
|
||||
)
|
||||
}catch(error){console.log('SSSSSSSSSSSSSSSSSSSSSSSSS',error)}
|
||||
} catch (error) { console.log('SSSSSSSSSSSSSSSSSSSSSSSSS', error) }
|
||||
}
|
||||
else
|
||||
return handleResultResponse(
|
||||
@ -365,7 +350,7 @@ const extraControllers = {
|
||||
res,
|
||||
httpStatus.NOT_FOUND
|
||||
);
|
||||
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
|
||||
//Ponemos el evento en SOLD_OUT
|
||||
if (dataInscription.event.assistants == inscriptionsWithoutReservationAndOverflowCount)
|
||||
@ -439,12 +424,12 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
//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);
|
||||
@ -482,7 +467,7 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada");
|
||||
|
||||
//Actualizamos confirmados asistentes
|
||||
refreshConfirmed (inscription);
|
||||
refreshConfirmed(inscription);
|
||||
|
||||
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed === 1) {
|
||||
//Eliminamos la reserva hecha del centro aliado
|
||||
@ -505,12 +490,12 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||
//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);
|
||||
|
||||
@ -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: {
|
||||
|
||||
@ -237,13 +237,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: "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,13 +257,13 @@ 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"){
|
||||
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){
|
||||
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);
|
||||
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);
|
||||
}
|
||||
@ -302,7 +303,7 @@ const extraControllers = {
|
||||
};
|
||||
|
||||
//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;
|
||||
@ -332,7 +333,7 @@ const extraControllers = {
|
||||
);
|
||||
|
||||
//Si se ha llenado ponemos el evento en SOLD_OUT
|
||||
if (eventToDiscountAssistants.confirmed == newAforo)
|
||||
if (eventToDiscountAssistants.confirmed >= newAforo)
|
||||
await eventService._updateSoldOutEvent(eventToDiscountAssistants.id, true);
|
||||
|
||||
//Finalmente publicamos la reserva solo si no está asociada a la lista de espera
|
||||
@ -351,11 +352,11 @@ const extraControllers = {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -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,7 +125,8 @@ 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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user