This commit is contained in:
David Arranz 2019-07-26 16:50:53 +02:00
parent eb446432e2
commit 582c0aec42
23 changed files with 420 additions and 508 deletions

View File

@ -18,6 +18,25 @@ const commentsComposer = (comments) => {
else return comments;
};
const commentComposer = (comment, context) => {
if (comment.user) {
comment.user_name = comment.user.name + '---';
comment.profile_picture = cdnHelper.getCDNMediaUrl(comment.user.profile_picture);
}else {
comment.user_name = comment.nameUserOld;
comment.profile_picture = cdnHelper.getCDNMediaUrl(comment.profile_pictureOld);
}
delete comment.nameUserOld;
delete comment.profile_pictureOld;
delete comment.userId;
delete comment.user;
return Object.assign({},
comment);
};
const multimediaComposer = (multimedias) => {
if(multimedias) {
@ -133,5 +152,6 @@ const entityComposer = (entity, context) => {
module.exports = {
entityComposer,
speakerComposer,
eventComposer
eventComposer,
commentComposer
}

View File

@ -16,7 +16,7 @@ const MODULE_NAME = '[blog.controller]';
// Success Messages
//const VG_CT_VIDEOGAME_DELETED_SUCCESSFULLY = 'Videogame deleted successfully';
const blogCommentsService = generateCommentService(models.Post.Comments);
//const blogCommentsService = generateCommentService(models.Post.Comments);
const controllerOptions = {
MODULE_NAME,

View File

@ -35,15 +35,21 @@ module.exports = function (sequelize, DataTypes) {
through: models.PostCategory,
foreignKey: 'postId'
});
//Post.Comments = Post.hasMany(models.Comment, { foreignKey: 'postId' });
//Post.Reactions = Post.hasMany(models.PostReaction, { foreignKey: 'postId' });
//Post.User = Post.belongsTo(models.User, { foreignKey: 'userId' });
/*
Post.Multimedias = Post.belongsToMany(models.MultimediaFile, {
through: models.MultimediaPost,
foreignKey: 'postId'
});
*/
//OJO antes de force comentar
// OJO GENERA UN FOREIGN KEY Con eventos y habrá ID de otras entidades que no exitan en la tabla eventos, porque son post o speakers
Post.Multimedias = Post.hasMany(models.Multimedia, {
foreignKey: 'entityId',
as: { singular: 'multimedia', plural: 'multimedias' }
});
Post.Comments = Post.hasMany(models.Comment, {
foreignKey: 'entityId',
as: { singular: 'comment', plural: 'comments' }
});
};
return Post;
};

View File

@ -0,0 +1,15 @@
'use strict';
const generateControllers = require('../../core/controllers');
const commentService = require('./comment.service');
const { extractParamsFromRequest, handleErrorResponse, handleResultResponse } = require('../../helpers/controller.helper');
// Module Name
const MODULE_NAME = '[comment.controller]';
const controllerOptions = { MODULE_NAME };
const extraControllers = {
};
module.exports = generateControllers(commentService, extraControllers, controllerOptions);

View File

@ -17,49 +17,53 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false
},
/*entity: {
type: DataTypes.VIRTUAL,
get: function () {
const name = this.get('entityName');
const id = this.get('entityId');
let modelName = '';
switch (name) {
case 'post':
modelName = 'Post';
break;
case 'speaker':
modelName = 'Speaker'
break;
case 'event':
modelName = 'Event';
break;
default:
break;
}
return sequelize.models[modelName].findOne(id);
}
}*/
nameUserOld: {
type: DataTypes.STRING(125),
},
profile_pictureOld: {
type: DataTypes.STRING(255),
},
}, {
indexes: [{
unique: false,
fields: ['entityId']
}],
tableName: 'comments',
freezeTableName: true,
timestamps: true,
});
indexes: [{
unique: false,
fields: ['entityId']
}],
tableName: 'comments',
freezeTableName: true,
timestamps: true,
defaultScope: {
include: [{
model: sequelize.models.User,
as: 'user',
attributes: ['name', 'surname', 'profile_picture'],
}]
},
});
Comment.addScope('onlyEvents', () => {
return {
where: {
entityName: 'event'
}
}
});
Comment.addScope('onlySpeakers', () => {
return {
where: {
entityName: 'speaker'
}
}
});
Comment.associate = function (models) {
Comment.User = Comment.belongsTo(models.User, { foreignKey: 'userId', constraints: false, as: 'user' });
//Comment.Conference = Comment.belongsTo(models.Conference, { foreignKey: 'conferenceId', constraints: false });
//Comment.Post = Comment.belongsTo(models.Post, { foreignKey: 'postId', constraints: false });
//Comment.Speaker = Comment.belongsTo(models.Speaker, { foreignKey: 'speakerId', constraints: false });
};
return Comment;
};

