mirror of
https://framagit.org/les/gancio.git
synced 2025-01-31 16:42:22 +01:00
check if place or tag exists, fix #268
This commit is contained in:
parent
10d8eb0107
commit
1508df3850
3 changed files with 16 additions and 9 deletions
|
@ -35,12 +35,12 @@ export default {
|
||||||
...mapState(['settings']),
|
...mapState(['settings']),
|
||||||
...mapGetters(['hide_thumbs', 'is_dark']),
|
...mapGetters(['hide_thumbs', 'is_dark']),
|
||||||
},
|
},
|
||||||
asyncData({ $axios, params, error }) {
|
async asyncData({ $axios, params, error }) {
|
||||||
try {
|
try {
|
||||||
const place = params.place
|
const events = await $axios.$get(`/place/${encodeURIComponent(params.place)}`)
|
||||||
return $axios.$get(`/place/${encodeURIComponent(place)}`)
|
return events
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error({ statusCode: 400, message: 'Error!' })
|
error({ statusCode: 404, message: 'Place not found!' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ export default {
|
||||||
const events = await $axios.$get(`/tag/${encodeURIComponent(tag)}`)
|
const events = await $axios.$get(`/tag/${encodeURIComponent(tag)}`)
|
||||||
return { events, tag }
|
return { events, tag }
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error({ statusCode: 400, message: 'Error!' })
|
error({ statusCode: 404, message: 'Tag not found' })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
const { Tag, Event } = require('../models/models')
|
const { Tag, Event } = require('../models/models')
|
||||||
const uniq = require('lodash/uniq')
|
const uniq = require('lodash/uniq')
|
||||||
const log = require('../../log')
|
const log = require('../../log')
|
||||||
|
const Sequelize = require('sequelize')
|
||||||
|
|
||||||
const { where, fn, col, Op } = require('sequelize')
|
const { where, fn, col, Op } = require('sequelize')
|
||||||
const exportController = require('./export')
|
const exportController = require('./export')
|
||||||
|
@ -25,14 +25,21 @@ module.exports = {
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
|
|
||||||
// /feed/rss/tag/:tagname
|
// /feed/rss/tag/:tag
|
||||||
// /feed/ics/tag/:tagname
|
// /feed/ics/tag/:tag
|
||||||
// /feed/json/tag/:tagname
|
// /feed/json/tag/:tag
|
||||||
// tag/:tag
|
// tag/:tag
|
||||||
async getEvents (req, res) {
|
async getEvents (req, res) {
|
||||||
const eventController = require('./event')
|
const eventController = require('./event')
|
||||||
const format = req.params.format || 'json'
|
const format = req.params.format || 'json'
|
||||||
const tags = req.params.tag
|
const tags = req.params.tag
|
||||||
|
|
||||||
|
// check if this tag exists
|
||||||
|
if(!await Tag.findOne({ where:
|
||||||
|
Sequelize.where( Sequelize.fn( 'LOWER', Sequelize.col('tag')),
|
||||||
|
Sequelize.Op.eq, tags.toLocaleLowerCase())})) {
|
||||||
|
return res.sendStatus(404)
|
||||||
|
}
|
||||||
const events = await eventController._select({ tags: tags.toLocaleLowerCase(), show_recurrent: true, show_multidate: true, start: 0, reverse: true })
|
const events = await eventController._select({ tags: tags.toLocaleLowerCase(), show_recurrent: true, show_multidate: true, start: 0, reverse: true })
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case 'rss':
|
case 'rss':
|
||||||
|
|
Loading…
Reference in a new issue