32 lines
1.0 KiB
JavaScript
32 lines
1.0 KiB
JavaScript
import { requireAuth } from '../../utils/authHelpers.js'
|
|
import { getLiveSession, updateLiveSession } from '../../utils/liveSessions.js'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const user = requireAuth(event)
|
|
const id = event.context.params?.id
|
|
if (!id) throw createError({ statusCode: 400, message: 'id required' })
|
|
|
|
const session = getLiveSession(id)
|
|
if (!session) throw createError({ statusCode: 404, message: 'Live session not found' })
|
|
if (session.userId !== user.id) throw createError({ statusCode: 403, message: 'Forbidden' })
|
|
|
|
const body = await readBody(event).catch(() => ({}))
|
|
const lat = Number(body?.lat)
|
|
const lng = Number(body?.lng)
|
|
const updates = {}
|
|
if (Number.isFinite(lat)) updates.lat = lat
|
|
if (Number.isFinite(lng)) updates.lng = lng
|
|
if (Object.keys(updates).length) {
|
|
updateLiveSession(id, updates)
|
|
}
|
|
|
|
const updated = getLiveSession(id)
|
|
return {
|
|
id: updated.id,
|
|
label: updated.label,
|
|
lat: updated.lat,
|
|
lng: updated.lng,
|
|
updatedAt: updated.updatedAt,
|
|
}
|
|
})
|