View File

@ -0,0 +1,55 @@
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 entityValidation = require('./entity.validations');
const commentController = require('./comment.controller');
const generalInvalidFields = [
];
routes.get('/comments',
isLoggedUser,
FieldMiddleware.middleware({
invalidFields: generalInvalidFields
}),
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "createdAt" }),
commentController.find({
scopes: ['defaultScope'],
}),
);
routes.get('/comments/events',
isLoggedUser,
FieldMiddleware.middleware({
invalidFields: generalInvalidFields
}),
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "createdAt" }),
commentController.find({
scopes: ['defaultScope', 'onlyEvents'],
}),
);
routes.get('/comments/speakers',
isLoggedUser,
FieldMiddleware.middleware({
invalidFields: generalInvalidFields
}),
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "createdAt" }),
commentController.find({
scopes: ['defaultScope', 'onlySpeakers'],
}),
);
module.exports = routes;

View File

@ -1,10 +1,35 @@
/* global Post */
/* global Comment */
'use strict';
const _ = require('lodash');
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
const models = require('../../core/models');
const { commentComposer } = require('../../helpers/composes.helper');
const extraMethods = {}
const extraMethods = {
afterFetchAll: (result, params, context) => {
if (!result.count) {
return result;
}
let rows = result.rows.map(row => row.toJSON());
rows = rows.map(comment => commentComposer(comment, context));
return {
count: rows.length,
rows: rows
}
},
/*
afterFetchOne: (result, params, context) => {
if (result)
result = result.toJSON();
return eventComposer(result, context);
},
*/
}
module.exports = generateService(models.Comment, extraMethods);
module.exports = (model) => generateService(model, extraMethods);

View File

@ -140,7 +140,6 @@ module.exports = function (sequelize, DataTypes) {
as: 'type',
attributes: ['name', 'title'],
}]
},
});
@ -155,22 +154,15 @@ module.exports = function (sequelize, DataTypes) {
Event.Details = Event.hasMany(models.EventDetail, { foreignKey: 'eventId', as: "details" });
//OJOJOJOJOJOJOJJOJ
//OJO antes de force comentar
// OJO GENERA UN FOREIGN KEY Con eventos y habrá ID de otras entidades que no exitan en la tabla eventos, porque son post o speakers
// Event.Comments = Event.hasMany(models.Comment, {
// foreignKey: 'entityId',
// scope: {
// entityName: 'event'
// },
// as: "comments"
// });
// Event.Multimedias = Event.hasMany(models.Multimedia, {
// foreignKey: 'entityId',
// scope: {
// entityName: 'event'
// },
// as: { singular: 'multimedia', plural: 'multimedias' }});
Event.Comments = Event.hasMany(models.Comment, {
foreignKey: 'entityId',
scope: {
entityName: 'event'
},
as: "comments"
});
Event.Multimedias = Event.hasMany(models.Multimedia, {
foreignKey: 'entityId',
@ -243,7 +235,7 @@ module.exports = function (sequelize, DataTypes) {
model: sequelize.models.MultimediaFile,
as: "multimediaFile"
}]
}]
}]
}]
}]
}

View File

