57 lines
2.0 KiB
JavaScript
57 lines
2.0 KiB
JavaScript
'use strict';
|
|
|
|
const generateControllers = require('../../core/controllers');
|
|
const eventInscriptionService = require('./events_inscriptions.service');
|
|
|
|
const { extractParamsFromRequest } = require('../../helpers/controller.helper');
|
|
|
|
// Module Name
|
|
const MODULE_NAME = '[eventInscription.controller]';
|
|
|
|
const controllerOptions = { MODULE_NAME };
|
|
const extraControllers = {
|
|
|
|
prepareInscription: async (req, res, next) => {
|
|
console.log('>>>>>>>>>>>>>>>>>>>> prepareInscription');
|
|
const params = extractParamsFromRequest(req, res, {});
|
|
|
|
let typeInscription = 'presencial';
|
|
//online
|
|
if (req.body.type === 'online') {
|
|
if (req.body.code)
|
|
typeInscription = 'reservation online'
|
|
else if (req.body.group_size > 1)
|
|
typeInscription = 'reservation online'
|
|
else typeInscription = 'online'
|
|
|
|
}
|
|
//onsite
|
|
else {
|
|
if (req.body.code)
|
|
typeInscription = 'reservation presencial'
|
|
else if (req.body.group_size > 1)
|
|
typeInscription = 'reservation presencial'
|
|
};
|
|
|
|
let dataInscription = {
|
|
eventId: params.params.id,
|
|
reservationCode: (req.user) ? req.body.code : Buffer.from(req.body.code, 'base64').toString('ascii'),
|
|
type: typeInscription,
|
|
source: (req.user) ? 'app' : 'web', //En el caso de tener ya usuario viene por APP sino viene por web
|
|
validated: null, //si no esta validado la inscripción es a la lista de espera
|
|
inscriptionsWithoutReservationAndOverflowCount: null, //nº total de inscritos sin reserva y sin overflow asignada
|
|
inscriptionsWithReservationCount: null, //nº total de inscritos a la reserva asignada
|
|
event: null,
|
|
reservation: null,
|
|
inscription: null,
|
|
};
|
|
res.locals.dataInscription = dataInscription;
|
|
next();
|
|
},
|
|
|
|
|
|
};
|
|
|
|
module.exports = generateControllers(eventInscriptionService, extraControllers, controllerOptions);
|
|
|