From 5bd7a3e62e9d5d570860ca6953a2a24a6a868187 Mon Sep 17 00:00:00 2001 From: lesion Date: Thu, 2 Dec 2021 12:09:32 +0100 Subject: [PATCH] add `max` parameter to /events/ API --- server/api/controller/event.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/server/api/controller/event.js b/server/api/controller/event.js index 3d257b99..2d878ba4 100644 --- a/server/api/controller/event.js +++ b/server/api/controller/event.js @@ -357,7 +357,7 @@ const eventController = { if (event.recurrent) { eventController._createRecurrent() } else { - // send notifications (mastodon / email) + // send notifications const notifier = require('../../notifier') 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 = { // do not include parent recurrent event recurrent: null, @@ -517,18 +518,20 @@ const eventController = { attributes: { 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: [ { model: Resource, required: false, attributes: ['id'] }, { model: Tag, + order: [Sequelize.literal('(SELECT COUNT("tagTag") FROM event_tags WHERE tagTag = tag) DESC')], attributes: ['tag'], required: !!tags, ...where_tags, through: { attributes: [] } }, { model: Place, required: true, attributes: ['id', 'name', 'address'] } - ] + ], + limit: max }).catch(e => { log.error('[EVENT]', e) return [] @@ -545,15 +548,16 @@ const eventController = { * Select events based on params */ async select (req, res) { - const start = req.query.start + const start = req.query.start || dayjs().unix() const end = req.query.end const tags = req.query.tags const places = req.query.places + const max = req.query.max const show_recurrent = settingsController.settings.allow_recurrent_event && (typeof req.query.show_recurrent !== 'undefined' ? req.query.show_recurrent === 'true' : settingsController.settings.recurrent_event_visible) res.json(await eventController._select({ - start, end, places, tags, show_recurrent + start, end, places, tags, show_recurrent, max })) },