From b0b94b963be395e88b65336fcceab14e81d1950c Mon Sep 17 00:00:00 2001 From: david Date: Mon, 22 Jul 2019 11:50:30 +0200 Subject: [PATCH] a --- modules/events/event.controller.js | 48 ++++++++++++++++++++++++++++- modules/events/event.routes.js | 9 +++++- modules/events/event.validations.js | 21 +++++++------ 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/modules/events/event.controller.js b/modules/events/event.controller.js index b5a1cc8..4814162 100644 --- a/modules/events/event.controller.js +++ b/modules/events/event.controller.js @@ -55,6 +55,24 @@ const extraControllers = { console.log('usuariooooooooooooo--CASO CON TOKEN'); console.log(req.user); + + + var origin = (req.user && req.user.role == 90) ? 'admin' : 'web'; + + var user = { + id: null, + email: req.body.email, + name: req.body.name, + surname: req.body.surname + }; + + var invitationCode = Buffer.from(req.params.encodedInvitationCode, 'base64').toString('ascii'); + console.log(user, invitationCode); + + + + + let dataUser = { id: req.user.id, phone: req.user.phone, @@ -241,7 +259,35 @@ const extraControllers = { } - return handleResultResponse(await dataInscription.inscription.toJSON(), null, params, res, httpStatus.CREATED) + return handleResultResponse(await dataInscription.inscription.toJSON(), null, params, res, httpStatus.CREATED) + + /* + 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); + } +*/ + }, diff --git a/modules/events/event.routes.js b/modules/events/event.routes.js index acf06fb..77a0d2b 100644 --- a/modules/events/event.routes.js +++ b/modules/events/event.routes.js @@ -113,10 +113,17 @@ routes.get('/events/:id/inscriptions', // Hacer una inscripción routes.post('/events/:id/inscriptions', isLoggedUser, -// SchemaValidator(eventValidation.InscriptionInputType, true), + SchemaValidator(eventValidation.InscriptionInputType, true), eventController.createInscription ); +// Hacer una inscripción por la web +routes.post('/events/:id/webinscriptions', + SchemaValidator(eventValidation.webInscriptionInputType, true), + eventController.createInscription +); + + routes.delete('/events/:id/inscriptions', // Borrar una inscripción (poner el id de la inscripción????) isLoggedUser, diff --git a/modules/events/event.validations.js b/modules/events/event.validations.js index d605eea..0f77175 100644 --- a/modules/events/event.validations.js +++ b/modules/events/event.validations.js @@ -3,17 +3,18 @@ const Joi = require('joi'); const InscriptionInputType = Joi.object().keys({ id: Joi.string().required(), code: Joi.string().optional() - -/* address: Joi.string().required(), - city: Joi.string().required(), - gmt: Joi.number().min(-12).max(+12), - description: Joi.string().optional(), - country: Joi.string().optional(), - state: Joi.string().optional(), - postal_code: Joi.string().optional(), - accessibility: Joi.string().optional() -*/ }); + +const webInscriptionInputType = Joi.object().keys({ + id: Joi.string().required(), + code: Joi.string().required(), + email: Joi.string().email({ minDomainSegments: 2 }).required(), + name: Joi.string().required(), + surname: Joi.string().optional(), + phone: Joi.string().optional() +}); + + /* const EventsListOutputType = Joi.object().keys({ id: Joi.string().required(),