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
|
//1. Todas las inscripciones online de un evento, cuando el usuario es administrador
|
||||||
getInscriptionsOnline: async (req, res, next) => {
|
getInscriptionsOnline: async (req, res, next) => {
|
||||||
const params = extractParamsFromRequest(req, res, {});
|
const params = extractParamsFromRequest(req, res, {});
|
||||||
@ -147,7 +147,7 @@ const extraControllers = {
|
|||||||
const userId = req.user.id;
|
const userId = req.user.id;
|
||||||
var result = null;
|
var result = null;
|
||||||
|
|
||||||
//console.log(params, req.user.level);
|
//console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', params, req.user.level);
|
||||||
if (!eventId)
|
if (!eventId)
|
||||||
return handleResultResponse("Es necesario el ID del evento", null, params, res, httpStatus.NOT_FOUND);
|
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);
|
var member = generateMemberInscription(inscription.user, inscription, inscription.reservation);
|
||||||
member.marketing_memberId = await eventInscriptionService._addMember(marketingListIdEvent, member);
|
member.marketing_memberId = await eventInscriptionService._addMember(marketingListIdEvent, member);
|
||||||
eventInscriptionService._updateMarketingMemberOfInscription(inscription.id, member.marketing_memberId);
|
eventInscriptionService._updateMarketingMemberOfInscription(inscription.id, member.marketing_memberId);
|
||||||
member.qrConfig = generateQRConfig(member);
|
member.qrConfig = QRHelper.generateQRConfig(member);
|
||||||
member.qrCode = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
member.qrCode = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
||||||
member.qrCodeUrl = QRHelper.getInscriptionQRCodeUrl(inscription.id);
|
member.qrCodeUrl = QRHelper.getInscriptionQRCodeUrl(inscription.id);
|
||||||
console.log(
|
console.log(
|
||||||
|
|||||||
@ -8,25 +8,20 @@ const eventService = require("./event.service");
|
|||||||
const mailService = require("./mail.service");
|
const mailService = require("./mail.service");
|
||||||
const marketingListService = require("./marketing_list.service");
|
const marketingListService = require("./marketing_list.service");
|
||||||
const QRHelper = require("../../helpers/qr.helper");
|
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 { data } = require("../../core/logger");
|
||||||
const lodash = require("lodash");
|
const lodash = require("lodash");
|
||||||
|
const userService = require("../auth/user.service");
|
||||||
|
|
||||||
// Module Name
|
// Module Name
|
||||||
const MODULE_NAME = "[eventInscription.controller]";
|
const MODULE_NAME = "[eventInscription.controller]";
|
||||||
const controllerOptions = { MODULE_NAME };
|
const controllerOptions = { MODULE_NAME };
|
||||||
|
|
||||||
|
|
||||||
async function refreshConfirmed (inscription){
|
async function refreshConfirmed(inscription) {
|
||||||
|
|
||||||
if (!inscription){
|
if (!inscription) {
|
||||||
return handleResultResponse(
|
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada");
|
||||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada",
|
|
||||||
null,
|
|
||||||
params,
|
|
||||||
res,
|
|
||||||
httpStatus.NOT_FOUND
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (inscription.type === "online")
|
if (inscription.type === "online")
|
||||||
@ -74,25 +69,15 @@ async function refreshConfirmed (inscription){
|
|||||||
if (inscription.reservationId != null) {
|
if (inscription.reservationId != null) {
|
||||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo reserva", EventOrReservationChangeId);
|
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo reserva", EventOrReservationChangeId);
|
||||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||||
if (!(await eventReservationService._updateConfirmedReservation(EventOrReservationChangeId, NewConfirmed)))
|
if (!(await eventReservationService._updateConfirmedReservation(EventOrReservationChangeId, NewConfirmed))) {
|
||||||
return handleResultResponse(
|
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada");
|
||||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada",
|
}
|
||||||
null,
|
|
||||||
params,
|
|
||||||
res,
|
|
||||||
httpStatus.NOT_FOUND
|
|
||||||
);
|
|
||||||
} else {
|
} else {
|
||||||
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo evento", EventOrReservationChangeId);
|
console.log(">>>>>>>>>>>>>>Voy a actualizar aforo evento", EventOrReservationChangeId);
|
||||||
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
console.log(">>>>>>>>>>>>>> ", NewConfirmed);
|
||||||
if (!(await eventService._updateConfirmedEvent(EventOrReservationChangeId, NewConfirmed)))
|
if (!(await eventService._updateConfirmedEvent(EventOrReservationChangeId, NewConfirmed))) {
|
||||||
return handleResultResponse(
|
throw new Error("Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion");
|
||||||
"Error al eliminar inscripción, no puedo cambiar confirmados a la inscripcion",
|
}
|
||||||
null,
|
|
||||||
params,
|
|
||||||
res,
|
|
||||||
httpStatus.NOT_FOUND
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -109,7 +94,7 @@ const extraControllers = {
|
|||||||
typeInscription = "online";
|
typeInscription = "online";
|
||||||
|
|
||||||
//Si viene code es la appa antigua o la nueva
|
//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)))
|
|| ((req.body.group_size) && (req.body.group_size > 1)))
|
||||||
typeInscription = typeInscription + " group";
|
typeInscription = typeInscription + " group";
|
||||||
|
|
||||||
@ -215,7 +200,7 @@ const extraControllers = {
|
|||||||
return handleResultResponse(dataInscription.inscription, null, params, res, httpStatus.OK);
|
return handleResultResponse(dataInscription.inscription, null, params, res, httpStatus.OK);
|
||||||
};
|
};
|
||||||
|
|
||||||
} catch(error){
|
} catch (error) {
|
||||||
return handleResultResponse("Error checkInscriptionByUser", error, params, res, httpStatus.NOT_FOUND);
|
return handleResultResponse("Error checkInscriptionByUser", error, params, res, httpStatus.NOT_FOUND);
|
||||||
};
|
};
|
||||||
next();
|
next();
|
||||||
@ -235,7 +220,7 @@ const extraControllers = {
|
|||||||
}
|
}
|
||||||
//console.log("inscripcion encontrada>>>>>>>>>>>>>>>>>>>>>>>>>>>", inscription);
|
//console.log("inscripcion encontrada>>>>>>>>>>>>>>>>>>>>>>>>>>>", inscription);
|
||||||
inscription = await inscription.toJSON();
|
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);
|
var member = marketingListService._generateMarketingDTO(inscription);
|
||||||
member.qrConfig = QRHelper.generateQRConfig(member);
|
member.qrConfig = QRHelper.generateQRConfig(member);
|
||||||
inscription.code_ticket_qr = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
inscription.code_ticket_qr = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
||||||
@ -344,8 +329,8 @@ const extraControllers = {
|
|||||||
dataInscription.event.id,
|
dataInscription.event.id,
|
||||||
inscriptionsWithoutReservationAndOverflowCount
|
inscriptionsWithoutReservationAndOverflowCount
|
||||||
)
|
)
|
||||||
){
|
) {
|
||||||
try{
|
try {
|
||||||
dataInscription.inscription = await eventInscriptionService._createInscription(
|
dataInscription.inscription = await eventInscriptionService._createInscription(
|
||||||
dataInscription.event.id,
|
dataInscription.event.id,
|
||||||
dataUser.id,
|
dataUser.id,
|
||||||
@ -355,7 +340,7 @@ const extraControllers = {
|
|||||||
null,
|
null,
|
||||||
null
|
null
|
||||||
)
|
)
|
||||||
}catch(error){console.log('SSSSSSSSSSSSSSSSSSSSSSSSS',error)}
|
} catch (error) { console.log('SSSSSSSSSSSSSSSSSSSSSSSSS', error) }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return handleResultResponse(
|
return handleResultResponse(
|
||||||
@ -365,7 +350,7 @@ const extraControllers = {
|
|||||||
res,
|
res,
|
||||||
httpStatus.NOT_FOUND
|
httpStatus.NOT_FOUND
|
||||||
);
|
);
|
||||||
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
||||||
|
|
||||||
//Ponemos el evento en SOLD_OUT
|
//Ponemos el evento en SOLD_OUT
|
||||||
if (dataInscription.event.assistants == inscriptionsWithoutReservationAndOverflowCount)
|
if (dataInscription.event.assistants == inscriptionsWithoutReservationAndOverflowCount)
|
||||||
@ -439,12 +424,12 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
|||||||
//Incluimos correo en sendinblue
|
//Incluimos correo en sendinblue
|
||||||
try {
|
try {
|
||||||
marketingListService.addMarketingList(dataUser, dataInscription);
|
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
|
//Mandamos correo con entrada o lista de espera
|
||||||
try {
|
try {
|
||||||
mailService.sendEmailConfirm(dataUser, dataInscription);
|
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);
|
return handleResultResponse(await dataInscription.inscription, null, params, res, httpStatus.CREATED);
|
||||||
@ -482,7 +467,7 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
|||||||
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada");
|
console.log(">>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada");
|
||||||
|
|
||||||
//Actualizamos confirmados asistentes
|
//Actualizamos confirmados asistentes
|
||||||
refreshConfirmed (inscription);
|
refreshConfirmed(inscription);
|
||||||
|
|
||||||
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed === 1) {
|
if (inscription.user.profile === "tutor" && inscription.reservation && inscription.reservation.confirmed === 1) {
|
||||||
//Eliminamos la reserva hecha del centro aliado
|
//Eliminamos la reserva hecha del centro aliado
|
||||||
@ -505,12 +490,12 @@ console.log('Inscripcion hecha>>>', dataInscription.inscription);
|
|||||||
//Quitamos correo en sendinblue
|
//Quitamos correo en sendinblue
|
||||||
try {
|
try {
|
||||||
marketingListService._deleteMember(marketingListId, inscription.user.email);
|
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
|
//Mandamos correo de confirmación de eliminación
|
||||||
try {
|
try {
|
||||||
mailService.sendEmailCancelate(inscription);
|
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");
|
console.log(">>>>>>>>>>>>>>Inscripcion eliminada con todos los pasos");
|
||||||
return handleResultResponse("Inscripción eliminada", null, params, res, httpStatus.DELETEOK);
|
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) => {
|
_getInscriptionByEventAndValidated: (eventId, validated) => {
|
||||||
return models.EventInscription.scope("defaultScope").findAll({
|
return models.EventInscription.scope("defaultScope").findAll({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
@ -237,13 +237,14 @@ const extraControllers = {
|
|||||||
params,
|
params,
|
||||||
res,
|
res,
|
||||||
httpStatus.NOT_FOUND
|
httpStatus.NOT_FOUND
|
||||||
)};
|
)
|
||||||
|
};
|
||||||
|
|
||||||
const reservationData = {
|
const reservationData = {
|
||||||
reservation_code: eventReservationService._generateReservatioCode(dataInscription.event, dataUser.entityName),
|
reservation_code: eventReservationService._generateReservatioCode(dataInscription.event, dataUser.entityName),
|
||||||
state: "draft", //sin confirmar, publish es cuando se descuenta del aforo del evento
|
state: "draft", //sin confirmar, publish es cuando se descuenta del aforo del evento
|
||||||
color: "gray",
|
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,
|
init_available_date: dataInscription.event.init_available_date,
|
||||||
end_available_date: dataInscription.event.end_available_date,
|
end_available_date: dataInscription.event.end_available_date,
|
||||||
entityId: dataUser.entityId,
|
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
|
//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;
|
const plazasDisponibles = dataInscription.event.assistants - dataInscription.event.confirmed;
|
||||||
if (plazasDisponibles < reservationData.assistants)
|
if (plazasDisponibles < reservationData.assistants)
|
||||||
if (dataInscription.event.allow_overflow){
|
if (dataInscription.event.allow_overflow) {
|
||||||
reservationData.overflowEventId = dataInscription.event.overflow_eventId;
|
reservationData.overflowEventId = dataInscription.event.overflow_eventId;
|
||||||
reservationData.description = reservationData.description + ' en lista de espera'
|
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);
|
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
|
//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");
|
console.log(">> No se aplica descuento de aforo ya que es una reserva publicada");
|
||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
@ -332,7 +333,7 @@ const extraControllers = {
|
|||||||
);
|
);
|
||||||
|
|
||||||
//Si se ha llenado ponemos el evento en SOLD_OUT
|
//Si se ha llenado ponemos el evento en SOLD_OUT
|
||||||
if (eventToDiscountAssistants.confirmed == newAforo)
|
if (eventToDiscountAssistants.confirmed >= newAforo)
|
||||||
await eventService._updateSoldOutEvent(eventToDiscountAssistants.id, true);
|
await eventService._updateSoldOutEvent(eventToDiscountAssistants.id, true);
|
||||||
|
|
||||||
//Finalmente publicamos la reserva solo si no está asociada a la lista de espera
|
//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_email = dataUser.email;
|
||||||
dataInscription.reservation.contact_name = dataUser.name;
|
dataInscription.reservation.contact_name = dataUser.name;
|
||||||
dataInscription.reservation.event = dataInscription.event;
|
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);
|
mailService.sendReservationEmail(dataInscription.reservation);
|
||||||
}catch(error){
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -505,15 +506,15 @@ const extraControllers = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Incluimos correo en sendinblue
|
// Incluimos correo en sendinblue
|
||||||
try {
|
try {
|
||||||
// marketingListService.addMarketingList(dataUser, dataInscription);
|
// 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
|
//Mandamos correo con entrada o lista de espera
|
||||||
try {
|
try {
|
||||||
mailService.sendEmailConfirm(dataUser, dataInscription);
|
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);
|
return handleResultResponse(Result, null, params, res, httpStatus.CREATED);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@ -125,7 +125,8 @@ module.exports = function (sequelize, DataTypes) {
|
|||||||
required: false,
|
required: false,
|
||||||
include: [{
|
include: [{
|
||||||
model: sequelize.models.MultimediaFile,
|
model: sequelize.models.MultimediaFile,
|
||||||
as: "multimediaFile"
|
as: "multimediaFile",
|
||||||
|
order: [['createdAt', 'DESC']],
|
||||||
}]
|
}]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "lqdvi-api3",
|
"name": "lqdvi-api3",
|
||||||
"version": "1.3.0",
|
"version": "1.3.3",
|
||||||
"description": "",
|
"description": "",
|
||||||
"author": "Rodax Software",
|
"author": "Rodax Software",
|
||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user