This commit is contained in:
David Arranz 2019-07-18 18:13:27 +02:00
parent 4f8e9bcaff
commit 024835ec58
12 changed files with 49 additions and 148 deletions

View File

@ -131,6 +131,11 @@ module.exports = function (sequelize, DataTypes) {
// },
// as: { singular: 'multimedia', plural: 'multimedias' }});
Event.Multimedias = Event.hasMany(models.Multimedia, {
foreignKey: 'entityId',
as: { singular: 'multimedia', plural: 'multimedias' }
});
Event.Reservations = Event.hasMany(models.EventReservation, { foreignKey: 'eventId', as: "reservations" });
Event.Inscriptions = Event.hasMany(models.EventInscription, { foreignKey: 'eventId', as: "inscriptions" });
Event.Questions = Event.hasMany(models.EventQuestion, { foreignKey: 'eventId', as: "questions" });
@ -152,6 +157,20 @@ module.exports = function (sequelize, DataTypes) {
}
});
Event.addScope('includeMultimedias', () => {
return {
include: [{
model: sequelize.models.Multimedia,
as: 'multimedias',
required: false,
include : [{
model: sequelize.models.MultimediaFile,
}]
},
]
}
});
Event.addScope('includeSpeakers', () => {
return {
include: [{
@ -164,9 +183,11 @@ module.exports = function (sequelize, DataTypes) {
include: [{
model: sequelize.models.Speaker,
as: 'speaker',
required: false,
include : [{
model: sequelize.models.Multimedia,
as: 'multimedias',
required: false,
include: [{
model: sequelize.models.MultimediaFile,
}]

View File

@ -37,11 +37,11 @@ routes.get('/events/next',
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "init_available_date" }),
eventController.find({
scopes: ['defaultScope', 'next', 'includeVenue', 'includeSpeakers'],
scopes: ['defaultScope', 'next', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
}),
);
routes.get('/events/past',
routes.get('/events/pass',
//isLoggedUser,
FieldMiddleware.middleware({
invalidFields: generalInvalidFields
@ -49,7 +49,7 @@ routes.get('/events/past',
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "-init_date" }),
eventController.find({
scopes: ['defaultScope', 'past', 'includeVenue', 'includeSpeakers'],
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeSpeakers'],
}),
);

View File

@ -9,8 +9,7 @@ const models = require('../../core/models');
const extraMethods = {
afterFetchAll: (result, params, context) => {
return result;
/*
if (!result.count) {
return result;
}
@ -21,7 +20,13 @@ const extraMethods = {
rows = rows.map(event => Object.assign({},
event,
{ details: undefined },
{ speakers: event.details.map(details => ({ ...details.speaker, order: details.order }) ) }
{ speakers: event.details.map((details) => {
const multimedias = details.speaker.multimedias.map((multimedias) => {
return {...multimedias, ...multimedias.MultimediaFile, MultimediaFile: undefined };
});
const data = { ...details.speaker, order: details.order, multimedias: multimedias };
return data;
} ) }
));
}
@ -29,7 +34,6 @@ const extraMethods = {
count: rows.length,
rows: rows
}
*/
},

View File

@ -13,9 +13,8 @@ module.exports = function (sequelize, DataTypes) {
description: {
type: DataTypes.STRING,
},
typeId: {
type: DataTypes.UUID,
foreignKey: true,
type: {
type: DataTypes.STRING,
},
provider: {
type: DataTypes.STRING,
@ -37,9 +36,7 @@ module.exports = function (sequelize, DataTypes) {
});
MultimediaFile.associate = function (models) {
MultimediaFile.MultimediaType = MultimediaFile.belongsTo(models.MultimediaType, { foreignKey: 'typeId' });
MultimediaFile.UserCreate = MultimediaFile.belongsTo(models.User, { foreignKey: 'userId' });
MultimediaFile.Multimedias = MultimediaFile.hasMany(models.Multimedia, { foreignKey: 'multimediafileId' });
};

View File

@ -1,14 +0,0 @@
'use strict';
const generateControllers = require('../../core/controllers');
const multimediaTypeService = require('./multimedia_types.service');
// Module Name
const MODULE_NAME = '[multimedia_types.controller]';
const controllerOptions = { MODULE_NAME };
const extraControllers = {};
module.exports = generateControllers(multimediaTypeService, extraControllers, controllerOptions);

View File

@ -1,27 +0,0 @@
'use strict';
module.exports = function (sequelize, DataTypes) {
const MultimediaType = sequelize.define('MultimediaType', {
id: {
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
primaryKey: true,
},
name: {
type: DataTypes.STRING,
},
description: {
type: DataTypes.STRING,
},
}, {
tableName: 'multimedia_types',
freezeTableName: true,
timestamps: true,
});
MultimediaType.associate = function (models) {
MultimediaType.MultimediasFiles = MultimediaType.hasMany(models.MultimediaFile, { foreignKey: 'typeId' });
};
return MultimediaType;
};

View File

@ -1,21 +0,0 @@
const routes = require('express').Router();
const { isAdministratorUser, isLoggedUser } = require('../../middlewares/accessValidator');
const SchemaValidator = require('../../middlewares/schemaValidator');
/*const PaginateMiddleware = require('../../middlewares/paginate');
const FieldMiddleware = require('../../middlewares/fields');*/
//const SortMiddleware = require('../../middlewares/sort');
const MultimediaTypesValidation = require('./multimedia_types.validations');
const MultimediaTypesController = require('./multimedia_types.controller');
//routes.get('/venues', true, SortMiddleware.middleware({ default: "name" }), venueController.find);
//routes.get('/venues', isLoggedUser, SortMiddleware.middleware({ default: "name" }), venueController.find);
//routes.get('/venues/:id', isLoggedUser, venueController.findOne);
routes.post('/multimediaTypes/', SchemaValidator(MultimediaTypesValidation.MultimediaTypesInputType, true), MultimediaTypesController.create);
//routes.put('/venues/:id', isAdministratorUser, venueController.update);
//routes.delete('/venues/:id', isAdministratorUser, venueController.delete);
module.exports = routes;

View File

@ -1,10 +0,0 @@
/* global MultimediaType */
'use strict';
const _ = require('lodash');
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');
const extraMethods = {};
module.exports = generateService(models.MultimediaType, extraMethods);

View File

@ -1,17 +0,0 @@
const Joi = require('joi');
const MultimediaTypesInputType = Joi.object().keys({
name: Joi.string().required(),
description: Joi.string().optional(),
});
/*
const MultimediaTypesOutputType = Joi.object().keys({
name: Joi.string().required(),
description: Joi.string().optional(),
});
*/
module.exports = {
MultimediaTypesInputType,
// MultimediaTypesOutputType
};

View File

@ -51,6 +51,12 @@ module.exports = function (sequelize, DataTypes) {
tableName: 'speakers',
freezeTableName: true,
timestamps: true,
defaultScope: {
where: {
state: 'publish'
}
},
});
Speaker.associate = function (models) {

View File

@ -2,7 +2,6 @@
Cargar
script-carga-bd-users.sql
script-carga-bd-event_types.sql
script-carga-bd-multimedia_types.sql
script-carga-bd-values.sql
script-carga-bd-venues.sql
script-carga-bd-envents_venues_aux.sql
@ -12,8 +11,8 @@ script-carga-bd-entidades.sql
insert into lqdvi_v2.entities_entities_types (entityid, typeid, createdAt, updatedAt)
select id, '76b17163-a167-11e9-a57c-000c295f0f58', now(), now() from `entities`
insert into lqdvi_v2.`multimedia_files` (id, name, description, typeid, provider, code, url, createdAt, userId, updatedAt)
SELECT a.id, a.title, a.description, '166fb0aa-5182-4d22-addd-818337194cd7', a.provider, a.code, a.url, a.created, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now()
insert into lqdvi_v2.`multimedia_files` (id, name, description, type, provider, code, url, createdAt, userId, updatedAt)
SELECT a.id, a.title, a.description, 'video', a.provider, a.code, a.url, a.created, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now()
FROM lqdvi.`video` as a;
@ -29,7 +28,7 @@ set e.venueID = (select a.venueID from envents_venues_aux a where a.eventID = e.
insert into lqdvi_v2.speakers
(id, name, description, slogan, twitter, facebook, youtube, linkedin, instagram, web, state, typeId, userId, createdAt, updatedAt)
SELECT id, name, description, slogan, twitter, facebook, youtube, linkedin, instagram, web, 'publicado', 1, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now()
SELECT id, name, description, slogan, twitter, facebook, youtube, linkedin, instagram, web, 'publish', 1, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now()
FROM lqdvi.speaker;
insert into lqdvi_v2.speakers_values (speakerid, valueId, createdAt, updatedAt)
@ -48,20 +47,20 @@ FROM lqdvi.`conference`
where resume in (select id from lqdvi_v2.multimedia_files);
//insertamos las imagenes de los ponentes
insert into lqdvi_v2.multimedia_files (id, name, description, typeId, provider, url, userId, createdAt, updatedAt)
SELECT UUID() as ID, concat(name, ' - picture'), id as speakerId, '14c3810c-aca0-440a-b597-f72a7ceb59dc', 'cdn', picture, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now() FROM lqdvi.speaker
insert into lqdvi_v2.multimedia_files (id, name, description, type, provider, url, userId, createdAt, updatedAt)
SELECT UUID() as ID, concat(name, ' - picture'), id as speakerId, 'picture', 'cdn', picture, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now() FROM lqdvi.speaker
where picture is not null;
insert into lqdvi_v2.multimedias (id, multimediafileid, entityid, entityname, type, createdat, updatedat)
SELECT UUID() as ID, id as multimediafileid, description as speakerid, 'speaker', 'picture-speaker', now(), now() FROM lqdvi_v2.multimedia_files
SELECT UUID() as ID, id as multimediafileid, description as speakerid, 'speaker', 'avatar', now(), now() FROM lqdvi_v2.multimedia_files
where name like '%picture%';
insert into lqdvi_v2.multimedia_files (id, name, description, typeId, provider, url, userId, createdAt, updatedAt)
SELECT UUID() as ID, concat(name, ' - wallpaper'), id as speakerId, '14c3810c-aca0-440a-b597-f72a7ceb59dc', 'cdn', wallpaper, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now() FROM lqdvi.speaker
insert into lqdvi_v2.multimedia_files (id, name, description, type, provider, url, userId, createdAt, updatedAt)
SELECT UUID() as ID, concat(name, ' - wallpaper'), id as speakerId, 'picture', 'cdn', wallpaper, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', now(), now() FROM lqdvi.speaker
where wallpaper is not null;
insert into lqdvi_v2.multimedias (id, multimediafileid, entityid, entityname, type, createdat, updatedat)
SELECT UUID() as ID, id as multimediafileid, description as speakerid, 'speaker', 'wallpaper-speaker', now(), now() FROM lqdvi_v2.multimedia_files
SELECT UUID() as ID, id as multimediafileid, description as speakerid, 'speaker', 'wallpaper', now(), now() FROM lqdvi_v2.multimedia_files
where name like '%wallpaper%';
insert into lqdvi_v2.`multimedias` (id, entityId, entityName, multimediafileId, type, createdAt, updatedAt)

View File

@ -1,37 +0,0 @@
-- MySQL dump 10.13 Distrib 5.7.26, for Linux (x86_64)
--
-- Host: localhost Database: lqdvi_v2
-- ------------------------------------------------------
-- Server version 5.7.26-0ubuntu0.16.04.1
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
--
-- Dumping data for table `multimedia_types`
--
LOCK TABLES `multimedia_types` WRITE;
/*!40000 ALTER TABLE `multimedia_types` DISABLE KEYS */;
INSERT INTO `multimedia_types` VALUES ('14c3810c-aca0-440a-b597-f72a7ceb59dc','picture - Imagen','JPG / PNG','2019-07-04 16:42:29','2019-07-04 16:42:29'),('166fb0aa-5182-4d22-addd-818337194cd7','Video','Video de Vimeo o Youtube','2019-06-24 11:27:59','2019-06-24 11:27:59'),('574c8977-5578-4b5c-b093-6db791132daa','PodCast','PodCast de','2019-06-24 11:30:04','2019-06-24 11:30:04');
/*!40000 ALTER TABLE `multimedia_types` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
-- Dump completed on 2019-07-04 18:52:59