2019-07-09 08:51:00 +00:00
'use strict' ;
2019-08-29 18:08:22 +00:00
const moment = require ( 'moment' ) ;
2019-07-19 19:36:20 +00:00
const httpStatus = require ( 'http-status' ) ;
2019-07-09 08:51:00 +00:00
const generateControllers = require ( '../../core/controllers' ) ;
2019-07-28 20:08:15 +00:00
const QRHelper = require ( '../../helpers/qr.helper' ) ;
2019-08-13 18:00:27 +00:00
const emailHelper = require ( '../../helpers/mail.helper' ) ;
2019-08-19 17:54:39 +00:00
const path = require ( "path" ) ;
2019-08-13 18:00:27 +00:00
const messages = require ( '../../helpers/messages.json' ) ;
2019-07-09 08:51:00 +00:00
const eventService = require ( './event.service' ) ;
2019-07-19 17:39:19 +00:00
const eventReservationService = require ( './events_reservations.service' ) ;
2019-07-20 19:23:05 +00:00
const eventInscriptionService = require ( './events_inscriptions.service' ) ;
2019-07-09 15:37:56 +00:00
const { extractParamsFromRequest , handleErrorResponse , handleResultResponse } = require ( '../../helpers/controller.helper' ) ;
2019-07-09 08:51:00 +00:00
2019-07-16 18:18:28 +00:00
//PRUEBA
const SchemaValidator = require ( '../../middlewares/schemaValidator' ) ;
const eventValidation = require ( './event.validations' ) ;
const Joi = require ( 'joi' ) ;
2019-07-19 17:39:19 +00:00
const userService = require ( '../auth/user.service' ) ;
2019-07-20 19:23:05 +00:00
2019-07-09 08:51:00 +00:00
// Module Name
const MODULE _NAME = '[event.controller]' ;
const controllerOptions = { MODULE _NAME } ;
2019-07-09 15:37:56 +00:00
const extraControllers = {
2019-07-19 17:39:19 +00:00
2019-07-19 19:36:20 +00:00
checkReservationCode : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
2019-09-09 14:36:45 +00:00
const appVersion = ( ( req && req . headers && req . headers [ 'accept-version' ] ) ? req . headers [ 'accept-version' ] : null ) ;
console . log ( 'checkReservationCode - appVEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEErsion: ' , appVersion ) ;
2019-07-19 19:36:20 +00:00
const eventId = params . params . id ;
const encodedInvitationCode = params . params . encodedInvitationCode ;
2019-07-26 18:12:00 +00:00
const registrationCode = Buffer . from ( req . params . encodedInvitationCode , 'base64' ) . toString ( 'ascii' ) ;
2019-07-19 19:36:20 +00:00
try {
const result = await eventReservationService . _getReservaByCode ( eventId , registrationCode ) ;
2019-09-10 15:07:22 +00:00
if ( appVersion ) {
if ( ( appVersion == '1.0.0' ) || ( appVersion == '1.0.1' ) || ( appVersion == '1.0.2' ) )
return handleResultResponse ( ! ! result , null , params , res , httpStatus . OK )
else
return handleResultResponse ( result , null , params , res , httpStatus . OK ) ;
}
2019-09-09 14:36:45 +00:00
else
return handleResultResponse ( ! ! result , null , params , res , httpStatus . OK ) ;
2019-07-19 19:36:20 +00:00
} catch ( error ) {
2019-07-30 16:24:06 +00:00
return handleErrorResponse ( MODULE _NAME , 'checkReservationCode' , error , res )
2019-07-19 19:36:20 +00:00
}
} ,
2019-07-25 18:43:03 +00:00
//Funcion que devuelve:
2019-08-20 15:37:53 +00:00
//1. Todas las inscripciones de un evento, cuando el usuario es administrador
2019-07-25 18:43:03 +00:00
//2. Todas las inscripciones de un usuario, cuando no nos llega ningun param con id
getInscriptions : async ( req , res , next ) => {
2019-07-21 20:58:41 +00:00
const params = extractParamsFromRequest ( req , res , { } ) ;
const eventId = params . params . id ;
const userId = req . user . id ;
2019-08-20 15:37:53 +00:00
var result = null ;
2019-07-21 20:58:41 +00:00
2019-08-30 18:04:21 +00:00
console . log ( params , req . user . level ) ;
2019-07-25 18:43:03 +00:00
if ( eventId ) {
try {
2019-08-20 15:37:53 +00:00
if ( req . user . level = 8 )
result = await eventInscriptionService . _getInscriptionByEvent ( eventId )
else
result = await eventInscriptionService . _getInscriptionByEventAndUser ( eventId , userId ) ;
2019-08-30 16:51:45 +00:00
2019-07-30 16:24:06 +00:00
return handleResultResponse ( result , null , params , res , ( result === null ) ? httpStatus . NOT _FOUND : httpStatus . OK ) ;
2019-07-25 18:43:03 +00:00
} catch ( error ) {
2019-07-30 16:24:06 +00:00
return handleErrorResponse ( MODULE _NAME , 'getInscriptions' , error , res )
2019-07-25 18:43:03 +00:00
}
2019-07-21 20:58:41 +00:00
}
2019-07-25 18:43:03 +00:00
else {
try {
2019-08-20 15:37:53 +00:00
result = await eventInscriptionService . _getInscriptionsUser ( userId ) ;
2019-07-30 16:24:06 +00:00
return handleResultResponse ( result , null , params , res , ( result === null ) ? httpStatus . NOT _FOUND : httpStatus . OK ) ;
2019-07-25 18:43:03 +00:00
} catch ( error ) {
2019-07-30 16:24:06 +00:00
return handleErrorResponse ( MODULE _NAME , 'getInscriptions' , error , res )
2019-07-25 18:43:03 +00:00
}
}
2019-07-21 20:58:41 +00:00
} ,
2019-07-30 16:24:06 +00:00
getInscriptionsOfNextEventsCount : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const userId = req . user . id ;
try {
const result = await eventInscriptionService . _getInscriptionsOfNextEventsUser ( userId ) ;
console . log ( 'bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb' ) ;
2019-07-30 16:29:22 +00:00
return handleResultResponse ( { count : result } , null , params , res , httpStatus . OK ) ;
2019-07-30 16:24:06 +00:00
} catch ( error ) {
console . log ( 'aaaaaaaaaaaaaaaaaaaaaaaaaaaa' ) ;
return handleErrorResponse ( MODULE _NAME , 'getInscriptionsOfNextEventsCount' , error , res )
}
} ,
2019-07-28 20:08:15 +00:00
getInscription : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const inscriptionId = params . params . id ;
const userId = req . user . id ;
try {
let inscription = await eventInscriptionService . _getInscriptionById ( inscriptionId ) ;
if ( ! inscription ) {
return handleResultResponse ( "Inscripción no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
} else if ( inscription . userId !== userId ) {
return handleResultResponse ( "Inscripción no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
}
inscription = await inscription . toJSON ( ) ;
const qrConfig = {
name : req . user . name ,
surname : req . user . surname ,
2019-08-30 17:47:28 +00:00
inscription : inscription . date ,
2019-07-28 20:08:15 +00:00
code : inscription . code _ticket ,
color : ( inscription . level && inscription . level . color ) ? inscription . level . color : null ,
}
inscription . code _ticket _qr = await QRHelper . getInscriptionQRCode ( qrConfig ) ;
return handleResultResponse ( inscription , null , params , res , httpStatus . OK ) ;
} catch ( error ) {
return handleResultResponse ( "Error al buscar la inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
}
} ,
2019-08-14 17:49:38 +00:00
findPartners : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
try {
const result = await eventReservationService . _getPartners ( params . params . id ) ;
2019-08-14 20:50:04 +00:00
return handleResultResponse ( result , result . count , params , res , httpStatus . OK ) ;
2019-08-20 19:13:30 +00:00
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'findPartners' , error , res )
}
} ,
findColleges : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
try {
const result = await eventReservationService . _getColleges ( params . params . id ) ;
return handleResultResponse ( result , result . count , params , res , httpStatus . OK ) ;
2019-08-14 17:49:38 +00:00
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'findPartners' , error , res )
}
} ,
2019-09-12 09:54:00 +00:00
validateInscription : async ( req , res , next ) => {
2019-09-12 10:04:42 +00:00
console . log ( '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><< validateInscription' ) ;
2019-09-12 09:54:00 +00:00
const params = extractParamsFromRequest ( req , res , { } ) ;
const user = req . user ;
2019-09-12 10:04:42 +00:00
console . log ( '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1validar inscription:' , params ) ;
2019-09-12 09:54:00 +00:00
console . log ( 'usuario:' , user ) ;
try {
const inscription = await eventInscriptionService . _getInscriptionById ( inscriptionId ) ;
console . log ( '>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion a borrar:' ) ;
console . log ( inscription ) ;
/ * i f ( ! i n s c r i p t i o n | | ( i n s c r i p t i o n . u s e r I d ! = = u s e r . i d ) )
return handleResultResponse ( "Inscription no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
//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 ;
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 ;
}
//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 ) ;
}
//Eliminamos miembro de la lista de mailchimp a la que está asociado
await eventInscriptionService . _deleteMember ( marketingListId , inscription . marketing _memberId ) ;
/ * M a n d a r c o r r e o d e c o n f i r m a c i o n d e d e s i n s c r i p c i o n
var headerMail = {
to : user . email ,
name : user . name + ' ' + user . surname ,
subject : ( ( member . validated ) ? 'Entrada' : 'Lista de espera' ) + ' para el congreso ' + dataInscription . 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' ) ,
}
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' ) ;
} ;
* /
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);
} catch ( error ) {
return handleResultResponse ( "Error al validar inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
}
} ,
2019-07-25 16:39:18 +00:00
deleteInscription : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const user = req . user ;
const inscriptionId = params . params . id ;
2019-07-28 20:08:15 +00:00
try {
2019-07-25 16:39:18 +00:00
const inscription = await eventInscriptionService . _getInscriptionById ( inscriptionId ) ;
console . log ( '>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion a borrar:' ) ;
console . log ( inscription ) ;
2019-07-29 17:17:28 +00:00
if ( ! inscription || ( inscription . userId !== user . id ) )
2019-07-25 16:39:18 +00:00
return handleResultResponse ( "Inscription no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
//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 ;
2019-08-30 10:03:56 +00:00
let marketingListId = null ;
2019-09-11 13:56:27 +00:00
2019-09-11 14:10:21 +00:00
if ( inscription . reservationId != null ) {
2019-09-11 13:56:27 +00:00
console . log ( 'Tengo reservation>>>>>>>>>>>>>>>>>>' , inscription . reservationId ) ;
2019-07-25 16:39:18 +00:00
NewConfirmed = await eventInscriptionService . _getCountInscriptionsWithReservation ( EventOrReservationChangeId )
2019-08-30 10:03:56 +00:00
marketingListId = ( await eventReservationService . _getReservaById ( EventOrReservationChangeId ) ) . marketing _list ;
}
2019-09-11 14:10:21 +00:00
else if ( inscription . overflowEventId != null ) {
2019-09-11 13:56:27 +00:00
console . log ( 'Tengo overflow>>>>>>>>>>>>>>>>>>' , inscription . overflowEventId ) ;
2019-08-30 10:03:56 +00:00
NewConfirmed = await eventInscriptionService . _getCountInscriptionsWithOverflowEventId ( EventOrReservationChangeId ) ;
marketingListId = ( await eventService . _getEvent ( EventOrReservationChangeId ) ) . marketing _list ;
}
2019-09-11 14:10:21 +00:00
else if ( inscription . eventId != null ) {
2019-07-25 16:39:18 +00:00
NewConfirmed = await eventInscriptionService . _getCountInscriptionsWithoutReservationAndOverflow ( EventOrReservationChangeId ) ;
2019-08-30 10:03:56 +00:00
marketingListId = ( await eventService . _getEvent ( EventOrReservationChangeId ) ) . marketing _list ;
}
2019-07-25 16:39:18 +00:00
//Actualizamos aforo del evento o de la reserva
2019-09-11 14:13:51 +00:00
if ( inscription . reservationId != null ) {
2019-09-11 14:23:52 +00:00
console . log ( '>>>>>>>>>>>>>>Voy a actualizar aforo reserva' , EventOrReservationChangeId ) ;
2019-09-11 13:56:27 +00:00
console . log ( '>>>>>>>>>>>>>> ' , NewConfirmed ) ;
2019-07-25 16:39:18 +00:00
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 {
2019-09-11 14:23:52 +00:00
console . log ( '>>>>>>>>>>>>>>Voy a actualizar aforo evento' , EventOrReservationChangeId ) ;
2019-09-11 13:56:27 +00:00
console . log ( '>>>>>>>>>>>>>> ' , NewConfirmed ) ;
2019-07-25 16:39:18 +00:00
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 ) ;
}
2019-08-30 10:03:56 +00:00
//Eliminamos miembro de la lista de mailchimp a la que está asociado
await eventInscriptionService . _deleteMember ( marketingListId , inscription . marketing _memberId ) ;
2019-09-12 09:54:00 +00:00
/ * M a n d a r c o r r e o d e c o n f i r m a c i o n d e d e s i n s c r i p c i o n
var headerMail = {
to : user . email ,
name : user . name + ' ' + user . surname ,
subject : ( ( member . validated ) ? 'Entrada' : 'Lista de espera' ) + ' para el congreso ' + dataInscription . 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' ) ,
}
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' ) ;
} ;
* /
2019-07-25 16:39:18 +00:00
return handleResultResponse ( "Inscripción eliminada" , null , params , res , httpStatus . DELETEOK ) ;
}
else
return handleResultResponse ( "No se pudo eliminar inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
} catch ( error ) {
return handleResultResponse ( "Error al eliminar inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
}
2019-07-19 19:36:20 +00:00
2019-07-25 16:39:18 +00:00
} ,
//Esta función se puede llamar desde APP y desde WEB
2019-07-12 09:48:04 +00:00
createInscription : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
2019-09-02 11:16:45 +00:00
console . log ( 'CREATE INSCRIPTION>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< ' , params ) ;
2019-07-23 13:15:41 +00:00
//Iniciamos entidades relacionadas con la inscripción.
2019-07-20 16:11:43 +00:00
let dataUser = {
2019-07-23 13:15:41 +00:00
id : ( req . user ) ? req . user . id : null ,
2019-09-10 15:23:28 +00:00
phone : ( req . user ) ? req . user . phone : ( ( req . body . phone != '+34' ) ? req . body . phone : null ) ,
2019-07-23 13:15:41 +00:00
name : ( req . user ) ? req . user . name : req . body . name ,
surname : ( req . user ) ? req . user . surname : req . body . surname ,
email : ( req . user ) ? req . user . email : req . body . email ,
2019-07-23 13:37:08 +00:00
entityId : null ,
2019-07-23 13:15:41 +00:00
userResult : ( req . user ) ? req . user : null ,
2019-07-20 16:11:43 +00:00
}
2019-07-19 17:39:19 +00:00
2019-07-20 16:11:43 +00:00
let dataInscription = {
2019-07-20 19:23:05 +00:00
eventId : params . params . id ,
2019-07-23 13:15:41 +00:00
reservationCode : ( req . user ) ? req . body . code : Buffer . from ( req . body . code , 'base64' ) . toString ( 'ascii' ) ,
type : ( req . body . code ) ? 'reservation' : 'regular' ,
2019-07-25 16:39:18 +00:00
source : ( req . user ) ? 'app' : 'web' , //En el caso de tener ya usuario viene por APP sino viene por web
2019-07-21 13:30:49 +00:00
validated : null , //si no esta validado la inscripción es a la lista de espera
2019-07-20 19:23:05 +00:00
inscriptionsWithoutReservationCount : null , //nº total de inscritos sin reserva asignada
inscriptionsWithReservationCount : null , //nº total de inscritos a la reserva asignada
2019-07-23 13:15:41 +00:00
event : null ,
reservation : null ,
inscription : null ,
2019-07-19 17:39:19 +00:00
}
2019-07-25 16:39:18 +00:00
2019-07-23 13:43:42 +00:00
console . log ( 'DATAUSER_INICIAL>>>>>>>>>>>>>>>>>>>>' ) ;
console . log ( dataUser ) ;
console . log ( 'DATAINSCRIPTION_INICIAL>>>>>>>>>>>>>>>>>>' ) ;
console . log ( dataInscription ) ;
2019-07-19 17:39:19 +00:00
2019-07-20 19:23:05 +00:00
//SI VIENE CODIGO DE RESERVA, RECUPERAMOS LA RESERVA Y EL EVENTO
if ( dataInscription . reservationCode ) {
2019-07-19 19:36:20 +00:00
try {
2019-07-20 19:23:05 +00:00
dataInscription . reservation = await eventReservationService . _getReservaByCode ( dataInscription . eventId , dataInscription . reservationCode ) ;
2019-07-20 16:11:43 +00:00
if ( dataInscription . reservation ) {
dataInscription . reservation = await dataInscription . reservation . toJSON ( ) ;
dataInscription . event = dataInscription . reservation . Event ;
2019-07-19 19:36:20 +00:00
} else {
// No se ha encontrado
return handleResultResponse ( "Código de reserva no encontrado" , null , params , res , httpStatus . NOT _FOUND ) ;
}
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'createInscription' , error , res )
}
2019-07-19 17:39:19 +00:00
}
2019-07-20 19:23:05 +00:00
//SOLO RECUPERAMOS EL EVENTO
2019-07-19 17:39:19 +00:00
else {
2019-07-19 19:36:20 +00:00
try {
2019-07-20 16:11:43 +00:00
dataInscription . event = await eventService . _getEvent ( dataInscription . eventId ) ;
if ( dataInscription . event ) {
dataInscription . event = await dataInscription . event . toJSON ( ) ;
2019-07-19 19:36:20 +00:00
} else {
// No se ha encontrado
return handleResultResponse ( "Evento no encontrado" , null , params , res , httpStatus . NOT _FOUND ) ;
}
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'createInscription' , error , res )
}
2019-07-19 17:39:19 +00:00
}
2019-07-23 13:37:08 +00:00
console . log ( '>>>>>>>>>>>>>>>>>>>>>>>esta es la reserva y el evento al que quiere inscribirse' ) ;
2019-07-20 16:11:43 +00:00
console . log ( dataInscription . reservation ) ;
2019-07-23 13:37:08 +00:00
console . log ( dataInscription . event ) ;
//Asignamos a los datos del usuario a crear, el id de la entidad a la que pertenece, este caso solo es necesario cuando viene la inscripción por web ya que hay que crear un usuario nuevo
if ( dataInscription . reservation )
dataUser . entityId = dataInscription . reservation . entityId ;
2019-07-19 19:36:20 +00:00
2019-07-20 16:11:43 +00:00
//creamos o recuperamos el usuario teniendo en cuenta que pude venir por APP o WEB
//si viene por web se tendra en cuenta el email y si viene por APP el phone para buscar
2019-07-19 19:36:20 +00:00
try {
2019-09-10 15:07:22 +00:00
//CHAPUZA PARA PODER DAR DE ALTA USUARIOS CON EL MISMO CORREO ELECTRONICO, PERO DISTINTO NOMBRE Y APELLIDO.
if ( req . user ) //? 'app' : 'web', //En el caso de tener ya usuario viene por APP sino viene por web
dataUser . userResult = await userService . _getOrCreateUser ( dataUser )
else
dataUser . userResult = await userService . _getOrCreateUserWEB ( dataUser ) ;
2019-07-20 16:11:43 +00:00
if ( ! dataUser . userResult ) {
// No se ha encontrado
return handleResultResponse ( "No se ha podido crear o encontrar el usuario dado" , null , params , res , httpStatus . NOT _FOUND ) ;
} ;
2019-07-19 19:36:20 +00:00
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'createInscription' , error , res ) ;
}
2019-07-20 16:11:43 +00:00
console . log ( '>>>>>>>>>>>>>>>>>>>>>>este es el usuario que quiere inscribirse' ) ;
console . log ( dataUser . userResult ) ;
2019-07-19 19:36:20 +00:00
2019-07-19 17:39:19 +00:00
2019-07-20 16:11:43 +00:00
try {
//Comprobamos que el usuario no tenga ya inscripcion para ese evento
2019-07-25 16:39:18 +00:00
dataInscription . inscription = await eventInscriptionService . _getInscriptionByEventAndUser ( dataInscription . event . id , dataUser . userResult . user . id ) ;
2019-07-20 16:11:43 +00:00
if ( dataInscription . inscription ) {
2019-07-25 16:39:18 +00:00
console . log ( 'esta es la inscripcion que ya tengo>>>>>>>>>>>>>>>>>>>>><' ) ;
console . log ( dataInscription . inscription ) ;
//Devuelvo la reserva que ya tiene hecha el usuario
if ( ( ! dataInscription . inscription . reservationId ) || ( dataInscription . inscription . reservationId == dataInscription . reservation . id ) )
return handleResultResponse ( dataInscription . inscription , null , params , res , httpStatus . OK ) ;
//ACTUALIZAMOS LA RESERVA DE LA INSCRIPCION CON LA NUEVA Y CAMBIAMOS COMFIRMADOS DEVOLVIENDO LA INSCRIPCIÓN CON LA NUEVA RESERVA
let CountConfirmedOldReservation = await eventInscriptionService . _getCountInscriptionsWithReservation ( dataInscription . inscription . reservationId ) ;
-- CountConfirmedOldReservation ;
console . log ( 'actualizo confirmados de la reserva anterior' ) ;
await eventReservationService . _updateConfirmedReservation ( dataInscription . inscription . reservationId , CountConfirmedOldReservation ) ;
let CountConfirmedNewReservation = await eventInscriptionService . _getCountInscriptionsWithReservation ( dataInscription . reservation . id ) ;
++ CountConfirmedNewReservation ;
console . log ( 'actualizo confirmados de la nueva reserva' ) ;
await eventReservationService . _updateConfirmedReservation ( dataInscription . reservation . id , CountConfirmedNewReservation ) ;
await eventInscriptionService . _updateReservationOfInscription ( dataInscription . inscription . id , dataInscription . reservation . id ) ;
dataInscription . inscription = await eventInscriptionService . _getInscriptionById ( dataInscription . inscription . id ) ;
return handleResultResponse ( dataInscription . inscription , null , params , res , httpStatus . OK ) ;
}
2019-07-20 19:23:05 +00:00
//TENEMOS QUE CREAR INSCRIPCIÓN
2019-07-20 16:11:43 +00:00
else {
2019-07-20 19:23:05 +00:00
//CON CODIGO DE RESERVA SE MODIFICA EL CONFIRMED DE LA RESERVA, YA QUE SE DESCONTARA DEL AFORO DE LA RESERVA
if ( dataInscription . reservation ) {
dataInscription . inscriptionsWithReservationCount = await eventInscriptionService . _getCountInscriptionsWithReservation ( dataInscription . reservation . id ) ;
++ dataInscription . inscriptionsWithReservationCount ;
2019-07-25 16:39:18 +00:00
console . log ( 'me inscribo por reserva>>>>>>>>>>>>>>>>>>>>>>>>>>><< con asistentes: ' , dataInscription . reservation . assistants ) ;
console . log ( dataInscription . reservation . sold _out ) ;
console . log ( dataInscription . inscriptionsWithReservationCount ) ;
2019-07-21 13:30:49 +00:00
//COMPROBAMOS SI ES VALIDO O HAY QUE APUNTARLE A LA LISTA DE ESPERA DE LA RESERVA
2019-07-25 16:39:18 +00:00
if ( ( dataInscription . reservation . sold _out == 0 ) && ( dataInscription . reservation . assistants >= dataInscription . inscriptionsWithReservationCount ) ) {
2019-07-21 13:30:49 +00:00
dataInscription . validated = true ;
//Actualizamos aforo de la lista de espera de la reserva y creamos inscripcion en la lista de espera de la reserva
2019-07-25 16:39:18 +00:00
if ( await eventReservationService . _updateConfirmedReservation ( dataInscription . reservation . id , dataInscription . inscriptionsWithReservationCount ) )
2019-07-21 13:30:49 +00:00
dataInscription . inscription = await eventInscriptionService . _createInscription ( dataInscription . event . id ,
dataUser . userResult . user . id ,
dataInscription . type ,
dataInscription . validated ,
2019-07-25 16:39:18 +00:00
dataInscription . source ,
dataInscription . reservation . id ,
2019-07-21 13:30:49 +00:00
null )
else
return handleResultResponse ( "No se ha podido actualizar el aforo de la reserva" , null , params , res , httpStatus . NOT _FOUND ) ;
2019-07-25 16:39:18 +00:00
2019-09-10 18:44:00 +00:00
//Ponemos la reserva en SOLD_OUT para que no se pueda apuntar nadie más
if ( dataInscription . reservation . assistants == dataInscription . inscriptionsWithReservationCount )
await eventReservationService . _updateSoldOutReservation ( dataInscription . reservation . id , true ) ;
}
// APUNTARSE A LISTA DE ESPERA SI SE PUEDE
2019-07-21 13:30:49 +00:00
else {
if ( dataInscription . reservation . allow _overflow === true ) {
dataInscription . validated = false ;
2019-07-25 16:39:18 +00:00
dataInscription . inscriptionsWithReservationCount = await eventInscriptionService . _getCountInscriptionsWithReservation ( dataInscription . reservation . overflow _reservationId ) ;
2019-07-21 13:30:49 +00:00
++ dataInscription . inscriptionsWithReservationCount ;
// if (dataInscription.reservation.assistants >= dataInscription.inscriptionsWithReservationCount) {
//Actualizamos aforo de la reserva y creamos inscripcion
2019-07-25 16:39:18 +00:00
if ( await eventReservationService . _updateConfirmedReservation ( dataInscription . reservation . overflow _reservationId , dataInscription . inscriptionsWithReservationCount ) )
2019-07-21 13:30:49 +00:00
dataInscription . inscription = await eventInscriptionService . _createInscription ( dataInscription . event . id ,
dataUser . userResult . user . id ,
dataInscription . type ,
dataInscription . validated ,
2019-07-25 16:39:18 +00:00
dataInscription . source ,
dataInscription . reservation . overflow _reservationId ,
2019-07-21 13:30:49 +00:00
null )
else
return handleResultResponse ( "No se ha podido actualizar el aforo de la reserva" , null , params , res , httpStatus . NOT _FOUND ) ;
}
else
return handleResultResponse ( "Aforo completo de la reserva y no hay lista de espera" , null , params , res , httpStatus . NOT _FOUND ) ;
}
}
//SIN CODIGO DE RESERVA SE MODIFICA EL CONFIRMED DEL EVENTO, YA QUE SE DESCONTARA DEL AFORO DEL EVENTO
2019-07-20 19:23:05 +00:00
else {
2019-07-25 16:39:18 +00:00
dataInscription . inscriptionsWithoutReservationCount = await eventInscriptionService . _getCountInscriptionsWithoutReservationAndOverflow ( dataInscription . event . id ) ;
2019-07-20 19:23:05 +00:00
++ dataInscription . inscriptionsWithoutReservationCount ;
2019-07-21 13:30:49 +00:00
//COMPROBAMOS SI ES VALIDO O HAY QUE APUNTARLE A LA LISTA DE ESPERA DEL EVENTO
2019-07-25 16:39:18 +00:00
if ( ( dataInscription . event . sold _out == 0 ) && ( dataInscription . event . assistants >= dataInscription . inscriptionsWithoutReservationCount ) ) {
2019-07-21 13:30:49 +00:00
dataInscription . validated = true ;
//Actualizamos aforo del evento y creamos inscripcion
if ( await eventService . _updateConfirmedEvent ( dataInscription . event . id , dataInscription . inscriptionsWithoutReservationCount ) )
dataInscription . inscription = await eventInscriptionService . _createInscription ( dataInscription . event . id ,
dataUser . userResult . user . id ,
dataInscription . type ,
dataInscription . validated ,
2019-07-25 16:39:18 +00:00
dataInscription . source ,
2019-07-21 13:30:49 +00:00
null ,
null )
else
return handleResultResponse ( "No se ha podido actualizar el aforo del evento" , null , params , res , httpStatus . NOT _FOUND ) ;
2019-09-10 18:44:00 +00:00
//Ponemos el evento en SOLD_OUT
if ( dataInscription . event . assistants == dataInscription . inscriptionsWithoutReservationCount )
await eventService . _updateSoldOutEvent ( dataInscription . event . id , true ) ;
2019-07-21 13:30:49 +00:00
}
2019-09-10 18:44:00 +00:00
// APUNTARSE A la lista de espera si se puede
2019-07-21 13:30:49 +00:00
else {
if ( dataInscription . event . allow _overflow === true ) {
dataInscription . validated = false ;
//Actualizamos aforo de la lista de espera del evento y creamos inscripcion
2019-09-11 11:01:16 +00:00
console . log ( 'evento de lista de espera que debo actulizar sus confirmados>>>>>>>>>>>>>>>>>>>>>' , dataInscription . event . overflow _eventId ) ;
2019-09-11 11:11:47 +00:00
//recuperamos la cantidad de apuntados al evento overflow a lista de espera
2019-09-11 11:01:16 +00:00
const ConfirmedWaitList = await eventInscriptionService . _getCountInscriptionsWithOverflowEventId ( dataInscription . event . overflow _eventId ) ;
2019-09-11 11:11:47 +00:00
console . log ( 'cantidad apuntados al evento padre>>>>>>>>>>>>>>>>>>>>>' , dataInscription . inscriptionsWithoutReservationCount ) ;
console . log ( 'cantidad apuntados al evento de lista de espera asociado>>>>>>>>>>>>>>>>>>>>>' , ConfirmedWaitList ) ;
2019-09-11 11:01:16 +00:00
2019-09-11 11:07:32 +00:00
2019-09-11 11:01:16 +00:00
2019-09-11 11:11:47 +00:00
if ( await eventService . _updateConfirmedEvent ( dataInscription . event . overflow _eventId , ConfirmedWaitList ) ) {
//console.log('voy a crearrrrrr la inscripcion');
2019-07-25 16:39:18 +00:00
dataInscription . inscription = await eventInscriptionService . _createInscription ( dataInscription . event . id ,
2019-07-21 13:30:49 +00:00
dataUser . userResult . user . id ,
dataInscription . type ,
dataInscription . validated ,
2019-07-25 16:39:18 +00:00
dataInscription . source ,
2019-07-21 13:30:49 +00:00
null ,
2019-09-02 15:04:11 +00:00
dataInscription . event . overflow _eventId ) ;
}
2019-09-02 16:00:34 +00:00
else {
console . log ( 'No se ha podido actualizar el aforo del evento' ) ;
2019-07-21 13:30:49 +00:00
return handleResultResponse ( "No se ha podido actualizar el aforo del evento" , null , params , res , httpStatus . NOT _FOUND ) ;
2019-09-02 16:00:34 +00:00
}
2019-07-21 13:30:49 +00:00
}
else
return handleResultResponse ( "Aforo completo y no hay lista de espera" , null , params , res , httpStatus . NOT _FOUND ) ;
}
2019-07-20 19:23:05 +00:00
}
2019-07-20 16:11:43 +00:00
}
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'createInscription' , error , res ) ;
}
2019-07-19 17:39:19 +00:00
2019-07-29 12:59:01 +00:00
const marketingListOfInscription = dataInscription . event . marketing _list ;
2019-08-13 18:00:27 +00:00
/ * A H O R A S E A L M A C E N A T O D O E N U N A Ú N I C A L I S T A D E M A I L C H I M P , Q U E E S L A D E L E V E N T O
( si en un futuro se quiere tener listas independientes , bastaría con tratarlo aqui los campos de marketinglist de la reserva ... )
2019-07-29 12:59:01 +00:00
if ( dataInscription . inscription . reservationId )
marketingListOfInscription = dataInscription . reservation . marketingList
else if ( dataInscription . inscription . overflowEventId )
marketingListOfInscription = ( await _getEvent ( dataInscription . inscription . overflowEventId ) ) . marketingList ;
else
marketingListOfInscription = dataInscription . event . marketingList ;
* /
2019-09-11 13:56:27 +00:00
2019-08-29 18:08:22 +00:00
//Creamos objeto member para facilitar inserción en mailchimp y envio de correo
var member = {
marketing _memberId : null ,
email : dataUser . userResult . user . email ,
name : dataUser . userResult . user . name ,
surname : dataUser . userResult . user . surname ,
source : dataInscription . inscription . source ,
reservation _code : ( dataInscription . reservation ) ? dataInscription . reservation . reservation _code : null ,
date : dataInscription . inscription . date ,
code _ticket : dataInscription . inscription . code _ticket ,
validated : dataInscription . inscription . validated ,
color : ( dataInscription . reservation ) ? dataInscription . reservation . color : null ,
description : ( ( dataInscription . reservation ) ? dataInscription . reservation . description : 'Entrada Normal' ) . toUpperCase ( ) ,
entity : ( dataInscription . reservation ) ? dataInscription . reservation . Entity . name : dataUser . userResult . user . entityId ,
userId : dataUser . userResult . user . id
}
console . log ( 'member a añadir a mailchimp y envio correo' ) ;
console . log ( member ) ;
2019-09-02 15:22:12 +00:00
try
{
member . marketing _memberId = await eventInscriptionService . _addMember ( marketingListOfInscription , member ) ;
eventInscriptionService . _updateMarketingMemberOfInscription ( dataInscription . inscription . id , member . marketing _memberId ) ;
} catch ( error ) {
console . log ( 'No se ha podido añadir email a mailchimp' ) ;
} ;
2019-07-29 12:59:01 +00:00
2019-08-29 18:08:22 +00:00
//MADAMOS MAIL CON LA ENTRADA
const qrConfig = {
name : member . name ,
surname : member . surname ,
date : member . date ,
code : member . code _ticket ,
color : member . color ,
}
const qrCode = await QRHelper . getInscriptionQRCode ( qrConfig ) ;
var headerMail = {
2019-08-13 18:00:27 +00:00
to : member . email ,
name : member . name + ' ' + member . surname ,
2019-08-29 18:08:22 +00:00
subject : ( ( member . validated ) ? 'Entrada' : 'Lista de espera' ) + ' para el congreso ' + dataInscription . 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' ) ,
2019-07-22 09:50:30 +00:00
}
2019-09-02 15:22:12 +00:00
2019-08-30 16:17:04 +00:00
console . log ( 'Mandamos mail con entrada>>>>>>>>>>>>>>>>>>>>>>>>>>>' ) ;
console . log ( headerMail , bodyMail ) ;
2019-09-02 15:22:12 +00:00
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' ) ;
} ;
2019-08-13 18:00:27 +00:00
return handleResultResponse ( await dataInscription . inscription . toJSON ( ) , null , params , res , httpStatus . CREATED )
2019-07-28 20:08:15 +00:00
} ,
getQRCodeInscription : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const inscriptionId = params . params . id ;
const userId = req . user . id ;
try {
const inscription = await eventInscriptionService . _getInscriptionById ( inscriptionId ) ;
if ( ! inscription ) {
return handleResultResponse ( "Inscription no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
} else if ( inscription . userId !== userId ) {
return handleResultResponse ( "Inscription no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
}
const qrConfig = {
name : req . user . name ,
surname : req . user . surname ,
2019-08-30 17:47:28 +00:00
date : inscription . date ,
2019-07-28 20:08:15 +00:00
code : inscription . code _ticket ,
color : ( inscription . level && inscription . level . color ) ? inscription . level . color : null ,
}
const qrCode = await QRHelper . getInscriptionQRCode ( qrConfig ) ;
return handleResultResponse ( qrCode , null , params , res , httpStatus . OK ) ;
} catch ( error ) {
return handleResultResponse ( "Error al buscar la inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
}
2019-08-30 17:47:28 +00:00
} ,
2019-08-31 10:38:13 +00:00
validateInscription : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
var eventId = params . params . id ;
var email = params . params . email ;
try {
const user = await userService . _getUserByEmail ( email ) ;
if ( user ) {
const result = await eventInscriptionService . _getInscriptionByEventAndUser ( eventId , user . id )
if ( result )
return handleResultResponse ( result . stateText , null , params , res , httpStatus . OK ) ;
}
return handleResultResponse ( "No hay inscripción con ese email" , null , params , res , httpStatus . NOT _FOUND ) ;
} catch ( error ) {
return handleErrorResponse ( MODULE _NAME , 'validateInscription' , error , res )
}
} ,
2019-08-30 17:47:28 +00:00
sendMailTicket : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const inscriptionId = params . params . id ;
2019-08-31 11:47:15 +00:00
const user = req . user ;
2019-08-30 17:47:28 +00:00
try {
const inscription = await eventInscriptionService . _getInscriptionById ( inscriptionId ) ;
2019-08-31 11:47:15 +00:00
if ( ! inscription )
return handleResultResponse ( "Inscription no encontrada" , null , params , res , httpStatus . NOT _FOUND ) ;
// if (inscription.userId !== user.id)
2019-08-30 17:56:28 +00:00
// return handleResultResponse("Inscription no encontrada", null, params, res, httpStatus.NOT_FOUND);
2019-07-22 09:50:30 +00:00
2019-08-31 11:47:15 +00:00
const userInscription = await userService . _getUserById ( inscription . userId ) ;
console . log ( inscription ) ;
2019-08-30 17:47:28 +00:00
const qrConfig = {
2019-08-31 11:47:15 +00:00
name : userInscription . name ,
surname : userInscription . surname ,
2019-08-30 17:47:28 +00:00
date : inscription . date ,
code : inscription . code _ticket ,
2019-08-30 17:56:28 +00:00
color : ( inscription . reservation ) ? inscription . reservation . color : null ,
2019-08-30 17:47:28 +00:00
}
const qrCode = await QRHelper . getInscriptionQRCode ( qrConfig ) ;
2019-08-30 17:56:28 +00:00
var headerMail = {
2019-08-31 11:47:15 +00:00
to : userInscription . email ,
name : userInscription . name + ' ' + userInscription . surname ,
subject : ( ( inscription . validated ) ? 'Entrada' : 'Lista de espera' ) + ' para el congreso ' + inscription . event . name + ' confirmada'
2019-08-30 17:56:28 +00:00
}
2019-08-31 11:47:15 +00:00
2019-08-30 17:56:28 +00:00
var bodyMail = {
2019-08-31 11:47:15 +00:00
tipoEntrada : ( inscription . validated ) ? 'Entrada' : 'Lista de espera' ,
descriptionEntrada : ( inscription . reservation ) ? inscription . reservation . description : 'Entrada Normal' ,
2019-08-30 17:56:28 +00:00
qrCode : qrCode ,
color : qrConfig . color ,
2019-08-31 11:47:15 +00:00
codeTicket : inscription . code _ticket ,
eventName : inscription . event . name ,
dateInscription : moment ( inscription . event . init _date ) . format ( 'D [de] MMMM [de] YYYY' ) ,
2019-08-30 17:56:28 +00:00
}
console . log ( 'Mandamos mail con entrada>>>>>>>>>>>>>>>>>>>>>>>>>>>' ) ;
console . log ( headerMail , bodyMail ) ;
2019-08-31 11:47:15 +00:00
if ( inscription . validated )
2019-08-30 17:56:28 +00:00
emailHelper . sendTicket ( headerMail , bodyMail )
else
emailHelper . sendListaEspera ( headerMail , bodyMail ) ;
2019-08-30 17:47:28 +00:00
return handleResultResponse ( null , null , params , res , httpStatus . OK ) ;
} catch ( error ) {
return handleResultResponse ( "Error al buscar la inscripción" , null , params , res , httpStatus . NOT _FOUND ) ;
}
2019-07-14 16:44:59 +00:00
} ,
2019-08-19 17:54:39 +00:00
getReservationsExcel : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
2019-08-20 15:37:53 +00:00
const eventId = params . params . id ;
2019-08-21 15:41:05 +00:00
const type = params . params . type ;
2019-08-19 17:54:39 +00:00
const userId = req . user . id ;
2019-08-21 15:41:05 +00:00
const reservations = await eventReservationService . _getReservationsExcel ( req . user , eventId , null , type , function ( result , status ) {
2019-08-19 17:54:39 +00:00
if ( result . messenger . code == "S99001" ) {
console . log ( result ) ;
res . setHeader ( 'Content-Type' , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) ;
res . setHeader ( 'Content-Disposition' , 'attachment; filename=' + result . data . name ) ;
res . attachment ( result . data . name ) ;
res . download ( path . resolve ( result . data . path ) , result . data . name ) ;
} else {
res . status ( status ) . json ( result ) ;
}
} )
2019-08-20 16:39:05 +00:00
} ,
getInscripcionsExcel : async ( req , res , next ) => {
const params = extractParamsFromRequest ( req , res , { } ) ;
const eventId = params . params . id ;
const userId = req . user . id ;
const inscriptions = await eventInscriptionService . _getInscriptionsExcel ( req . user , eventId , function ( result , status ) {
if ( result . messenger . code == "S99001" ) {
console . log ( result ) ;
res . setHeader ( 'Content-Type' , 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' ) ;
res . setHeader ( 'Content-Disposition' , 'attachment; filename=' + result . data . name ) ;
res . attachment ( result . data . name ) ;
res . download ( path . resolve ( result . data . path ) , result . data . name ) ;
} else {
res . status ( status ) . json ( result ) ;
}
} )
} ,
2019-07-09 15:37:56 +00:00
} ;
2019-07-09 08:51:00 +00:00
module . exports = generateControllers ( eventService , extraControllers , controllerOptions ) ;