aa
This commit is contained in:
parent
d37b3fd84d
commit
c5473233d5
@ -148,96 +148,83 @@ console.log(params, req.user.level);
|
||||
},
|
||||
|
||||
validateInscription: async (req, res, next) => {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><< validateInscription');
|
||||
const params = extractParamsFromRequest(req, res, {});
|
||||
const user = req.user;
|
||||
|
||||
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1validar inscription:', params);
|
||||
console.log('usuario:', user);
|
||||
|
||||
const inscriptionId = params.params.id;
|
||||
|
||||
try {
|
||||
const inscription = await eventInscriptionService._getInscriptionById(inscriptionId);
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion a borrar:');
|
||||
console.log(inscription);
|
||||
/* if (!inscription || (inscription.userId !== user.id))
|
||||
return handleResultResponse("Inscription no encontrada", null, params, res, httpStatus.NOT_FOUND);
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion a Validar:');
|
||||
console.log(inscription);
|
||||
|
||||
//Borramos inscripcion y descontamos asistentes
|
||||
if (await eventInscriptionService._deleteInscription(inscription.id) > 0) {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion borrada');
|
||||
const EventOrReservationChangeId = ((inscription.reservationId) ? inscription.reservationId : ((inscription.overflowEventId) ? inscription.overflowEventId : inscription.eventId));
|
||||
let NewConfirmed = 0;
|
||||
let marketingListId = null;
|
||||
//Si la inscripcion no existe o ya está validada no hago nada
|
||||
if (!inscription)
|
||||
return handleResultResponse("Inscription no encontrada", null, params, res, httpStatus.NOT_FOUND)
|
||||
else if (inscription.validated)
|
||||
return handleResultResponse("Inscripción validada", null, params, res, httpStatus.OK);
|
||||
|
||||
if (inscription.reservationId != null) {
|
||||
console.log('Tengo reservation>>>>>>>>>>>>>>>>>>', inscription.reservationId);
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithReservation(EventOrReservationChangeId)
|
||||
marketingListId = (await eventReservationService._getReservaById(EventOrReservationChangeId)).marketing_list;
|
||||
}
|
||||
else if (inscription.overflowEventId != null) {
|
||||
console.log('Tengo overflow>>>>>>>>>>>>>>>>>>', inscription.overflowEventId);
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithOverflowEventId(EventOrReservationChangeId);
|
||||
marketingListId = (await eventService._getEvent(EventOrReservationChangeId)).marketing_list;
|
||||
}
|
||||
else if (inscription.eventId != null) {
|
||||
NewConfirmed = await eventInscriptionService._getCountInscriptionsWithoutReservationAndOverflow(EventOrReservationChangeId);
|
||||
marketingListId = (await eventService._getEvent(EventOrReservationChangeId)).marketing_list;
|
||||
}
|
||||
//Si la inscripción es lista de espera de una reserva
|
||||
if (inscription.reservationId)
|
||||
{
|
||||
return handleResultResponse("Inscription a validar viene por reserva hay que implementarlo", null, params, res, httpStatus.NOT_FOUND);
|
||||
// console.log('Tengo reservation>>>>>>>>>>>>>>>>>>', inscription.reservationId);
|
||||
// NewConfirmed = await eventInscriptionService._getCountInscriptionsWithReservation(EventOrReservationChangeId)
|
||||
// marketingListId = (await eventReservationService._getReservaById(EventOrReservationChangeId)).marketing_list;
|
||||
// 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);
|
||||
}
|
||||
//Si la inscripcion es lista de espera del evento
|
||||
else if (inscription.overflowEventId)
|
||||
{
|
||||
const OverflowEventId = inscription.overflowEventId;
|
||||
|
||||
//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);
|
||||
if (await eventInscriptionService._validateInscription(inscription.id) > 0) {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion validada');
|
||||
var NewConfirmedOverflow = await eventInscriptionService._getCountInscriptionsWithOverflowEventId(OverflowEventId);
|
||||
var NewConfirmedEvent = await eventInscriptionService._getCountInscriptionsWithoutReservationAndOverflow(inscription.eventId);
|
||||
marketingListIdOverflow = (await eventService._getEvent(OverflowEventId)).marketing_list;
|
||||
marketingListIdEvent = (await eventService._getEvent(inscription.eventId)).marketing_list;
|
||||
|
||||
}
|
||||
if (!await eventService._updateConfirmedEvent(OverflowEventId, NewConfirmedOverflow))
|
||||
return handleResultResponse("Error al validad inscripción, no puedo cambiar confirmados a la lista de espera", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
if (!await eventService._updateConfirmedEvent(inscription.eventId, NewConfirmedEvent))
|
||||
return handleResultResponse("Error al validad inscripción, no puedo cambiar confirmados al evento", null, params, res, httpStatus.NOT_FOUND);
|
||||
//Eliminamos miembro de la lista de mailchimp a la que está asociado
|
||||
await eventInscriptionService._deleteMember(marketingListId, inscription.marketing_memberId);
|
||||
// await eventInscriptionService._deleteMember(marketingListIdOverflow, inscription.marketing_memberId);
|
||||
|
||||
/*Mandar correo de confirmacion de desinscripcion
|
||||
var headerMail = {
|
||||
to: user.email,
|
||||
name: user.name + ' ' + user.surname,
|
||||
subject: ((member.validated) ? 'Entrada' : 'Lista de espera') + ' para el congreso ' + dataInscription.event.name + ' confirmada'
|
||||
}
|
||||
const userInscription = inscription.user;
|
||||
//Mandar correo de confirmacion de desinscripcion
|
||||
var headerMail = {
|
||||
to: userInscription.email,
|
||||
name: userInscription.name + ' ' + userInscription.surname,
|
||||
subject: 'Entrada para el congreso ' + inscription.event.name + ' confirmada'
|
||||
}
|
||||
|
||||
var bodyMail = {
|
||||
tipoEntrada: (member.validated) ? 'Entrada' : 'Lista de espera',
|
||||
descriptionEntrada: member.description,
|
||||
qrCode: qrCode,
|
||||
color: qrConfig.color,
|
||||
codeTicket: member.code_ticket,
|
||||
eventName: dataInscription.event.name,
|
||||
dateInscription: moment(dataInscription.event.init_date).format('D [de] MMMM [de] YYYY'),
|
||||
}
|
||||
var bodyMail = {
|
||||
tipoEntrada: 'Entrada',
|
||||
// descriptionEntrada: member.description,
|
||||
// qrCode: qrCode,
|
||||
// color: qrConfig.color,
|
||||
// codeTicket: member.code_ticket,
|
||||
eventName: inscription.event.name,
|
||||
dateInscription: moment(inscription.event.init_date).format('D [de] MMMM [de] YYYY'),
|
||||
}
|
||||
|
||||
console.log('Mandamos mail con entrada>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
console.log(headerMail, bodyMail);
|
||||
console.log('Mandamos mail con entrada>>>>>>>>>>>>>>>>>>>>>>>>>>>');
|
||||
console.log(headerMail, bodyMail);
|
||||
|
||||
try {
|
||||
if (member.validated)
|
||||
emailHelper.sendTicket(headerMail, bodyMail)
|
||||
else
|
||||
emailHelper.sendListaEspera(headerMail, bodyMail);
|
||||
} catch (error) {
|
||||
console.log('No se ha podido mandar email con entrada');
|
||||
};
|
||||
*/
|
||||
try {
|
||||
emailHelper.sendTicket(headerMail, bodyMail)
|
||||
} catch (error) {
|
||||
console.log('No se ha podido mandar email con entrada');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
return handleResultResponse("Inscripción validada", null, params, res, httpStatus.OK);
|
||||
//}
|
||||
// else
|
||||
// return handleResultResponse("No se pudo eliminar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||
return handleResultResponse("Inscripción validada", null, params, res, httpStatus.OK);
|
||||
}
|
||||
else
|
||||
return handleResultResponse("No se pudo validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
} catch (error) {
|
||||
return handleResultResponse("Error al validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||
|
||||
@ -169,6 +169,18 @@ const extraMethods = {
|
||||
});
|
||||
},
|
||||
|
||||
//Validamos la inscripcion la quitamos de las lista de espera y asignamos el usuario que la ha validado
|
||||
_validateInscription: (inscriptionId, userId) => {
|
||||
return models.EventInscription.update({
|
||||
validated: true,
|
||||
overflowEventId: null,
|
||||
validateUserId: userId,
|
||||
},
|
||||
{where: {
|
||||
id: inscriptionId,
|
||||
}});
|
||||
},
|
||||
|
||||
_addMember: (marketingListId, member) => {
|
||||
|
||||
// console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr1');
|
||||
|
||||
Loading…
Reference in New Issue
Block a user