71 lines
2.1 KiB
JavaScript
71 lines
2.1 KiB
JavaScript
/* global Venue */
|
|
'use strict';
|
|
|
|
const _ = require('lodash');
|
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
|
const models = require('../../core/models');
|
|
|
|
const extraMethods = {
|
|
|
|
_existsInscription: (params, context) => {
|
|
|
|
return new Promise (function (resolve, reject) {
|
|
models.EventInscription.count({
|
|
where: params,
|
|
|
|
}).then(function (count) {
|
|
if (count > 0) {
|
|
reject({ message: 'Ya existe una inscripción para ese email' })
|
|
} else {
|
|
resolve(true);
|
|
}
|
|
}).catch(function (error) {
|
|
reject(error)
|
|
});
|
|
})
|
|
},
|
|
|
|
_getInscriptionCount: (params, context) => {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
models.Inscription.count({
|
|
where: {
|
|
eventId: context.eventId,
|
|
reservationId: (context.code) ? context.reservation.id : null,
|
|
},
|
|
})
|
|
.then(function (count) {
|
|
context.inscriptionCount = count;
|
|
resolve(count);
|
|
}).catch(function (error) {
|
|
reject(error)
|
|
});
|
|
})
|
|
},
|
|
|
|
_createInscription: (params, context) => {
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
database.models.Inscription.create({
|
|
eventId: context.eventId,
|
|
type: context.type,
|
|
source: 'web',
|
|
userId: context.user.id,
|
|
//valid: !(tickets > assistants),
|
|
reservationId: (context.code) ? context.reservation.id : null
|
|
})
|
|
.then(function (result) {
|
|
inscription = result.dataValues;
|
|
inscription.user = context.user;
|
|
resolve(inscription);
|
|
})
|
|
.catch(function (error) {
|
|
reject(error)
|
|
});
|
|
});
|
|
},
|
|
|
|
|
|
};
|
|
|
|
module.exports = generateService(models.EventInscription, extraMethods); |