a
This commit is contained in:
parent
78473f9604
commit
c91d9461e1
48
helpers/mail.helper.js
Normal file
48
helpers/mail.helper.js
Normal file
@ -0,0 +1,48 @@
|
||||
const mailjet_public = "c9cbd50d7f4afe487e56949f95cb28a0";
|
||||
const mailjet_private = "f8b77ee8e7b1181d94f07905d90e18c6";
|
||||
const mailjet_from_email = "info@loquedeverdadimporta.org";
|
||||
const mailjet_from_name = "Fundación Lo Que De Verdad Importa";
|
||||
|
||||
/**
|
||||
* Enviar un email
|
||||
* @param {number} data.to - Email destino
|
||||
* @param {number} data.name - Nombre del contacto destino
|
||||
* @param {number} data.subject - Asunto
|
||||
* @param {number} data.text - Cuerpo del mensaje en texto plano
|
||||
* @param {number} data.html - Cuerpo del mensaje en HTML
|
||||
* @return {Promise}
|
||||
*
|
||||
*/
|
||||
function send(data) {
|
||||
const mailjet = require('node-mailjet')
|
||||
.connect(mailjet_public, mailjet_private)
|
||||
const request = mailjet
|
||||
.post("send", { 'version': 'v3.1' })
|
||||
.request({
|
||||
"Messages": [{
|
||||
"From": {
|
||||
"Email": mailjet_from_email,
|
||||
"Name": mailjet_from_name
|
||||
},
|
||||
"To": [{
|
||||
"Email": data.to,
|
||||
"Name": data.name
|
||||
}],
|
||||
"Subject": data.subject,
|
||||
"TextPart": data.text,
|
||||
"HTMLPart": data.html
|
||||
}]
|
||||
})
|
||||
|
||||
request
|
||||
.then((result) => {
|
||||
console.log(result.body)
|
||||
return result;
|
||||
})
|
||||
.catch((error) => {
|
||||
console.log(error.statusCode)
|
||||
return error;
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.send = send;
|
||||
@ -44,18 +44,19 @@ function getMembers(listId) {
|
||||
})
|
||||
});
|
||||
}
|
||||
*/
|
||||
|
||||
function getMember(listId, data) {
|
||||
function getMember(listId, member) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
logger.debug('getMember => ', '/search-members', listId, ' email: ' + data.email);
|
||||
console.log('getMember => ', '/search-members', listId, ' email: ' + member.EMAIL);
|
||||
mailchimp.get('/search-members', {
|
||||
list_id: listId,
|
||||
query: data.email,
|
||||
query: member.EMAIL,
|
||||
fields: ['email_address'],
|
||||
})
|
||||
.then(function (results) {
|
||||
if (results && results.exact_matches && (results.exact_matches.total_items == 1)) {
|
||||
logger.debug('getMember => ', results.exact_matches.members[0].id);
|
||||
console.log('getMember => ', results.exact_matches.members[0].id);
|
||||
resolve(results.exact_matches.members[0]);
|
||||
}
|
||||
else reject();
|
||||
@ -64,41 +65,46 @@ function getMember(listId, data) {
|
||||
reject(error)
|
||||
})
|
||||
});
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
function addMember(listId, member) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
// logger.debug('addMember => ', '/lists/' + listId + '/members', ' email: ' + member.email);
|
||||
console.log('addMember => ', '/lists/' + listId + '/members', ' email: ' + member.email);
|
||||
|
||||
|
||||
var member2 = {
|
||||
var memberMailchimp = {
|
||||
EMAIL: member.email,
|
||||
FNAME: member.name,
|
||||
LNAME: member.surname,
|
||||
SOURCE: member.source,
|
||||
RESERCODE: member.reservation_code,
|
||||
TICKETCODE: member.code_ticket,
|
||||
VALIDATED: member.validated,
|
||||
VALIDATED: (member.validated)? 1 : 0,
|
||||
COLOR: member.color,
|
||||
DESCOLOR: member.description,
|
||||
ENTITYNAME: member.entityId,
|
||||
ENTITYNAME: member.entity,
|
||||
USERID: member.userId
|
||||
}
|
||||
|
||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr3');
|
||||
console.log(listId, memberMailchimp);
|
||||
|
||||
|
||||
mailchimp.post('/lists/' + listId + '/members', {
|
||||
email_address: member2.EMAIL,
|
||||
merge_fields: member2,
|
||||
email_address: memberMailchimp.EMAIL,
|
||||
merge_fields: memberMailchimp,
|
||||
status: 'subscribed'
|
||||
})
|
||||
.then(function (results) {
|
||||
console.log('addMember => ', member.EMAIL, results.id, results.statusCode);
|
||||
resolve(results);
|
||||
console.log('addMember => ', memberMailchimp.EMAIL, results.id, results.statusCode);
|
||||
memberMailchimp.ID = results.id;
|
||||
resolve(memberMailchimp);
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.log('addMember => ', error.title, error.status);
|
||||
if ((error.status == 400) && (error.title == 'Member Exists')) {
|
||||
resolve(getMember(listId, member));
|
||||
resolve(getMember(listId, memberMailchimp));
|
||||
} else {
|
||||
reject(error);
|
||||
}
|
||||
|
||||
25
helpers/messages.json
Normal file
25
helpers/messages.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"emails": {
|
||||
"confirmInvitation": {
|
||||
"subject": "Tu invitación al congreso {{congreso}} está confirmada.",
|
||||
"body": {
|
||||
"text": "¡Gracias por inscribirte al congreso {{congreso}}!\n\nTienes una plaza confirmada para asistir a este evento. Por favor, si no vas a poder asistir cancela tu reserva para que otra persona pueda asistir.\n\nDos días antes de la fecha del congreso recibirás otro email con tu entrada, la cual deberás presentar en el stand de invitados ubicado en el hall para acceder al mismo.\n\nFundación Lo Que De Verdad Importa.\n",
|
||||
"html": "<p>¡Gracias por inscribirte al congreso {{congreso}}!</p><p>Tienes una plaza confirmada para asistir a este evento. Por favor, si no vas a poder asistir cancela tu reserva para que otra persona pueda asistir.</p><p>Dos días antes de la fecha del congreso recibirás otro email con tu entrada, la cual deberás presentar en el stand de invitados ubicado en el hall para acceder al mismo.</p><p>Fundación Lo Que De Verdad Importa.</p>"
|
||||
}
|
||||
},
|
||||
"confirmInvitationToWaitingList": {
|
||||
"subject": "Tu invitación al congreso {{congreso}} está en lista de espera.",
|
||||
"body": {
|
||||
"text": "¡Gracias por inscribirte al congreso {{congreso}}!\n\nTu invitación está en lista de espera. Si finalmente quedaran plazas disponibles te lo comunicaremos via email.\n\nFundación Lo Que De Verdad Importa.\n",
|
||||
"html": "<p>¡Gracias por inscribirte al congreso {{congreso}}!</p><p>Tu invitación está en lista de espera. Si finalmente quedaran plazas disponibles te lo comunicaremos via email.</p><p>Fundación Lo Que De Verdad Importa.</p>"
|
||||
}
|
||||
},
|
||||
"recoverPassword": {
|
||||
"subject": "Tu nueva clave para LQDVI",
|
||||
"body": {
|
||||
"text": "Hola!, \n\n Solicitaste cambiar la contraseña, hemos creado una nueva.\n\n Entra en la app con tu dirección de email y esta clave: {{password}}\n\nFundación Lo Que De Verdad Importa.",
|
||||
"html": "¡Hola!, <br/><br/>Solicitaste cambiar la contraseña, hemos creado una nueva.<br/><br/>Entra en la app con tu dirección de email y esta clave: <b>{{password}}</b><br/><br/>Fundación Lo Que De Verdad Importa."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -17,9 +17,10 @@ const extraMethods = {
|
||||
} else {
|
||||
await models.User.findOrCreate({
|
||||
where: {
|
||||
phone: dataUser.phone,
|
||||
phone: (dataUser.phone)? dataUser.phone : null, //puede que al venir la solicitud por web no venga el phone
|
||||
email: dataUser.email,
|
||||
},
|
||||
include: [{ model: models.Entity }],
|
||||
defaults: {
|
||||
phone: dataUser.phone,
|
||||
email: dataUser.email,
|
||||
|
||||
@ -2,6 +2,8 @@
|
||||
const httpStatus = require('http-status');
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const QRHelper = require('../../helpers/qr.helper');
|
||||
const emailHelper = require('../../helpers/mail.helper');
|
||||
const messages = require('../../helpers/messages.json');
|
||||
const eventService = require('./event.service');
|
||||
const eventReservationService = require('./events_reservations.service');
|
||||
const eventInscriptionService = require('./events_inscriptions.service');
|
||||
@ -381,7 +383,8 @@ console.log('actualizo confirmados de la nueva reserva');
|
||||
|
||||
|
||||
const marketingListOfInscription = dataInscription.event.marketing_list;
|
||||
/*
|
||||
/*AHORA SE ALMACENA TODO EN UNA ÚNICA LISTA DE MAILCHIMP, QUE ES LA DEL EVENTO
|
||||
(si en un futuro se quiere tener listas independientes, bastaría con tratarlo aqui los campos de marketinglist de la reserva ...)
|
||||
if (dataInscription.inscription.reservationId)
|
||||
marketingListOfInscription = dataInscription.reservation.marketingList
|
||||
else if (dataInscription.inscription.overflowEventId)
|
||||
@ -389,37 +392,33 @@ console.log('actualizo confirmados de la nueva reserva');
|
||||
else
|
||||
marketingListOfInscription = dataInscription.event.marketingList;
|
||||
*/
|
||||
eventInscriptionService._addMember(marketingListOfInscription, dataUser.userResult.user, dataInscription.inscription, dataInscription.reservation)
|
||||
return handleResultResponse(await dataInscription.inscription.toJSON(), null, params, res, httpStatus.CREATED)
|
||||
|
||||
const member = await eventInscriptionService._addMember(marketingListOfInscription, dataUser.userResult.user, dataInscription.inscription, dataInscription.reservation);
|
||||
eventInscriptionService._updateMarketingMemberOfInscription(dataInscription.inscription.id, member.marketing_memberId);
|
||||
|
||||
|
||||
/*
|
||||
if (invitationCode) {
|
||||
_getLevelAndPartner()
|
||||
.then(_getOrCreateUser)
|
||||
.then(_existsInscription)
|
||||
.then(_getInscriptionCount)
|
||||
.then(_updateLevel)
|
||||
.then(_createInscription) --------------------> HASTA AQUI
|
||||
.then(_addMember)
|
||||
.then(_updateInscription)
|
||||
.then(_getConference)
|
||||
.then(_sendConfirmMail)
|
||||
.then(_handleResponse)
|
||||
.catch(_handleError);
|
||||
} else {
|
||||
_existsInscription()
|
||||
.then(_getInscriptionCount)
|
||||
.then(_getConference)
|
||||
.then(_updateConference)
|
||||
.then(_createInscription) -----------------------> HASTA AQUI
|
||||
.then(_addMember)
|
||||
.then(_updateInscription)
|
||||
.then(_handleResponse)
|
||||
.catch(_handleError);
|
||||
var mailOptions = {
|
||||
to: member.email,
|
||||
name: member.name + ' ' + member.surname,
|
||||
}
|
||||
*/
|
||||
|
||||
if (dataInscription.inscription.validated) {
|
||||
mailOptions = Object.assign(mailOptions, {
|
||||
subject: messages.emails.confirmInvitation.subject.concat(dataInscription.event.name),
|
||||
text: messages.emails.confirmInvitation.body.text.concat(dataInscription.event.name),
|
||||
html: messages.emails.confirmInvitation.body.html.concat(dataInscription.event.name),
|
||||
});
|
||||
} else {
|
||||
mailOptions = Object.assign(mailOptions, {
|
||||
subject: messages.emails.confirmInvitationToWaitingList.subject.concat(dataInscription.event.name),
|
||||
text: messages.emails.confirmInvitationToWaitingList.body.text.concat(dataInscription.event.name),
|
||||
html: messages.emails.confirmInvitationToWaitingList.body.html.concat(dataInscription.event.name),
|
||||
});
|
||||
};
|
||||
|
||||
console.log('maaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaail');
|
||||
console.log(mailOptions);
|
||||
emailHelper.send(mailOptions);
|
||||
return handleResultResponse(await dataInscription.inscription.toJSON(), null, params, res, httpStatus.CREATED)
|
||||
},
|
||||
|
||||
getQRCodeInscription: async (req, res, next) => {
|
||||
|
||||
@ -235,7 +235,7 @@ routes.get('/web/events',
|
||||
|
||||
// Hacer una inscripción por la web
|
||||
routes.post('/web/events/:id/inscriptions',
|
||||
//SchemaValidator(eventValidation.webInscriptionInputType, true),
|
||||
SchemaValidator(eventValidation.webInscriptionInputType, true),
|
||||
eventController.createInscription
|
||||
);
|
||||
|
||||
|
||||
@ -6,7 +6,7 @@ const InscriptionInputType = Joi.object().keys({
|
||||
});
|
||||
|
||||
const webInscriptionInputType = Joi.object().keys({
|
||||
id: Joi.string().required(),
|
||||
// id: Joi.string().required(),
|
||||
code: Joi.string().required(),
|
||||
email: Joi.string().email({ minDomainSegments: 2 }).required(),
|
||||
name: Joi.string().required(),
|
||||
@ -24,6 +24,6 @@ const EventsListOutputType = Joi.object().keys({
|
||||
*/
|
||||
|
||||
module.exports = {
|
||||
// VenueInputType,
|
||||
webInscriptionInputType,
|
||||
InscriptionInputType
|
||||
};
|
||||
|
||||
@ -112,6 +112,15 @@ const extraMethods = {
|
||||
});
|
||||
},
|
||||
|
||||
_updateMarketingMemberOfInscription: (id, marketingMemberId) => {
|
||||
return models.EventInscription.update({
|
||||
marketing_memberId: marketingMemberId,
|
||||
},
|
||||
{
|
||||
where: { id: id }
|
||||
});
|
||||
},
|
||||
|
||||
_createInscription: (eventId, userId, type, validated, source, reservationId, overflowEventId) => {
|
||||
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<valores de la inscripcion');
|
||||
console.log(eventId, userId, type, validated, source, reservationId, overflowEventId);
|
||||
@ -151,10 +160,10 @@ const extraMethods = {
|
||||
_addMember: (marketingListId, user, inscription, reservation) => {
|
||||
|
||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr1');
|
||||
console.log(user);
|
||||
|
||||
console.log(user, reservation);
|
||||
|
||||
var member = {
|
||||
marketing_memberId: null,
|
||||
email: user.email,
|
||||
name: user.name,
|
||||
surname: user.surname,
|
||||
@ -164,27 +173,24 @@ const extraMethods = {
|
||||
validated: inscription.validated,
|
||||
color: (reservation) ? reservation.color : 'white',
|
||||
description: (reservation) ? reservation.description : 'entrada libre',
|
||||
entityId: (reservation) ? reservation.entityId : user.entityId,
|
||||
entity: (reservation) ? reservation.Entity.name : user.entityId,
|
||||
userId: user.id
|
||||
}
|
||||
|
||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr1');
|
||||
console.log(marketingListId, member.validated);
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (!marketingListId || !member.validated) {
|
||||
if (!marketingListId) { // || !member.validated) {
|
||||
resolve(member)
|
||||
} else {
|
||||
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasddddddmemberrrrr2');
|
||||
marketing.addMember(marketingListId, member)
|
||||
.then(function (result) {
|
||||
member = result;
|
||||
member.marketing_memberId = result.ID;
|
||||
resolve(member);
|
||||
})
|
||||
.catch(function (error) {
|
||||
reject(error)
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
@ -12,7 +12,7 @@ const extraMethods = {
|
||||
where: { reservation_code: code, eventId: eventId },
|
||||
include: [{
|
||||
model: models.Event,
|
||||
}],
|
||||
}, {model: models.Entity}],
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@ -48,6 +48,7 @@
|
||||
"mysql": "^2.17.1",
|
||||
"mysql2": "^1.6.5",
|
||||
"node-fetch": "^2.3.0",
|
||||
"node-mailjet": "^3.3.1",
|
||||
"os": "^0.1.1",
|
||||
"passport": "^0.4.0",
|
||||
"passport-custom": "^1.0.5",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user