From c5473233d505ad196f0adad37014a6690ed87067 Mon Sep 17 00:00:00 2001 From: david Date: Thu, 12 Sep 2019 13:50:39 +0200 Subject: [PATCH] aa --- modules/events/event.controller.js | 137 ++++++++---------- modules/events/events_inscriptions.service.js | 12 ++ 2 files changed, 74 insertions(+), 75 deletions(-) diff --git a/modules/events/event.controller.js b/modules/events/event.controller.js index 4d97660..2d35294 100644 --- a/modules/events/event.controller.js +++ b/modules/events/event.controller.js @@ -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('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 0) { - console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>', 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('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>'); - 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); diff --git a/modules/events/events_inscriptions.service.js b/modules/events/events_inscriptions.service.js index 30edb0c..0aaee58 100644 --- a/modules/events/events_inscriptions.service.js +++ b/modules/events/events_inscriptions.service.js @@ -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');