init tags tab in admin panel

This commit is contained in:
lesion
2022-12-12 20:54:51 +01:00
parent 854bd6538a
commit 06b35b0cd0
7 changed files with 154 additions and 5 deletions

View File

@@ -1,6 +1,8 @@
const Tag = require('../models/tag')
const Event = require('../models/event')
const uniq = require('lodash/uniq')
const log = require('../../log')
const { where, fn, col, Op } = require('sequelize')
const exportController = require('./export')
@@ -45,6 +47,20 @@ module.exports = {
}
},
async getAll (_req, res) {
const tags = await Tag.findAll({
order: [[fn('COUNT', col('tag.tag')), 'DESC']],
attributes: ['tag', [fn('COUNT', col('tag.tag')), 'count']],
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
group: ['tag.tag'],
raw: true,
})
return res.json(tags)
},
/**
* search for tags by query string
* sorted by usage
@@ -60,9 +76,30 @@ module.exports = {
include: [{ model: Event, where: { is_visible: true }, attributes: [], through: { attributes: [] }, required: true }],
group: ['tag.tag'],
limit: 10,
subQuery:false
subQuery: false
})
return res.json(tags.map(t => t.tag))
},
async updateTag (req, res) {
const tag = await Tag.findByPk(req.body.tag)
await tag.update(req.body)
res.json(place)
},
async remove (req, res) {
log.info('Remove tag', req.params.tag)
const tagName = req.params.tag
try {
const tag = await Tag.findByPk(tagName)
await tag.destroy()
res.sendStatus(200)
} catch (e) {
log.error('Tag removal failed:', e)
res.sendStatus(404)
}
}
}

View File

@@ -162,15 +162,18 @@ if (config.status !== 'READY') {
api.get('/export/:type', cors, exportController.export)
api.get('/place/all', isAdmin, placeController.getAll)
api.get('/places', isAdmin, placeController.getAll)
api.get('/place/:placeName', cors, placeController.getEvents)
api.get('/place', cors, placeController.search)
api.get('/placeOSM/Nominatim/:place_details', cors, placeController._nominatim)
api.get('/placeOSM/Photon/:place_details', cors, placeController._photon)
api.put('/place', isAdmin, placeController.updatePlace)
api.get('/tags', isAdmin, tagController.getAll)
api.get('/tag', cors, tagController.search)
api.get('/tag/:tag', cors, tagController.getEvents)
api.delete('/tag/:tag', isAdmin, tagController.remove)
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES
api.get('/instances', isAdmin, instanceController.getAll)