add max
parameter to /events/ API
This commit is contained in:
parent
6749fbfea6
commit
5bd7a3e62e
1 changed files with 10 additions and 6 deletions
|
@ -357,7 +357,7 @@ const eventController = {
|
||||||
if (event.recurrent) {
|
if (event.recurrent) {
|
||||||
eventController._createRecurrent()
|
eventController._createRecurrent()
|
||||||
} else {
|
} else {
|
||||||
// send notifications (mastodon / email)
|
// send notifications
|
||||||
const notifier = require('../../notifier')
|
const notifier = require('../../notifier')
|
||||||
notifier.notifyEvent('Create', event.id)
|
notifier.notifyEvent('Create', event.id)
|
||||||
}
|
}
|
||||||
|
@ -482,7 +482,8 @@ const eventController = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
async _select ({ start, end, tags, places, show_recurrent }) {
|
async _select ({ start, end, tags, places, show_recurrent, max }) {
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
// do not include parent recurrent event
|
// do not include parent recurrent event
|
||||||
recurrent: null,
|
recurrent: null,
|
||||||
|
@ -517,18 +518,20 @@ const eventController = {
|
||||||
attributes: {
|
attributes: {
|
||||||
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
|
exclude: ['likes', 'boost', 'userId', 'is_visible', 'createdAt', 'updatedAt', 'description', 'resources']
|
||||||
},
|
},
|
||||||
order: ['start_datetime', Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE "tagTag" = tag) DESC')],
|
order: ['start_datetime'],
|
||||||
include: [
|
include: [
|
||||||
{ model: Resource, required: false, attributes: ['id'] },
|
{ model: Resource, required: false, attributes: ['id'] },
|
||||||
{
|
{
|
||||||
model: Tag,
|
model: Tag,
|
||||||
|
order: [Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE tagTag = tag) DESC')],
|
||||||
attributes: ['tag'],
|
attributes: ['tag'],
|
||||||
required: !!tags,
|
required: !!tags,
|
||||||
...where_tags,
|
...where_tags,
|
||||||
through: { attributes: [] }
|
through: { attributes: [] }
|
||||||
},
|
},
|
||||||
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
{ model: Place, required: true, attributes: ['id', 'name', 'address'] }
|
||||||
]
|
],
|
||||||
|
limit: max
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
log.error('[EVENT]', e)
|
log.error('[EVENT]', e)
|
||||||
return []
|
return []
|
||||||
|
@ -545,15 +548,16 @@ const eventController = {
|
||||||
* Select events based on params
|
* Select events based on params
|
||||||
*/
|
*/
|
||||||
async select (req, res) {
|
async select (req, res) {
|
||||||
const start = req.query.start
|
const start = req.query.start || dayjs().unix()
|
||||||
const end = req.query.end
|
const end = req.query.end
|
||||||
const tags = req.query.tags
|
const tags = req.query.tags
|
||||||
const places = req.query.places
|
const places = req.query.places
|
||||||
|
const max = req.query.max
|
||||||
const show_recurrent = settingsController.settings.allow_recurrent_event &&
|
const show_recurrent = settingsController.settings.allow_recurrent_event &&
|
||||||
(typeof req.query.show_recurrent !== 'undefined' ? req.query.show_recurrent === 'true' : settingsController.settings.recurrent_event_visible)
|
(typeof req.query.show_recurrent !== 'undefined' ? req.query.show_recurrent === 'true' : settingsController.settings.recurrent_event_visible)
|
||||||
|
|
||||||
res.json(await eventController._select({
|
res.json(await eventController._select({
|
||||||
start, end, places, tags, show_recurrent
|
start, end, places, tags, show_recurrent, max
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue