app2-api/modules/events/events_inscriptions.service.js

76 lines
2.4 KiB
JavaScript
Raw Normal View History

2019-07-19 17:39:19 +00:00
/* global Venue */
'use strict';
const _ = require('lodash');
2019-07-21 13:30:49 +00:00
const moment = require('moment');
2019-07-19 17:39:19 +00:00
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');
const extraMethods = {
2019-07-20 16:11:43 +00:00
_getInscription: (eventId, userId) => {
return models.EventInscription.findOne({
where: {
eventId: eventId,
userId: userId
},
2019-07-19 17:39:19 +00:00
})
},
2019-07-20 19:23:05 +00:00
//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,
},
})
},
2019-07-19 17:39:19 +00:00
2019-07-20 19:23:05 +00:00
//Nos devuelve el número de inscripciones realizadas para ese evento
_getCountInscriptionsWithoutReservation: (eventId) => {
return models.EventInscription.count({
2019-07-19 17:39:19 +00:00
where: {
2019-07-20 19:23:05 +00:00
eventId: eventId,
reservationId : null,
2019-07-19 17:39:19 +00:00
},
2019-07-20 19:23:05 +00:00
})
},
//Nos devuelve el número de inscripciones realizadas con esa reserva
_getCountInscriptionsWithReservation: (reservationId) => {
return models.EventInscription.count({
where: {
reservationId: reservationId,
},
2019-07-19 17:39:19 +00:00
})
},
2019-07-21 13:30:49 +00:00
_createInscription: (eventId, userId, ticket, type, validated, source, reservationId, overflowEventId) => {
2019-07-20 19:23:05 +00:00
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<valores de la inscripcion');
2019-07-21 13:30:49 +00:00
console.log(eventId, userId, ticket, type, validated, source, reservationId, overflowEventId);
2019-07-19 17:39:19 +00:00
return new Promise(function (resolve, reject) {
2019-07-20 16:11:43 +00:00
models.EventInscription.create({
eventId: eventId,
2019-07-21 13:30:49 +00:00
date: moment().utc(),
2019-07-20 16:11:43 +00:00
userId: userId,
type: type,
2019-07-21 13:30:49 +00:00
code_ticket: ticket,
2019-07-20 16:11:43 +00:00
source: source,
2019-07-21 13:30:49 +00:00
validated: validated,
2019-07-20 19:23:05 +00:00
reservationId: reservationId,
2019-07-21 13:30:49 +00:00
overflowEventId: overflowEventId,
2019-07-19 17:39:19 +00:00
})
.then(function (result) {
2019-07-20 19:23:05 +00:00
resolve(result);
2019-07-19 17:39:19 +00:00
})
.catch(function (error) {
reject(error)
});
});
},
};
module.exports = generateService(models.EventInscription, extraMethods);