update tag

This commit is contained in:
lesion
2022-12-13 15:37:04 +01:00
parent 06b35b0cd0
commit dcb954918a
6 changed files with 54 additions and 15 deletions

View File

@@ -88,6 +88,24 @@ module.exports = {
res.json(place)
},
async updateTag (req, res) {
const oldtag = await Tag.findByPk(req.body.tag)
const newtag = await Tag.findByPk(req.body.newTag)
// if the new tag does not exists, just rename the old one
if (!newtag) {
oldtag.tag = req.body.newTag
await oldtag.update({ tag: req.body.newTag })
} else {
// in case it exists:
// - search for events with old tag
const events = await oldtag.getEvents()
// - substitute it with the new one
await oldtag.removeEvents(events)
await newtag.addEvents(events)
}
res.sendStatus(200)
},
async remove (req, res) {
log.info('Remove tag', req.params.tag)

View File

@@ -162,6 +162,7 @@ if (config.status !== 'READY') {
api.get('/export/:type', cors, exportController.export)
// - PLACES
api.get('/places', isAdmin, placeController.getAll)
api.get('/place/:placeName', cors, placeController.getEvents)
api.get('/place', cors, placeController.search)
@@ -169,10 +170,12 @@ if (config.status !== 'READY') {
api.get('/placeOSM/Photon/:place_details', cors, placeController._photon)
api.put('/place', isAdmin, placeController.updatePlace)
// - TAGS
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)
api.put('/tag', isAdmin, tagController.updateTag)
// - FEDIVERSE INSTANCES, MODERATION, RESOURCES