add geolocalization
This commit is contained in:
@@ -44,7 +44,7 @@ const eventController = {
|
||||
order: [[Sequelize.col('w'), 'DESC']],
|
||||
where: {
|
||||
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
|
||||
},
|
||||
},
|
||||
attributes: [['tag','label'], [Sequelize.cast(Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'INTEGER'), 'w']],
|
||||
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
|
||||
group: ['tag.tag'],
|
||||
@@ -110,7 +110,7 @@ const eventController = {
|
||||
attributes: ['tag'],
|
||||
through: { attributes: [] }
|
||||
},
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address', 'details'] }
|
||||
],
|
||||
replacements,
|
||||
limit: 30,
|
||||
@@ -192,7 +192,7 @@ const eventController = {
|
||||
},
|
||||
include: [
|
||||
{ model: Tag, required: false, attributes: ['tag'], through: { attributes: [] } },
|
||||
{ model: Place, attributes: ['name', 'address', 'id'] },
|
||||
{ model: Place, attributes: ['name', 'address', 'details', 'id'] },
|
||||
{
|
||||
model: Resource,
|
||||
where: !is_admin && { hidden: false },
|
||||
@@ -222,7 +222,7 @@ const eventController = {
|
||||
recurrent: null,
|
||||
[Op.or]: [
|
||||
{ start_datetime: { [Op.gt]: event.start_datetime } },
|
||||
{
|
||||
{
|
||||
start_datetime: event.start_datetime,
|
||||
id: { [Op.gt]: event.id }
|
||||
}
|
||||
@@ -239,7 +239,7 @@ const eventController = {
|
||||
recurrent: null,
|
||||
[Op.or]: [
|
||||
{ start_datetime: { [Op.lt]: event.start_datetime } },
|
||||
{
|
||||
{
|
||||
start_datetime: event.start_datetime,
|
||||
id: { [Op.lt]: event.id }
|
||||
}
|
||||
@@ -405,7 +405,8 @@ const eventController = {
|
||||
}
|
||||
place = await Place.create({
|
||||
name: body.place_name,
|
||||
address: body.place_address
|
||||
address: body.place_address,
|
||||
details: body.place_details
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -559,13 +560,14 @@ const eventController = {
|
||||
}
|
||||
place = await Place.create({
|
||||
name: body.place_name,
|
||||
address: body.place_address
|
||||
address: body.place_address,
|
||||
details: body.place_details
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
await event.setPlace(place)
|
||||
|
||||
|
||||
// create/assign tags
|
||||
let tags = []
|
||||
if (body.tags) {
|
||||
@@ -624,7 +626,7 @@ const eventController = {
|
||||
|
||||
/**
|
||||
* Method to search for events with pagination and filtering
|
||||
* @returns
|
||||
* @returns
|
||||
*/
|
||||
async _select ({
|
||||
start = dayjs().unix(),
|
||||
@@ -665,7 +667,7 @@ const eventController = {
|
||||
|
||||
const replacements = []
|
||||
if (tags && places) {
|
||||
where[Op.and] = [
|
||||
where[Op.and] = [
|
||||
{ placeId: places ? places.split(',') : []},
|
||||
Sequelize.fn('EXISTS', Sequelize.literal(`SELECT 1 FROM event_tags WHERE ${Col('event_tags.eventId')}=${Col('event.id')} AND LOWER(${Col('tagTag')}) in (?)`))
|
||||
]
|
||||
@@ -679,10 +681,10 @@ const eventController = {
|
||||
|
||||
let pagination = {}
|
||||
if (limit) {
|
||||
pagination = {
|
||||
pagination = {
|
||||
limit,
|
||||
offset: limit * page,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const events = await Event.findAll({
|
||||
@@ -698,7 +700,7 @@ const eventController = {
|
||||
attributes: ['tag'],
|
||||
through: { attributes: [] }
|
||||
},
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
||||
{ model: Place, required: true, attributes: ['id', 'name', 'address', 'details'] }
|
||||
],
|
||||
...pagination,
|
||||
replacements
|
||||
|
||||
@@ -5,6 +5,7 @@ const exportController = require('./export')
|
||||
|
||||
const log = require('../../log')
|
||||
const { Op, where, col, fn, cast } = require('sequelize')
|
||||
const NOMINATIM_URL = 'https://nominatim.openstreetmap.org/search?limit=3&format=geocodejson&accept-language=it&q='
|
||||
|
||||
module.exports = {
|
||||
|
||||
@@ -60,7 +61,7 @@ module.exports = {
|
||||
{ address: where(fn('LOWER', col('address')), 'LIKE', '%' + search + '%')},
|
||||
]
|
||||
},
|
||||
attributes: ['name', 'address', 'id'],
|
||||
attributes: ['name', 'address', 'details', 'id'],
|
||||
include: [{ model: Event, where: { is_visible: true }, required: true, attributes: [] }],
|
||||
group: ['place.id'],
|
||||
raw: true,
|
||||
@@ -70,6 +71,16 @@ module.exports = {
|
||||
|
||||
// TOFIX: don't know why limit does not work
|
||||
return res.json(places.slice(0, 10))
|
||||
}
|
||||
},
|
||||
|
||||
}
|
||||
// async _nominatim (req, res) {
|
||||
// const details = req.params.place_details
|
||||
// const ret = await axios.get(`${NOMINATIM_URL}${details}`, { headers: { 'User-Agent': 'gancio 0.20' } })
|
||||
// debug(`${NOMINATIM_URL}${details}`)
|
||||
// debug(ret.status)
|
||||
// debug(ret.statusText)
|
||||
// debug(ret.data)
|
||||
// return ret
|
||||
// },
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ const defaultSettings = {
|
||||
allow_anon_event: true,
|
||||
allow_recurrent_event: false,
|
||||
recurrent_event_visible: false,
|
||||
allow_geolocalization: false,
|
||||
enable_federation: true,
|
||||
enable_resources: false,
|
||||
hide_boosts: true,
|
||||
|
||||
Reference in New Issue
Block a user