a
This commit is contained in:
parent
a72762d581
commit
01a02da4c3
@ -157,18 +157,10 @@ module.exports = function (sequelize, DataTypes) {
|
||||
type: DataTypes.UUID,
|
||||
foreignKey: true,
|
||||
},
|
||||
city: {
|
||||
type: DataTypes.STRING,
|
||||
locationId:{
|
||||
type: DataTypes.UUID,
|
||||
foreignKey: true,
|
||||
// references: {
|
||||
// model: 'Location',
|
||||
// key : 'city',
|
||||
// }
|
||||
},
|
||||
country: {
|
||||
type: DataTypes.STRING,
|
||||
foreignKey: true,
|
||||
},
|
||||
},
|
||||
url_streaming: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
@ -191,12 +183,6 @@ module.exports = function (sequelize, DataTypes) {
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
|
||||
indexes: [{
|
||||
unique: false,
|
||||
fields: ['country', 'city']
|
||||
}],
|
||||
|
||||
|
||||
defaultScope: {
|
||||
where: {
|
||||
state: 'publish',
|
||||
@ -206,7 +192,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
model: sequelize.models.EventType,
|
||||
as: 'type',
|
||||
attributes: ['name', 'title'],
|
||||
}]
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
@ -219,11 +205,9 @@ module.exports = function (sequelize, DataTypes) {
|
||||
|
||||
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
|
||||
Event.UserCreate = Event.belongsTo(models.User, { foreignKey: 'userId', as: "user" });
|
||||
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId', as: "venue",
|
||||
required: false,
|
||||
});
|
||||
|
||||
Event.Venue = Event.belongsTo(models.Venue, { foreignKey: 'venueId', as: "venue", required: false});
|
||||
Event.Details = Event.hasMany(models.EventDetail, { foreignKey: 'eventId', as: "details" });
|
||||
Event.Location = Event.belongsTo(models.Location, { foreignKey: 'locationId', as: "location" });
|
||||
|
||||
//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
|
||||
@ -235,15 +219,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
as: "comments",
|
||||
required: false,
|
||||
});
|
||||
/*
|
||||
Event.Location = Event.belongsTo(models.Location, {
|
||||
foreignKey: ['country', 'city'],
|
||||
// sourceKey: ['country', 'city'],
|
||||
as: "location",
|
||||
required: false,
|
||||
// constraints: false,
|
||||
});
|
||||
*/
|
||||
|
||||
Event.Multimedias = Event.hasMany(models.Multimedia, {
|
||||
foreignKey: 'entityId',
|
||||
as: { singular: 'multimedia', plural: 'multimedias' },
|
||||
@ -272,16 +248,6 @@ module.exports = function (sequelize, DataTypes) {
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
Event.addScope('includeLocation', () => {
|
||||
return {
|
||||
include: [
|
||||
{ model: sequelize.models.Location, as: "location", foreignKey: ['country', 'city'], required: false,}
|
||||
]
|
||||
}
|
||||
});
|
||||
*/
|
||||
|
||||
Event.addScope('includeMultimedias', () => {
|
||||
return {
|
||||
include: [{
|
||||
@ -385,10 +351,26 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
|
||||
|
||||
Event.addScope('CitiesOfEvents', {
|
||||
include : [{ model: sequelize.models.EventType, as: 'type', attributes:['name', 'title'] }],
|
||||
group: ['city', 'country', 'typeId'],
|
||||
attributes: ['city', 'country', 'type.name', 'type.title', [sequelize.fn('COUNT', sequelize.col('typeId')), 'ediciones'], [sequelize.fn('SUM', sequelize.col('assistants')), 'assistants']]
|
||||
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']],
|
||||
include: [{ model: sequelize.models.MultimediaFile, as: "multimediaFile", attributes: ['name', 'description', 'class', 'provider', 'url'] },]
|
||||
}]
|
||||
},
|
||||
{ model: sequelize.models.EventType, as: 'type', attributes: ['name', 'title'] }],
|
||||
group: ['location.country', 'location.city', 'Event.typeId',],
|
||||
attributes: ['location.country', 'location.city', 'type.name', 'type.title', [sequelize.fn('COUNT', sequelize.col('Event.typeId')), 'ediciones'], [sequelize.fn('SUM', sequelize.col('Event.assistants')), 'assistants']]
|
||||
}
|
||||
});
|
||||
|
||||
Event.addScope('onlyOfCity', (city) => {
|
||||
|
||||
@ -42,7 +42,6 @@ routes.get('/events',
|
||||
|
||||
routes.get('/events/cities',
|
||||
isLoggedUser,
|
||||
SortMiddleware.middleware({ default: "city" }),
|
||||
eventController.find({
|
||||
scopes: ['CitiesOfEvents']
|
||||
})
|
||||
@ -72,7 +71,7 @@ routes.get('/events/past', cacheSuccesses('24 hours'),
|
||||
PaginateMiddleware.middleware(),
|
||||
SortMiddleware.middleware({ default: "-init_date" }),
|
||||
eventController.find({
|
||||
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeDetails'],
|
||||
scopes: ['defaultScope', 'past', 'includeVenue', 'includeMultimedias', 'includeDetails'],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
'use strict';
|
||||
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const locationService = require('./locations.service');
|
||||
const locationService = require('./location.service');
|
||||
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = '[locations.controller]';
|
||||
const MODULE_NAME = '[location.controller]';
|
||||
|
||||
const controllerOptions = { MODULE_NAME };
|
||||
const extraControllers = {};
|
||||
@ -10,12 +10,10 @@ module.exports = function (sequelize, DataTypes) {
|
||||
country: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false,
|
||||
// primaryKey: true,
|
||||
},
|
||||
city: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false,
|
||||
// primaryKey: true,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
@ -31,7 +29,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
|
||||
Location.associate = function (models) {
|
||||
// Location.Events = Location.hasMany(models.Event, {as:'events', foreingKey: ['country', 'city'] });
|
||||
Location.Events = Location.hasMany(models.Event, {as: 'events', foreignKey: 'locationId'});
|
||||
|
||||
//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
|
||||
@ -57,5 +55,39 @@ module.exports = function (sequelize, DataTypes) {
|
||||
});
|
||||
|
||||
|
||||
Location.addScope('includeEvents', () => {
|
||||
return {
|
||||
include: [{
|
||||
model: sequelize.models.Event,
|
||||
as: 'events',
|
||||
required: false,
|
||||
group: ['typeId'],
|
||||
// attributes: ['name', 'type.title',] //[sequelize.fn('COUNT', sequelize.col('events.typeId')), 'ediciones'],] // [sequelize.fn('SUM', sequelize.col('Event.assistants')), 'assistants']]
|
||||
attributes: [[sequelize.fn('COUNT', sequelize.col('typeId')), 'ediciones'],] // [sequelize.fn('SUM', sequelize.col('Event.assistants')), 'assistants']]
|
||||
// include: [{
|
||||
// model: sequelize.models.MultimediaFile,
|
||||
// as: "multimediaFile"
|
||||
// }]
|
||||
},
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
Location.addScope('includeGroupEvents', () => {
|
||||
return {
|
||||
include: [{
|
||||
|
||||
as: 'events',
|
||||
required: false,
|
||||
// include: [{
|
||||
// model: sequelize.models.MultimediaFile,
|
||||
// as: "multimediaFile"
|
||||
// }]
|
||||
},
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return Location;
|
||||
};
|
||||
@ -6,13 +6,13 @@ const SchemaValidator = require('../../middlewares/schemaValidator');
|
||||
//const PaginateMiddleware = require('../../middlewares/paginate');
|
||||
//const FieldMiddleware = require('../../middlewares/fields');
|
||||
const SortMiddleware = require('../../middlewares/sort');
|
||||
const locationController = require('./locations.controller');
|
||||
const locationController = require('./location.controller');
|
||||
|
||||
routes.get('/locations',
|
||||
isLoggedUser,
|
||||
// SortMiddleware.middleware({ default: "city" }),
|
||||
locationController.find({
|
||||
scopes: ['includeMultimedias']
|
||||
scopes: ['includeMultimedias', 'includeEvents'],
|
||||
})
|
||||
);
|
||||
|
||||
@ -20,7 +20,7 @@ routes.get('/locations/:id',
|
||||
isLoggedUser,
|
||||
// SortMiddleware.middleware({ default: "city" }),
|
||||
locationController.findOne({
|
||||
scopes: ['includeMultimedias']
|
||||
scopes: ['includeMultimedias',]
|
||||
})
|
||||
);
|
||||
|
||||
@ -48,10 +48,194 @@ FROM lqdvi_v2.aux_table
|
||||
|
||||
|
||||
|
||||
|
||||
insert into locations (id, country, city, description, createdat, updatedat)
|
||||
select UUID() as ID, 'España', 'Madrid', 'En la ciudad de Madrid empezamos nuestra andadura', now(), now()
|
||||
from aux_table
|
||||
|
||||
|
||||
|
||||
insert into lqdvi_v2.`multimedia_files` (id, lqdvi_v2.`multimedia_files`.name, description, class, provider,
|
||||
url, userId, CreatedAt, UpdatedAt)
|
||||
|
||||
SELECT UUID() as ID, 'Locations - España - Madrid - Cibeles' , 'Estatua de la cibeles de Madrid',
|
||||
'picture','cdn', 'locations/madrid-espana-cibeles.jpg', 'ecf7dda2-258c-458d-a41f-de07a9cfb6eb', now(), now()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
update events
|
||||
set locationID = 'df9706d9-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Andorra'
|
||||
and country = 'Andorra';
|
||||
|
||||
update events
|
||||
set locationID = 'df970cb3-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Bregenz'
|
||||
and country = 'Austria';
|
||||
|
||||
update events
|
||||
set locationID = 'df970ea8-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Quito'
|
||||
and country = 'Ecuador';
|
||||
|
||||
update events
|
||||
set locationID = 'df970fa6-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Avilés'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df971031-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Barcelona'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df9710f6-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Bilbao'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df9711c7-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'La Coruña'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = '9f1cc156-c8ad-11e9-b18d-000c295f0f58'
|
||||
where city = 'Madrid'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df971307-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Málaga'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df9713a8-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Oviedo'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df9714cd-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Palma de Mallorca'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df9714cd-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Palma'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df97164b-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Pozuelo de Alarcón'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df971720-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Santander'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df97179f-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Sevilla'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df97187d-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Valencia'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df97195e-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Zaragoza'
|
||||
and country = 'España';
|
||||
|
||||
update events
|
||||
set locationID = 'df971a09-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'París'
|
||||
and country = 'Francia';
|
||||
|
||||
update events
|
||||
set locationID = 'df971a93-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Hermosillo'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971b09-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Mazatlán'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971b89-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'México DF'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971c1c-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Monterrey'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971c93-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Morelia'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971d10-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'San Cristobal de las Casas'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971da5-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Sinaola'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971e1c-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Toluca'
|
||||
and country = 'México';
|
||||
|
||||
update events
|
||||
set locationID = 'df971e91-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Lima'
|
||||
and country = 'Perú';
|
||||
|
||||
update events
|
||||
set locationID = 'df971f09-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Lisboa'
|
||||
and country = 'Portugal';
|
||||
|
||||
update events
|
||||
set locationID = 'df971fb5-c8de-11e9-b18d-000c295f0f58'
|
||||
where city = 'Oporto'
|
||||
and country = 'Portugal';
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user