2019-07-19 17:39:19 +00:00
|
|
|
/* global Events Reservations */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2019-08-14 17:49:38 +00:00
|
|
|
const Sequelize = require('sequelize');
|
2019-07-19 17:39:19 +00:00
|
|
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
|
|
|
|
const models = require('../../core/models');
|
|
|
|
|
|
|
|
|
|
const extraMethods = {
|
|
|
|
|
|
2019-07-19 19:36:20 +00:00
|
|
|
_getReservaByCode: (eventId, code) => {
|
|
|
|
|
return models.EventReservation.findOne({
|
|
|
|
|
where: { reservation_code: code, eventId: eventId },
|
|
|
|
|
include: [{
|
|
|
|
|
model: models.Event,
|
2019-08-13 18:00:27 +00:00
|
|
|
}, {model: models.Entity}],
|
2019-07-19 17:39:19 +00:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2019-08-14 17:49:38 +00:00
|
|
|
_getPartners: (eventId) => {
|
2019-08-15 12:33:21 +00:00
|
|
|
return models.EventReservation.findAll({
|
|
|
|
|
// attributes: [ [Sequelize.fn('DISTINCT', Sequelize.col('events_reservations.entityId'), Sequelize.col('events_reservations.eventId')), 'entities']],
|
2019-08-15 18:09:50 +00:00
|
|
|
// attributes: ['entityId','eventId', 'state'],
|
2019-08-14 17:49:38 +00:00
|
|
|
where: { eventId: eventId },
|
|
|
|
|
include: [{ model: models.Entity }],
|
2019-08-15 18:09:50 +00:00
|
|
|
order: [[{ model: models.Entity }, 'name', 'asc']],
|
|
|
|
|
|
|
|
|
|
|
2019-08-14 17:49:38 +00:00
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
2019-07-25 16:39:18 +00:00
|
|
|
_updateConfirmedReservation: (id, confirmed) => {
|
2019-07-20 19:23:05 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
models.EventReservation.update(
|
|
|
|
|
{
|
|
|
|
|
confirmed: confirmed,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
where: { id: id }
|
|
|
|
|
})
|
|
|
|
|
.then(function (result) {
|
|
|
|
|
resolve((result[0] === 1));
|
|
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
reject(error)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
2019-07-19 17:39:19 +00:00
|
|
|
|
2019-07-25 16:39:18 +00:00
|
|
|
_updateSoldOutReservation: (id, sold_out) => {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
models.EventReservation.update(
|
|
|
|
|
{
|
|
|
|
|
sold_out: sold_out,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
where: { id: id }
|
|
|
|
|
})
|
|
|
|
|
.then(function (result) {
|
|
|
|
|
resolve((result[0] === 1));
|
|
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
reject(error)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2019-07-19 17:39:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = generateService(models.EventReservation, extraMethods);
|