cleaner next/prev event
This commit is contained in:
@@ -91,6 +91,7 @@ const eventController = {
|
||||
const is_admin = req.user && req.user.is_admin
|
||||
const id = Number(req.params.event_id)
|
||||
let event
|
||||
|
||||
try {
|
||||
event = await Event.findByPk(id, {
|
||||
attributes: {
|
||||
@@ -113,8 +114,36 @@ const eventController = {
|
||||
} catch (e) {
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
if (!event) {
|
||||
return res.sendStatus(400)
|
||||
}
|
||||
|
||||
// get prev and next event
|
||||
const next = await Event.findOne({
|
||||
attributes: ['id'],
|
||||
where: {
|
||||
is_visible: true,
|
||||
parentId: null,
|
||||
start_datetime: { [Op.gt]: event.start_datetime }
|
||||
},
|
||||
order: [['start_datetime', 'ASC']]
|
||||
})
|
||||
|
||||
const prev = await Event.findOne({
|
||||
attributes: ['id'],
|
||||
where: {
|
||||
is_visible: true,
|
||||
parentId: null,
|
||||
start_datetime: { [Op.lt]: event.start_datetime }
|
||||
},
|
||||
order: [['start_datetime', 'DESC']]
|
||||
})
|
||||
|
||||
if (event && (event.is_visible || is_admin)) {
|
||||
event = event.get()
|
||||
event.next = next && next.id
|
||||
event.prev = prev && prev.id
|
||||
event.tags = event.tags.map(t => t.tag)
|
||||
if (format === 'json') {
|
||||
res.json(event)
|
||||
|
||||
@@ -115,11 +115,12 @@ const Helpers = {
|
||||
return res.data
|
||||
})
|
||||
.catch(e => {
|
||||
debug(e)
|
||||
debug(`[ERR] ${URL}: ${e}`)
|
||||
return false
|
||||
})
|
||||
|
||||
if (fedi_user) {
|
||||
debug(`Create a new AP User => ${URL}`)
|
||||
fedi_user = await APUser.create({ ap_id: URL, object: fedi_user })
|
||||
}
|
||||
return fedi_user
|
||||
@@ -136,6 +137,7 @@ const Helpers = {
|
||||
if (instance) { return instance }
|
||||
}
|
||||
|
||||
// TODO: is this a standard? don't think so
|
||||
instance = await axios.get(`${instance_url}/api/v1/instance`, { headers: { Accept: 'application/json' } })
|
||||
.then(res => res.data)
|
||||
.then(instance => {
|
||||
@@ -169,7 +171,7 @@ const Helpers = {
|
||||
}
|
||||
|
||||
// little hack -> https://github.com/joyent/node-http-signature/pull/83
|
||||
req.headers.authorization = 'Signature ' + req.headers.signature
|
||||
// req.headers.authorization = 'Signature ' + req.headers.signature
|
||||
|
||||
req.fedi_user = user
|
||||
|
||||
|
||||
Reference in New Issue
Block a user