104 lines
3.2 KiB
JavaScript
104 lines
3.2 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 = {
|
|
|
|
_getInscriptionById: (Id) => {
|
|
return models.EventInscription.findOne({
|
|
where: {
|
|
id: Id,
|
|
},
|
|
})
|
|
},
|
|
|
|
_getInscriptionByEventAndUser: (eventId, userId) => {
|
|
return models.EventInscription.findOne({
|
|
where: {
|
|
eventId: eventId,
|
|
userId: userId
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número de inscripciones confirmadas para ese evento sin tener en cuenta reservas
|
|
_getCountInscriptionsWithoutReservationAndOverflow: (eventId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
eventId: eventId,
|
|
reservationId: null,
|
|
overflowEventId: null
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número de inscripciones realizadas con esa reserva
|
|
_getCountInscriptionsWithReservation: (reservationId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
reservationId: reservationId,
|
|
},
|
|
})
|
|
},
|
|
|
|
//Nos devuelve el número de inscripciones realizadas con esa reserva
|
|
_getCountInscriptionsWithOverflowEventId: (overflowEventId) => {
|
|
return models.EventInscription.count({
|
|
where: {
|
|
overflowEventId: overflowEventId,
|
|
},
|
|
})
|
|
},
|
|
|
|
_updateReservationOfInscription: (id, reservationId) => {
|
|
return models.EventInscription.update ({
|
|
reservationId: reservationId,
|
|
},
|
|
{
|
|
where: { id: id }
|
|
});
|
|
},
|
|
|
|
_createInscription: (eventId, userId, type, validated, source, reservationId, overflowEventId) => {
|
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<valores de la inscripcion');
|
|
console.log(eventId, userId, 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: ('ENT-' + (Date.now() + Math.random()).toString()),
|
|
source: source,
|
|
validated: validated,
|
|
reservationId: reservationId,
|
|
overflowEventId: overflowEventId,
|
|
})
|
|
.then(function (result) {
|
|
resolve(result);
|
|
})
|
|
.catch(function (error) {
|
|
reject(error)
|
|
});
|
|
});
|
|
},
|
|
|
|
_deleteInscription: (id) => {
|
|
|
|
//habria que poner el idusuario para asegurar que otro usuario no borra una inscripcion de otro
|
|
|
|
return models.EventInscription.destroy({
|
|
where: {
|
|
id: id,
|
|
}
|
|
});
|
|
},
|
|
|
|
};
|
|
|
|
module.exports = generateService(models.EventInscription, extraMethods); |