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-18 18:13:07 +00:00
|
|
|
|
|
|
|
|
const multimediaComposer = (multimedias) => multimedias.map(multimedia => ({
|
|
|
|
|
...multimedia,
|
2019-07-18 16:39:07 +00:00
|
|
|
...multimedia.MultimediaFile,
|
|
|
|
|
type: multimedia.type,
|
|
|
|
|
media_type: multimedia.MultimediaFile.type,
|
|
|
|
|
MultimediaFile: undefined,
|
|
|
|
|
createdAt: undefined,
|
|
|
|
|
updatedAt: undefined,
|
|
|
|
|
userId: undefined,
|
|
|
|
|
}));
|
|
|
|
|
|
2019-07-18 18:13:07 +00:00
|
|
|
const speakerComposer = (speaker, context) => {
|
|
|
|
|
delete speaker.createdAt;
|
|
|
|
|
delete speaker.updatedAt;
|
|
|
|
|
return {...speaker,
|
|
|
|
|
multimedias: multimediaComposer(speaker.multimedias),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const eventComposer = (event, context) => {
|
|
|
|
|
|
|
|
|
|
if (context.scopes.includes('includeVenue')) {
|
|
|
|
|
delete event.venue.updatedAt;
|
|
|
|
|
delete event.venue.createdAt;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let multimedias = []
|
|
|
|
|
if (context.scopes.includes('includeMultimedias')) {
|
|
|
|
|
multimedias = multimediaComposer(event.multimedias)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
let speakers = []
|
|
|
|
|
if (context.scopes.includes('includeSpeakers')) {
|
|
|
|
|
speakers = event.details.map((detail) => ({
|
|
|
|
|
order: detail.order,
|
|
|
|
|
... speakerComposer(detail.speaker),
|
|
|
|
|
}))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return Object.assign({},
|
|
|
|
|
event,
|
|
|
|
|
{ multimedias: multimedias },
|
|
|
|
|
{ details: undefined },
|
|
|
|
|
{ speakers: speakers }
|
|
|
|
|
)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2019-07-09 15:37:56 +00:00
|
|
|
const extraMethods = {
|
2019-07-17 12:07:35 +00:00
|
|
|
afterFetchAll: (result, params, context) => {
|
2019-07-18 16:13:27 +00:00
|
|
|
|
2019-07-17 12:07:35 +00:00
|
|
|
if (!result.count) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let rows = result.rows.map(row => row.toJSON());
|
2019-07-18 18:13:07 +00:00
|
|
|
rows = rows.map(event => eventComposer(event, context));
|
2019-07-17 12:07:35 +00:00
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
count: rows.length,
|
|
|
|
|
rows: rows
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
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: {
|
|
|
|
|
id: eventId
|
|
|
|
|
}
|
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-20 19:23:05 +00:00
|
|
|
confirmed : confirmed,
|
2019-07-19 17:39:19 +00:00
|
|
|
},
|
|
|
|
|
{
|
2019-07-20 19:23:05 +00:00
|
|
|
where: { id: eventId }
|
2019-07-19 17:39:19 +00:00
|
|
|
})
|
|
|
|
|
.then(function (result) {
|
2019-07-20 19:23:05 +00:00
|
|
|
const aaa = result[0];
|
|
|
|
|
console.log('aaaaaaaaaaaaaaaaaaaaaaaaaaa');
|
|
|
|
|
console.log(aaa);
|
|
|
|
|
resolve((result[0] === 1));
|
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-09 15:37:56 +00:00
|
|
|
};
|
2019-07-09 08:51:00 +00:00
|
|
|
|
|
|
|
|
module.exports = generateService(models.Event, extraMethods);
|