add a tag controller

This commit is contained in:
lesion 2022-05-25 10:53:51 +02:00
parent 5125c51ea8
commit eaeb6c272f
No known key found for this signature in database
GPG key ID: 352918250B012177
2 changed files with 52 additions and 0 deletions

View file

@ -0,0 +1,47 @@
const dayjs = require('dayjs')
const Tag = require('../models/tag')
const Event = require('../models/event')
const eventController = require('./event')
const Sequelize = require('sequelize')
module.exports = {
// async getEvents (req, res) {
// const name = req.params.placeName
// const place = await Place.findOne({ where: { name }})
// if (!place) {
// log.warn(`Place ${name} not found`)
// return res.sendStatus(404)
// }
// const start = dayjs().unix()
// const events = await eventController._select({ start, places: `${place.id}`, show_recurrent: true})
// return res.json({ events, place })
// },
async get (req, res) {
const search = req.query.search
console.error(search)
const tags = await Tag.findAll({
order: [[Sequelize.fn('COUNT', Sequelize.col('tag.tag')), 'DESC']],
attributes: ['tag'],
where: {
tag: Sequelize.where(Sequelize.fn('LOWER', Sequelize.col('tag')), 'LIKE', '%' + search + '%'),
},
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
group: ['tag.tag'],
limit: 10,
subQuery:false
})
return res.json(tags.map(t => t.tag))
}
// async getPlaces (req, res) {
// const search = req.params.search
// const places = await Place.findAll({ where: {
// [Op.or]: [
// { name: }
// ]
// }})
// }
}

View file

@ -24,6 +24,7 @@ if (config.status !== 'READY') {
const { isAuth, isAdmin } = require('./auth')
const eventController = require('./controller/event')
const placeController = require('./controller/place')
const tagController = require('./controller/tag')
const settingsController = require('./controller/settings')
const exportController = require('./controller/export')
const userController = require('./controller/user')
@ -156,6 +157,10 @@ if (config.status !== 'READY') {
api.get('/place/:placeName/events', cors, placeController.getEvents)
// api.get('/place', cors, placeController.)
api.get('/tag', cors, tagController.get)
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES
api.get('/instances', isAdmin, instanceController.getAll)