@ -18,6 +18,19 @@ const generalInvalidFields = [
'multiple_limit', 'allow_overflow', 'marketing_list',
];
//Da todas las ciudades en las que ha habido congresos
routes.get('/cities',
// isLoggedUser,
// FieldMiddleware.middleware({
// invalidFields: generalInvalidFields
// }),
// PaginateMiddleware.middleware(),
// SortMiddleware.middleware({ default: "-init_date" }),
// eventController.find({
// scopes: ['defaultScope', 'includeVenue', 'includeMultimedias'],
// }),
);
routes.get('/events',
isLoggedUser,
FieldMiddleware.middleware({

View File

@ -11,10 +11,24 @@ const VenueValidation = require('./venue.validations');
const venueController = require('./venue.controller');
routes.get('/venues',
//SortMiddleware.middleware({ default: "name" }),
venueController.find()
);
routes.get('/venues/:id',
//isLoggedUser,
venueController.findOne());
routes.get('/venues/:id/events',
//isLoggedUser,
//SortMiddleware.middleware({ default: "name" }),
(req, res, next) => {
req.params.association = 'Events';
next();
},
venueController.find());
//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('/venues/', SchemaValidator(VenueValidation.VenueInputType, true), venueController.create);
//routes.put('/venues/:id', isAdministratorUser, venueController.update);

View File

@ -23,33 +23,6 @@ module.exports = function (sequelize, DataTypes) {
type: DataTypes.STRING,
allowNull: false,
},
/*entity: {
type: DataTypes.VIRTUAL,
get: function() {
const name = this.get('entityName');
const id = this.get('entityId');
let modelName = '';
switch (name) {
case 'post':
modelName = 'Post';
break;
case 'speaker':
modelName = 'Speaker'
break;
case 'event':
modelName = 'Event';
break;
default:
break;
}
return sequelize.models[modelName].findByPk(id).then(function(result) { return result });
}
}*/
}, {
indexes: [{
unique: false,

View File

@ -84,7 +84,7 @@ module.exports = function (sequelize, DataTypes) {
Speaker.EventDetails = Speaker.hasMany(models.EventDetail, { foreignKey: 'speakerId', as: "eventdetails" });
Speaker.Questions = Speaker.hasMany(models.EventQuestion, { foreignKey: 'speakerId', as: "questions" });
//OJOJOJOJOJOJOJJOJ
//OJO antes de force comentar
// OJO GENERA UN FOREIGN KEY Con eventos y habrá ID de otras entidades que no exitan en la tabla eventos, porque son post o speakers
Speaker.Multimedias = Speaker.hasMany(models.Multimedia, {
foreignKey: 'entityId',
@ -119,7 +119,7 @@ module.exports = function (sequelize, DataTypes) {
include: [{
model: sequelize.models.MultimediaFile,
as: "multimediaFile"
}]
}]
},
]
}

View File

@ -19,7 +19,8 @@ module.exports = function (sequelize, DataTypes) {
Value.Speakers = Value.belongsToMany(models.Speaker, {
through: models.SpeakerValue,
foreignKey: 'valueId'
foreignKey: 'valueId',
as: 'speakers'
});
};

View File

@ -17,7 +17,7 @@ routes.get('/values',
}),*/
PaginateMiddleware.middleware(),
SortMiddleware.middleware({ default: "name" }),
valueController.find
valueController.find()
);
routes.get('/values/:id',
@ -25,17 +25,18 @@ routes.get('/values/:id',
FieldMiddleware.middleware({
invalidFields: ['createdAt']
}),
valueController.findOne
valueController.findOne()
);
routes.get('/values/:id/speakers',
(req, res, next) => {
req.params.association = 'Speakers';
req.params.association = 'speakers';
next();
},
valueController.find,
valueController.find(),
);
//routes.get('/values/:id/:association',
//isLoggedUser,
/*FieldMiddleware.middleware({

File diff suppressed because one or more lines are too long

View File

@ -8,8 +8,6 @@ script-carga-bd-envents_venues_aux.sql
script-carga-bd-speaker_types.sql
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, 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()
@ -34,6 +32,9 @@ FROM lqdvi.speaker;
insert into lqdvi_v2.speakers_values (speakerid, valueId, createdAt, updatedAt)
SELECT speakerid, valueid, now(), now() FROM lqdvi.`speaker-value`;
//insertamos los videos relacionados
insert into lqdvi_v2.`multimedias` (id, entityId, entityName, multimediafileId, type, createdAt, updatedAt)
SELECT UUID() as ID, conferenceId as eventID, 'event', videoId as multimediafileid, 'relacion', now(), now()
@ -120,37 +121,6 @@ FROM lqdvi.partner a
left join lqdvi.level b on (b.partnerId = a.id);
//INSERTAMOS LAS ENTIDADES
insert into lqdvi_v2.entities
(id, name, state, createdAt, updatedAt, contact_person, contact_email )
SELECT UUID() as ID, name, 'ff', now(), now(), contact_name, contact_email
FROM lqdvi.partner;
//ASIGNAMOS QUE SON PARTNERS
insert into lqdvi_v2.entities_entities_types
(entityid, typeid, createdAt, updatedAt)
select id, '32d6306a-aa02-11e9-a553-000c295f0f58', now(), now()
from lqdvi_v2.entities
where state = 'ff';
update lqdvi_v2.entities
set state = 'publish'
where state = 'ff';
//OJO ASIGNAMOS EVENTO SEVILLA PARA PRUEBA, ESTE DEBE SER LUEGO LA CORUÑA
update lqdvi_v2.events_reservations
set eventID = '5f772798-5616-4663-a661-b6484dd11bd7';
//ENLAZAMOS CON LAS RESERVAS
//Metemos las preguntas de los congresos
insert into lqdvi_v2.events_questions (id, eventId, speakerId, anonimous, answered, discared, answer, userId, createdAt, updatedAt)
SELECT UUID() as ID, conferenceId, speakerId, anonymous, answered, discared, content, '0939bb2a-d33d-4290-ac81-fc9faa1c015e', created, now() FROM lqdvi.question;
//COMENTARIOS.....
insert into lqdvi_v2.comments (id, entityId, entityname, content, createdAt, updatedAt, userId)
@ -160,5 +130,18 @@ FROM lqdvi.`speaker-comment`;
insert into lqdvi_v2.events_reservations (id, init_available_date, end_available_date, gmt, state,
assistants, confirmed, sold_out, allow_multiple, multiple_limit,
description, reservation_code, color, allow_overflow, overflow_reservationId, marketing_list, createdat, updatedAt, userID, entityId, eventId)
SELECT UUID() as ID, '2019-09-03 00:00:00', '2019-10-03 22:00:00', 2, 'publish',
lqdvi.level.assistants, lqdvi.level.confirmed, lqdvi.level.sold_out, 0, 0,
lqdvi.level.name, lqdvi.level.invitation_code, lqdvi.level.color, 1, null, null,
now(), now(), '0939bb2a-d33d-4290-ac81-fc9faa1c015e', '6c2df93f-af83-11e9-aa90-000c295f0f58','5f772798-5616-4663-a661-b6484dd11bd7'
FROM lqdvi.level
where lqdvi.level.partnerId = '2851f45a-287a-41cc-8258-d50ffe02699b'

File diff suppressed because one or more lines are too long

View File

@ -1,81 +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 */;
--
-- Table structure for table `entities`
--
DROP TABLE IF EXISTS `entities`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entities` (
`id` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`name` varchar(255) NOT NULL,
`state` varchar(45) NOT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `entities_entities_types`
--
DROP TABLE IF EXISTS `entities_entities_types`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entities_entities_types` (
`entityId` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`typeId` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`entityId`,`typeId`),
UNIQUE KEY `entities_entities_types_entityId_typeId_unique` (`entityId`,`typeId`),
KEY `typeId` (`typeId`),
CONSTRAINT `entities_entities_types_ibfk_1` FOREIGN KEY (`entityId`) REFERENCES `entities` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
CONSTRAINT `entities_entities_types_ibfk_2` FOREIGN KEY (`typeId`) REFERENCES `entities_types` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `entities_types`
--
DROP TABLE IF EXISTS `entities_types`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entities_types` (
`id` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`name` varchar(255) NOT NULL,
`alias` varchar(45) NOT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
/*!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-10 13:14:45

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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 `entities_types`
--
LOCK TABLES `entities_types` WRITE;
/*!40000 ALTER TABLE `entities_types` DISABLE KEYS */;
INSERT INTO `entities_types` VALUES ('32d6306a-aa02-11e9-a553-000c295f0f58','ENTIDADES PATROCINADORAS COLABORADORAS','partner','2019-07-08 12:02:15','2019-07-08 12:02:15'),('76b17163-a167-11e9-a57c-000c295f0f58','ENTIDADES EDUCATIVAS COLABORADORAS','college','2019-07-08 12:02:15','2019-07-08 12:02:15');
/*!40000 ALTER TABLE `entities_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-19 10:52:18