export feed / api with inclusive tags or places
This commit is contained in:
@@ -504,14 +504,12 @@ const eventController = {
|
|||||||
where.start_datetime = { [Op.lte]: end }
|
where.start_datetime = { [Op.lte]: end }
|
||||||
}
|
}
|
||||||
|
|
||||||
if (places) {
|
if (places || tags) {
|
||||||
where.placeId = places.split(',')
|
where[Op.or] = {
|
||||||
}
|
placeId: places ? places.split(',') : [],
|
||||||
|
'$tags.tag$': tags ? tags.split(',') : []
|
||||||
let where_tags = {}
|
}
|
||||||
if (tags) {
|
}
|
||||||
where_tags = { where: { [Op.or]: { tag: tags.split(',') } } }
|
|
||||||
}
|
|
||||||
|
|
||||||
const events = await Event.findAll({
|
const events = await Event.findAll({
|
||||||
where,
|
where,
|
||||||
@@ -526,7 +524,6 @@ const eventController = {
|
|||||||
order: [Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE tagTag = tag) DESC')],
|
order: [Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE tagTag = tag) DESC')],
|
||||||
attributes: ['tag'],
|
attributes: ['tag'],
|
||||||
required: !!tags,
|
required: !!tags,
|
||||||
...where_tags,
|
|
||||||
through: { attributes: [] }
|
through: { attributes: [] }
|
||||||
},
|
},
|
||||||
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ const Event = require('../models/event')
|
|||||||
const Place = require('../models/place')
|
const Place = require('../models/place')
|
||||||
const Tag = require('../models/tag')
|
const Tag = require('../models/tag')
|
||||||
|
|
||||||
const { Op } = require('sequelize')
|
const { Op, literal } = require('sequelize')
|
||||||
const moment = require('dayjs')
|
const moment = require('dayjs')
|
||||||
const ics = require('ics')
|
const ics = require('ics')
|
||||||
|
|
||||||
@@ -16,16 +16,13 @@ const exportController = {
|
|||||||
|
|
||||||
const where = {}
|
const where = {}
|
||||||
const yesterday = moment().subtract('1', 'day').unix()
|
const yesterday = moment().subtract('1', 'day').unix()
|
||||||
let where_tags = {}
|
|
||||||
|
|
||||||
if (tags) {
|
|
||||||
where_tags = { where: { tag: tags.split(',') } }
|
|
||||||
}
|
|
||||||
|
|
||||||
if (places) {
|
|
||||||
where.placeId = places.split(',')
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (places || tags) {
|
||||||
|
where[Op.or] = {
|
||||||
|
placeId: places ? places.split(',') : [],
|
||||||
|
'$tags.tag$': tags ? tags.split(',') : []
|
||||||
|
}
|
||||||
|
}
|
||||||
if (!show_recurrent) {
|
if (!show_recurrent) {
|
||||||
where.parentId = null
|
where.parentId = null
|
||||||
}
|
}
|
||||||
@@ -39,7 +36,15 @@ const exportController = {
|
|||||||
start_datetime: { [Op.gte]: yesterday },
|
start_datetime: { [Op.gte]: yesterday },
|
||||||
...where
|
...where
|
||||||
},
|
},
|
||||||
include: [{ model: Tag, required: false, ...where_tags }, { model: Place, attributes: ['name', 'id', 'address'] }]
|
include: [
|
||||||
|
{
|
||||||
|
model: Tag,
|
||||||
|
order: [literal('(SELECT COUNT("tagTag") FROM event_tags WHERE tagTag = tag) DESC')],
|
||||||
|
attributes: ['tag'],
|
||||||
|
required: !!tags,
|
||||||
|
through: { attributes: [] }
|
||||||
|
},
|
||||||
|
{ model: Place, attributes: ['name', 'id', 'address'] }]
|
||||||
})
|
})
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|||||||
Reference in New Issue
Block a user