a
This commit is contained in:
parent
05e7d6494d
commit
854b58187b
@ -13,6 +13,22 @@ const citiesComposer = (city) => {
|
||||
else return city;
|
||||
}
|
||||
|
||||
const locationComposer = (location, context) => {
|
||||
if (location) {
|
||||
|
||||
let multimedias = [];
|
||||
if ((context.scopes) && (context.scopes.includes('includeMultimedias'))) {
|
||||
multimedias = multimediaComposer(location.multimedias);
|
||||
};
|
||||
|
||||
return {
|
||||
...location,
|
||||
multimedias: multimedias,
|
||||
};
|
||||
}
|
||||
else return location;
|
||||
}
|
||||
|
||||
const commentComposer = (comment, context) => {
|
||||
if (comment.user) {
|
||||
comment.user_name = comment.user.name + '---';
|
||||
@ -170,5 +186,6 @@ module.exports = {
|
||||
speakerComposer,
|
||||
eventComposer,
|
||||
commentComposer,
|
||||
citiesComposer
|
||||
citiesComposer,
|
||||
locationComposer
|
||||
}
|
||||
@ -205,7 +205,7 @@ module.exports = function (sequelize, DataTypes) {
|
||||
foreignKey: 'overflow_eventId',
|
||||
required: false });
|
||||
|
||||
Event.Type = Event.belongsTo(models.EventType, { foreignKey: 'typeId', as: "type" });
|
||||
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,
|
||||
@ -224,6 +224,13 @@ module.exports = function (sequelize, DataTypes) {
|
||||
required: false,
|
||||
});
|
||||
|
||||
Event.Location = Event.hasOne(models.Location, {
|
||||
foreignKey: ['city', 'country'],
|
||||
sourcekey: ['city', 'country'],
|
||||
as: "location",
|
||||
required: false,
|
||||
});
|
||||
|
||||
Event.Multimedias = Event.hasMany(models.Multimedia, {
|
||||
foreignKey: 'entityId',
|
||||
as: { singular: 'multimedia', plural: 'multimedias' },
|
||||
@ -252,6 +259,14 @@ module.exports = function (sequelize, DataTypes) {
|
||||
}
|
||||
});
|
||||
|
||||
Event.addScope('includeLocation', () => {
|
||||
return {
|
||||
include: [
|
||||
{ model: sequelize.models.Location, as: 'location', foreignKey: ['city', 'country'], sourcekey: ['city','country'] }
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
Event.addScope('includeMultimedias', () => {
|
||||
return {
|
||||
include: [{
|
||||
|
||||
@ -72,7 +72,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'], //, 'includeLocation'],
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
14
modules/locations/locations.controller.js
Normal file
14
modules/locations/locations.controller.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
const generateControllers = require('../../core/controllers');
|
||||
const locationService = require('./locations.service');
|
||||
|
||||
|
||||
// Module Name
|
||||
const MODULE_NAME = '[locations.controller]';
|
||||
|
||||
const controllerOptions = { MODULE_NAME };
|
||||
const extraControllers = {};
|
||||
|
||||
module.exports = generateControllers(locationService, extraControllers, controllerOptions);
|
||||
|
||||
55
modules/locations/locations.model.js
Normal file
55
modules/locations/locations.model.js
Normal file
@ -0,0 +1,55 @@
|
||||
const Sequelize = require('sequelize');
|
||||
|
||||
module.exports = function (sequelize, DataTypes) {
|
||||
const Location = sequelize.define('Location', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
country: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false
|
||||
},
|
||||
city: {
|
||||
type: DataTypes.STRING(125),
|
||||
allowNull: false
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
},
|
||||
}, {
|
||||
tableName: 'locations',
|
||||
freezeTableName: true,
|
||||
timestamps: true,
|
||||
});
|
||||
|
||||
Location.associate = function (models) {
|
||||
Location.Events = Location.hasMany(models.Event, { as: 'events', foreignKey: ['city', 'country'], sourcekey: ['city', 'country'] });
|
||||
|
||||
//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
|
||||
Location.Multimedias = Location.hasMany(models.Multimedia, {
|
||||
foreignKey: 'entityId',
|
||||
as: { singular: 'multimedia', plural: 'multimedias' },
|
||||
});
|
||||
};
|
||||
|
||||
Location.addScope('includeMultimedias', () => {
|
||||
return {
|
||||
include: [{
|
||||
model: sequelize.models.Multimedia,
|
||||
as: { singular: 'multimedia', plural: 'multimedias' },
|
||||
required: false,
|
||||
include: [{
|
||||
model: sequelize.models.MultimediaFile,
|
||||
as: "multimediaFile"
|
||||
}]
|
||||
},
|
||||
]
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return Location;
|
||||
};
|
||||
32
modules/locations/locations.routes.js
Normal file
32
modules/locations/locations.routes.js
Normal file
@ -0,0 +1,32 @@
|
||||
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 locationController = require('./locations.controller');
|
||||
|
||||
routes.get('/locations',
|
||||
isLoggedUser,
|
||||
// SortMiddleware.middleware({ default: "city" }),
|
||||
locationController.find({
|
||||
scopes: ['includeMultimedias']
|
||||
})
|
||||
);
|
||||
|
||||
routes.get('/locations/:id',
|
||||
isLoggedUser,
|
||||
// SortMiddleware.middleware({ default: "city" }),
|
||||
locationController.findOne({
|
||||
scopes: ['includeMultimedias']
|
||||
})
|
||||
);
|
||||
|
||||
/********************************************************************************************************
|
||||
* ADMINISTRACIÓN
|
||||
*********************************************************************************************************
|
||||
*/
|
||||
|
||||
module.exports = routes;
|
||||
38
modules/locations/locations.service.js
Normal file
38
modules/locations/locations.service.js
Normal file
@ -0,0 +1,38 @@
|
||||
/* global Venue */
|
||||
'use strict';
|
||||
|
||||
const _ = require('lodash');
|
||||
const { generateService, parseParamsToFindOptions } = require('../../helpers/service.helper');
|
||||
const { locationComposer } = require('../../helpers/composes.helper');
|
||||
const models = require('../../core/models');
|
||||
|
||||
const extraMethods = {
|
||||
|
||||
afterFetchAll: (result, params, context) => {
|
||||
|
||||
if (!result.count) {
|
||||
return result;
|
||||
}
|
||||
|
||||
let rows = result.rows.map(row => row.toJSON());
|
||||
|
||||
if (context.scopes.includes('includeMultimedias'))
|
||||
rows = rows.map(row => locationComposer(row, context));
|
||||
|
||||
return {
|
||||
count: result.count,
|
||||
rows: rows
|
||||
}
|
||||
},
|
||||
|
||||
afterFetchOne: (result, params, context) => {
|
||||
|
||||
if (result)
|
||||
result = result.toJSON();
|
||||
return locationComposer(result, context);
|
||||
},
|
||||
|
||||
|
||||
};
|
||||
|
||||
module.exports = generateService(models.Location, extraMethods);
|
||||
@ -20,5 +20,38 @@ FROM lqdvi_v2.aux_table
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
https://vimeo.com/328614321
|
||||
|
||||
|
||||
|
||||
**********Insertar multimedia asociado
|
||||
insert into lqdvi_v2.`multimedia_files` (id, lqdvi_v2.`multimedia_files`.name, description, class, provider, lqdvi_v2.`multimedia_files`.code,
|
||||
url, userId, CreatedAt, UpdatedAt)
|
||||
|
||||
SELECT UUID() as ID, 'THDVI - 1 Edición Bilbao' , 'Making of 1ª edición',
|
||||
'video','vimeo', '328614321', 'https://player.vimeo.com/video/328614321', 'ecf7dda2-258c-458d-a41f-de07a9cfb6eb', now(), now()
|
||||
|
||||
SELECT UUID() as ID, 'THDVI - 2 Edición Madrid' , 'Making of 2ª edición',
|
||||
'video','vimeo', '320555737', 'https://player.vimeo.com/video/320555737', 'ecf7dda2-258c-458d-a41f-de07a9cfb6eb', now(), now()
|
||||
|
||||
FROM lqdvi_v2.aux_table
|
||||
|
||||
insert into lqdvi_v2.multimedias (id, multimediafileId, entityId, entityName, type, createdAt, updatedat)
|
||||
|
||||
select UUID() as ID, 'd7cc286d-c50a-11e9-86a6-000c295f0f58', '0998e0c5-c4ce-11e9-86a6-000c295f0f58', 'event', 'resume', now(), now()
|
||||
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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user