2019-07-09 08:51:00 +00:00
|
|
|
/* global Venue */
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
const _ = require('lodash');
|
2019-07-09 15:59:17 +00:00
|
|
|
const moment = require('moment');
|
2019-07-09 08:51:00 +00:00
|
|
|
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
2019-07-09 16:56:22 +00:00
|
|
|
const Sequelize = require('sequelize');
|
2019-07-09 08:51:00 +00:00
|
|
|
const models = require('../../core/models');
|
2019-07-29 15:10:23 +00:00
|
|
|
const { citiesComposer, eventComposer } = require('../../helpers/composes.helper');
|
2019-07-18 18:13:07 +00:00
|
|
|
|
2019-07-09 15:37:56 +00:00
|
|
|
const extraMethods = {
|
2019-07-25 17:06:12 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
afterFetchAll: (result, params, context) => {
|
2019-07-25 17:06:12 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
if (!result.count) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rows = result.rows.map(row => row.toJSON());
|
2019-08-28 10:43:41 +00:00
|
|
|
|
2019-07-29 15:10:23 +00:00
|
|
|
if (context.scopes.includes('CitiesOfEvents'))
|
|
|
|
|
rows = rows.map(city => citiesComposer(city, context))
|
|
|
|
|
else
|
|
|
|
|
rows = rows.map(event => eventComposer(event, context));
|
2019-08-28 10:43:41 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
return {
|
2019-08-26 15:42:52 +00:00
|
|
|
count: result.count,
|
2019-07-17 12:07:35 +00:00
|
|
|
rows: rows
|
|
|
|
|
}
|
2019-07-29 15:10:23 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
},
|
|
|
|
|
|
2019-07-18 18:13:07 +00:00
|
|
|
afterFetchOne: (result, params, context) => {
|
2019-07-22 17:34:45 +00:00
|
|
|
if (result)
|
|
|
|
|
result = result.toJSON();
|
|
|
|
|
return eventComposer(result, context);
|
2019-07-14 16:44:59 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
2019-07-19 19:36:20 +00:00
|
|
|
_getEvent: (eventId) => {
|
|
|
|
|
return models.Event.findOne({
|
|
|
|
|
where: {
|
2019-09-11 14:19:22 +00:00
|
|
|
id: eventId,
|
|
|
|
|
typeId: { [Sequelize.Op.ne]: null }
|
2019-07-19 19:36:20 +00:00
|
|
|
}
|
2019-07-14 16:44:59 +00:00
|
|
|
});
|
2019-07-19 17:39:19 +00:00
|
|
|
},
|
2019-07-14 16:44:59 +00:00
|
|
|
|
2019-07-20 19:23:05 +00:00
|
|
|
_updateConfirmedEvent: (eventId, confirmed) => {
|
2019-07-19 17:39:19 +00:00
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
models.Event.update(
|
|
|
|
|
{
|
2019-07-25 16:39:18 +00:00
|
|
|
confirmed: confirmed,
|
2019-07-19 17:39:19 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-09-02 16:00:34 +00:00
|
|
|
where: { id: eventId, typeId: { [Sequelize.Op.ne]: null} }
|
2019-07-19 17:39:19 +00:00
|
|
|
})
|
|
|
|
|
.then(function (result) {
|
2019-09-02 15:37:00 +00:00
|
|
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>><resultado _updateConfirmedEvent', result);
|
2019-09-02 15:33:40 +00:00
|
|
|
if (result)
|
|
|
|
|
resolve((result[0] === 1))
|
|
|
|
|
else
|
|
|
|
|
resolve(false);
|
2019-07-19 17:39:19 +00:00
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
reject(error)
|
|
|
|
|
});
|
2019-07-14 16:44:59 +00:00
|
|
|
});
|
|
|
|
|
},
|
2019-07-19 17:39:19 +00:00
|
|
|
|
2019-07-25 16:39:18 +00:00
|
|
|
_updateSoldOutEvent: (eventId, sold_out) => {
|
|
|
|
|
return new Promise(function (resolve, reject) {
|
|
|
|
|
models.Event.update(
|
|
|
|
|
{
|
|
|
|
|
sold_out: sold_out,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
where: { id: eventId }
|
|
|
|
|
})
|
|
|
|
|
.then(function (result) {
|
2019-09-02 15:38:49 +00:00
|
|
|
console.log('>>>>>>>>>>>>>>>>>>>>>>>>><resultado _updateSoldOutEvent', result);
|
2019-09-02 15:33:40 +00:00
|
|
|
if (result)
|
|
|
|
|
resolve((result[0] === 1))
|
|
|
|
|
else
|
|
|
|
|
resolve(false);
|
2019-07-25 16:39:18 +00:00
|
|
|
})
|
|
|
|
|
.catch(function (error) {
|
|
|
|
|
reject(error)
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
2019-07-09 15:37:56 +00:00
|
|
|
};
|
2019-07-09 08:51:00 +00:00
|
|
|
|
|
|
|
|
module.exports = generateService(models.Event, extraMethods);
|