This commit is contained in:
David Arranz 2019-08-31 12:38:13 +02:00
parent 2f953e2838
commit a4b814747e
4 changed files with 44 additions and 1 deletions

View File

@ -34,7 +34,16 @@ const extraMethods = {
result = {user: user, isCreated: created}}); result = {user: user, isCreated: created}});
} }
return result; return result;
} },
_getUserByEmail: async (email) => {
return models.User.findOne({
where: {
email: email,
},
})
},
}; };

View File

@ -513,6 +513,26 @@ console.log(headerMail, bodyMail);
} }
}, },
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)
}
},
sendMailTicket: async (req, res, next) => { sendMailTicket: async (req, res, next) => {
const params = extractParamsFromRequest(req, res, {}); const params = extractParamsFromRequest(req, res, {});
const inscriptionId = params.params.id; const inscriptionId = params.params.id;

View File

@ -246,6 +246,11 @@ routes.post('/web/events/:id/inscriptions',
eventController.createInscription eventController.createInscription
); );
// Comprobar si estoy inscrito al congreso por la web
routes.get('/web/events/:id/inscriptions/:email',
eventController.validateInscription
);
/* /*
routes.get('/tickets/:id/', routes.get('/tickets/:id/',

View File

@ -105,5 +105,14 @@ module.exports = function (sequelize, DataTypes) {
} }
}); });
EventInscription.addScope('includeUser', () => {
return {
include: [{
model: sequelize.models.User,
as: 'user',
}],
}
});
return EventInscription; return EventInscription;
}; };