This commit is contained in:
David Arranz 2019-08-28 12:43:41 +02:00
parent 01a02da4c3
commit 777bf55bf6
5 changed files with 66 additions and 16 deletions

View File

@ -3,11 +3,14 @@ const cdnHelper = require('./cdn.helper');
const valuesComposer = (values) => (values) ? values.map(value => ({id: value.id, name: value.name,})): values;
const citiesComposer = (city) => {
const citiesComposer = (city, context) => {
if (city) {
if (city.location)
city.location = locationComposer(city.location, context);
return {
...city,
image: cdnHelper.getCDNCityMediaUrl(city.city),
};
}
else return city;
@ -17,9 +20,8 @@ const locationComposer = (location, context) => {
if (location) {
let multimedias = [];
if ((context.scopes) && (context.scopes.includes('includeMultimedias'))) {
if (location.multimedias)
multimedias = multimediaComposer(location.multimedias);
};
return {
...location,

56
locations.sql Normal file
View File

@ -0,0 +1,56 @@
-- MySQL dump 10.13 Distrib 5.7.27, for Linux (x86_64)
--
-- Host: localhost Database: lqdvi_v2
-- ------------------------------------------------------
-- Server version 5.7.27-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 `locations`
--
DROP TABLE IF EXISTS `locations`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `locations` (
`id` char(36) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`country` varchar(125) NOT NULL,
`city` varchar(125) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`createdAt` datetime NOT NULL,
`updatedAt` datetime NOT NULL,
PRIMARY KEY (`country`,`city`),
UNIQUE KEY `locations_country_city` (`country`,`city`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `locations`
--
LOCK TABLES `locations` WRITE;
/*!40000 ALTER TABLE `locations` DISABLE KEYS */;
INSERT INTO `locations` VALUES ('df9706d9-c8de-11e9-b18d-000c295f0f58','Andorra','Andorra','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df970cb3-c8de-11e9-b18d-000c295f0f58','Austria','Bregenz','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df970ea8-c8de-11e9-b18d-000c295f0f58','Ecuador','Quito','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df970fa6-c8de-11e9-b18d-000c295f0f58','España','Avilés','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971031-c8de-11e9-b18d-000c295f0f58','España','Barcelona','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df9710f6-c8de-11e9-b18d-000c295f0f58','España','Bilbao','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df9711c7-c8de-11e9-b18d-000c295f0f58','España','La Coruña','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('9f1cc156-c8ad-11e9-b18d-000c295f0f58','España','Madrid','En la ciudad de Madrid empezamos nuestra andadura','2019-08-27 11:32:43','2019-08-27 11:32:43'),('df971307-c8de-11e9-b18d-000c295f0f58','España','Málaga','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df9713a8-c8de-11e9-b18d-000c295f0f58','España','Oviedo','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df9714cd-c8de-11e9-b18d-000c295f0f58','España','Palma de Mallorca','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df97164b-c8de-11e9-b18d-000c295f0f58','España','Pozuelo de Alarcón','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971720-c8de-11e9-b18d-000c295f0f58','España','Santander','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df97179f-c8de-11e9-b18d-000c295f0f58','España','Sevilla','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df97187d-c8de-11e9-b18d-000c295f0f58','España','Valencia','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df97195e-c8de-11e9-b18d-000c295f0f58','España','Zaragoza','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971a09-c8de-11e9-b18d-000c295f0f58','Francia','París','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971a93-c8de-11e9-b18d-000c295f0f58','México','Hermosillo','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971b09-c8de-11e9-b18d-000c295f0f58','México','Mazatlán','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971b89-c8de-11e9-b18d-000c295f0f58','México','México DF','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971c1c-c8de-11e9-b18d-000c295f0f58','México','Monterrey','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971c93-c8de-11e9-b18d-000c295f0f58','México','Morelia','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971d10-c8de-11e9-b18d-000c295f0f58','México','San Cristobal de las Casas','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971da5-c8de-11e9-b18d-000c295f0f58','México','Sinaola','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971e1c-c8de-11e9-b18d-000c295f0f58','México','Toluca','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971e91-c8de-11e9-b18d-000c295f0f58','Perú','Lima','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971f09-c8de-11e9-b18d-000c295f0f58','Portugal','Lisboa','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17'),('df971fb5-c8de-11e9-b18d-000c295f0f58','Portugal','Oporto','En la ciudad de xxxx empezamos nuestra andadura','2019-08-27 17:25:17','2019-08-27 17:25:17');
/*!40000 ALTER TABLE `locations` 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-08-28 11:13:14

View File

@ -350,20 +350,12 @@ module.exports = function (sequelize, DataTypes) {
},
});
Event.addScope('CitiesOfEvents22', {
// include: [{ model: sequelize.models.Location, as: 'location', required: false, attributes: ['description']}],
include: [{ model: sequelize.models.EventType, as: 'type', attributes: ['name', 'title']}],
});
Event.addScope('CitiesOfEvents', () => {
return {
include: [{
model: sequelize.models.Location, as: 'location', required: false,
include: [{
model: sequelize.models.Multimedia, as: { singular: 'multimedia', plural: 'multimedias' }, required: false, attributes: [['type', 'aaa']],
model: sequelize.models.Multimedia, as: { singular: 'multimedia', plural: 'multimedias' }, required: false, attributes: ['type'],
include: [{ model: sequelize.models.MultimediaFile, as: "multimediaFile", attributes: ['name', 'description', 'class', 'provider', 'url'] },]
}]
},

View File

@ -17,12 +17,12 @@ const extraMethods = {
}
let rows = result.rows.map(row => row.toJSON());
/*
if (context.scopes.includes('CitiesOfEvents'))
rows = rows.map(city => citiesComposer(city, context))
else
rows = rows.map(event => eventComposer(event, context));
*/
return {
count: result.count,
rows: rows

View File

@ -12,7 +12,7 @@ routes.get('/locations',
isLoggedUser,
// SortMiddleware.middleware({ default: "city" }),
locationController.find({
scopes: ['includeMultimedias', 'includeEvents'],
scopes: ['includeMultimedias'] //, 'includeEvents'],
})
);