/* global Venue */ 'use strict'; const _ = require('lodash'); const moment = require('moment'); const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper'); const models = require('../../core/models'); function generateNewCodeTicket() { this.length = 8; this.timestamp = +new Date; var _getRandomInt = function (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; } this.generate = function () { var ts = this.timestamp.toString(); var parts = ts.split("").reverse(); var id = ""; for (var i = 0; i < this.length; ++i) { var index = _getRandomInt(0, parts.length - 1); id += parts[index]; } return id; } } const extraMethods = { _getInscriptionById: (Id) => { return models.EventInscription.findOne({ where: { id: Id, }, }) }, _getInscriptionByEventAndUser: (eventId, userId) => { return models.EventInscription.scope('includeEventAndVenue').findOne({ where: { eventId: eventId, userId: userId }, }) }, _getInscriptionsUser: (userId) => { return models.EventInscription.scope('includeEventAndVenue').findAll({ attributes: { exclude: ['marketing_memberId', 'overflowEventId', 'createdAt', 'updatedAt', 'userId', 'eventId', 'validateUserId'] }, where: { 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('>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>< { //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);