76 lines
2.4 KiB
JavaScript
76 lines
2.4 KiB
JavaScript
/* global Venue */
|
|
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const moment = require('moment');
|
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
|
const models = require('../../core/models');
|
|
|
|
const extraMethods = {
|
|
|
|
_getInscription: (eventId, userId) => {
|
|
return models.EventInscription.findOne({
|
|
where: {
|
|
eventId: eventId,
|
|
userId: userId
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número total de inscripciones realizadas para ese evento (para el codigo de ticket-entrada)
|
|
_getCountInscriptionsEvent: (eventId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
eventId: eventId,
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número de inscripciones realizadas para ese evento
|
|
_getCountInscriptionsWithoutReservation: (eventId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
eventId: eventId,
|
|
reservationId : null,
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número de inscripciones realizadas con esa reserva
|
|
_getCountInscriptionsWithReservation: (reservationId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
reservationId: reservationId,
|
|
},
|
|
})
|
|
},
|
|
|
|
_createInscription: (eventId, userId, ticket, type, validated, source, reservationId, overflowEventId) => {
|
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<valores de la inscripcion');
|
|
console.log(eventId, userId, ticket, type, validated, source, reservationId, overflowEventId);
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
models.EventInscription.create({
|
|
eventId: eventId,
|
|
date: moment().utc(),
|
|
userId: userId,
|
|
type: type,
|
|
code_ticket: ticket,
|
|
source: source,
|
|
validated: validated,
|
|
reservationId: reservationId,
|
|
overflowEventId: overflowEventId,
|
|
})
|
|
.then(function (result) {
|
|
resolve(result);
|
|
})
|
|
.catch(function (error) {
|
|
reject(error)
|
|
});
|
|
});
|
|
},
|
|
|
|
|
|
};
|
|
|
|
module.exports = generateService(models.EventInscription, extraMethods); |