a
This commit is contained in:
parent
c3b119545a
commit
2121540882
@ -88,7 +88,7 @@ function addMember(listId, member) {
|
|||||||
USERID: member.userId
|
USERID: member.userId
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr3');
|
console.log('addMember: En MailChimp');
|
||||||
console.log(listId, memberMailchimp);
|
console.log(listId, memberMailchimp);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -20,8 +20,80 @@ const userService = require('../auth/user.service');
|
|||||||
|
|
||||||
// Module Name
|
// Module Name
|
||||||
const MODULE_NAME = '[event.controller]';
|
const MODULE_NAME = '[event.controller]';
|
||||||
|
|
||||||
const controllerOptions = { MODULE_NAME };
|
const controllerOptions = { MODULE_NAME };
|
||||||
|
|
||||||
|
function generateMemberInscription (user, inscription, reservation) {
|
||||||
|
let memberInscription = null;
|
||||||
|
if (user && inscription) {
|
||||||
|
memberInscription = {
|
||||||
|
marketing_memberId: null,
|
||||||
|
email: user.email,
|
||||||
|
name: user.name,
|
||||||
|
surname: user.surname,
|
||||||
|
source: inscription.source,
|
||||||
|
eventName: (inscription.event) ? inscription.event.name : 'N/A',
|
||||||
|
reservation_code: (reservation) ? reservation.reservation_code : null,
|
||||||
|
date: inscription.date,
|
||||||
|
code_ticket: inscription.code_ticket,
|
||||||
|
validated: inscription.validated,
|
||||||
|
color: (reservation) ? reservation.color : null,
|
||||||
|
description: ((reservation) ? reservation.description : 'Entrada').toUpperCase(),
|
||||||
|
entity: (reservation) ? reservation.Entity.name : user.entityId,
|
||||||
|
userId: user.id,
|
||||||
|
qrConfig: null,
|
||||||
|
qrCode: null,
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return memberInscription;
|
||||||
|
};
|
||||||
|
|
||||||
|
function generateQRConfig (member) {
|
||||||
|
let qrConfig = null;
|
||||||
|
if (member) {
|
||||||
|
qrConfig = {
|
||||||
|
name: member.name,
|
||||||
|
surname: member.surname,
|
||||||
|
date: member.date,
|
||||||
|
code: member.code_ticket,
|
||||||
|
color: member.color,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return qrConfig;
|
||||||
|
};
|
||||||
|
|
||||||
|
function generateHeaderMail (member) {
|
||||||
|
let headerMail = null;
|
||||||
|
if (member) {
|
||||||
|
headerMail = {
|
||||||
|
to: member.email,
|
||||||
|
name: member.name + ' ' + member.surname,
|
||||||
|
subject: ((member.validated) ? 'Entrada' : 'Lista de espera') + ' para el congreso ' + member.eventName + ' confirmada'
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
return headerMail;
|
||||||
|
};
|
||||||
|
|
||||||
|
function generateBodyMail (member) {
|
||||||
|
let bodyMail = null;
|
||||||
|
if (member){
|
||||||
|
bodyMail = {
|
||||||
|
tipoEntrada: (member.validated) ? 'Entrada' : 'Lista de espera',
|
||||||
|
descriptionEntrada: member.description,
|
||||||
|
qrCode: member.qrCode,
|
||||||
|
color: member.qrConfig.color,
|
||||||
|
codeTicket: member.code_ticket,
|
||||||
|
eventName: member.eventName,
|
||||||
|
dateInscription: moment(member.date).format('D [de] MMMM [de] YYYY'),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return bodyMail;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
const extraControllers = {
|
const extraControllers = {
|
||||||
|
|
||||||
checkReservationCode: async (req, res, next) => {
|
checkReservationCode: async (req, res, next) => {
|
||||||
@ -174,8 +246,8 @@ console.log(inscription);
|
|||||||
// return handleResultResponse("Error al eliminar inscripción, no puedo cambiar confirmados a la reserva asociada", null, params, res, httpStatus.NOT_FOUND);
|
// 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
|
//Si la inscripcion es lista de espera del evento
|
||||||
else if (inscription.overflowEventId)
|
else if (inscription.overflowEventId) {
|
||||||
{
|
|
||||||
const OverflowEventId = inscription.overflowEventId;
|
const OverflowEventId = inscription.overflowEventId;
|
||||||
|
|
||||||
if (await eventInscriptionService._validateInscription(inscription.id, user.id) > 0) {
|
if (await eventInscriptionService._validateInscription(inscription.id, user.id) > 0) {
|
||||||
@ -185,59 +257,37 @@ console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>><Inscripcion validada');
|
|||||||
var marketingListIdOverflow = (await eventService._getEvent(OverflowEventId)).marketing_list;
|
var marketingListIdOverflow = (await eventService._getEvent(OverflowEventId)).marketing_list;
|
||||||
var marketingListIdEvent = (await eventService._getEvent(inscription.eventId)).marketing_list;
|
var marketingListIdEvent = (await eventService._getEvent(inscription.eventId)).marketing_list;
|
||||||
|
|
||||||
|
//Actualizamos aforos
|
||||||
if (!await eventService._updateConfirmedEvent(OverflowEventId, NewConfirmedOverflow))
|
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);
|
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))
|
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);
|
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(marketingListIdOverflow, inscription.marketing_memberId);
|
|
||||||
|
|
||||||
|
var member = generateMemberInscription(inscription.user, inscription, inscription.reservation);
|
||||||
|
console.log('generamos member>>>>>>>>>>>>>>>>>>>>> ', member);
|
||||||
|
//Eliminamos miembro de la lista de mailchimp a la que está asociado
|
||||||
|
await eventInscriptionService._deleteMember(marketingListIdOverflow, inscription.marketing_memberId);
|
||||||
|
member.marketing_memberId = await eventInscriptionService._addMember(marketingListIdEvent, member);
|
||||||
|
eventInscriptionService._updateMarketingMemberOfInscription(inscription.id, member.marketing_memberId);
|
||||||
|
|
||||||
const userInscription = inscription.user;
|
member.qrConfig = generateQRConfig(member);
|
||||||
|
member.qrCode = await QRHelper.getInscriptionQRCode(member.qrConfig);
|
||||||
|
|
||||||
|
|
||||||
//MADAMOS MAIL CON LA ENTRADA
|
|
||||||
const qrConfig = {
|
|
||||||
name: userInscription.name,
|
|
||||||
surname: userInscription.surname,
|
|
||||||
date: inscription.date,
|
|
||||||
code: inscription.code_ticket,
|
|
||||||
color: null,
|
|
||||||
}
|
|
||||||
const qrCode = await QRHelper.getInscriptionQRCode(qrConfig);
|
|
||||||
|
|
||||||
|
console.log('mandar correo>>>>>>>>>>>>>>>>>>>>> ', member);
|
||||||
//Mandar correo de confirmacion de desinscripcion
|
//Mandar correo de confirmacion de desinscripcion
|
||||||
var headerMail = {
|
try {
|
||||||
to: userInscription.email,
|
emailHelper.sendTicket(generateHeaderMail(member), generateBodyMail(member))
|
||||||
name: userInscription.name + ' ' + userInscription.surname,
|
} catch (error) {
|
||||||
subject: 'Entrada para el congreso ' + inscription.event.name + ' confirmada'
|
console.log('No se ha podido mandar email con entrada');
|
||||||
}
|
};
|
||||||
|
};
|
||||||
var bodyMail = {
|
|
||||||
tipoEntrada: 'Entrada',
|
|
||||||
description: 'ENTRADA',
|
|
||||||
qrCode: qrCode,
|
|
||||||
color: qrConfig.color,
|
|
||||||
codeTicket: inscription.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);
|
|
||||||
|
|
||||||
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);
|
return handleResultResponse("Inscripción validada", null, params, res, httpStatus.OK);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return handleResultResponse("No se pudo validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
return handleResultResponse("No se pudo validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return handleResultResponse("Error al validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
return handleResultResponse("Error al validar inscripción", null, params, res, httpStatus.NOT_FOUND);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user