47 lines
No EOL
1.5 KiB
JavaScript
47 lines
No EOL
1.5 KiB
JavaScript
import Event from '../../../models/event.js'
|
|
import { connectDB } from '../../../utils/mongoose.js'
|
|
import jwt from 'jsonwebtoken'
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
try {
|
|
// TODO: Temporarily disabled auth for testing - enable when authentication is set up
|
|
// const token = getCookie(event, 'auth-token') || getHeader(event, 'authorization')?.replace('Bearer ', '')
|
|
|
|
// if (!token) {
|
|
// throw createError({
|
|
// statusCode: 401,
|
|
// statusMessage: 'Authentication required'
|
|
// })
|
|
// }
|
|
|
|
// const config = useRuntimeConfig()
|
|
// const decoded = jwt.verify(token, config.jwtSecret)
|
|
|
|
const eventId = getRouterParam(event, 'id')
|
|
console.log('🔍 API: Get event by ID called')
|
|
console.log('🔍 API: Event ID param:', eventId)
|
|
|
|
await connectDB()
|
|
|
|
const eventData = await Event.findById(eventId)
|
|
console.log('🔍 API: Event data found:', eventData ? 'YES' : 'NO')
|
|
console.log('🔍 API: Event data preview:', eventData ? { id: eventData._id, title: eventData.title } : null)
|
|
|
|
if (!eventData) {
|
|
console.log('❌ API: Event not found in database')
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Event not found'
|
|
})
|
|
}
|
|
|
|
console.log('✅ API: Returning event data')
|
|
return { data: eventData }
|
|
} catch (error) {
|
|
console.error('❌ API: Error fetching event:', error)
|
|
throw createError({
|
|
statusCode: 500,
|
|
statusMessage: error.message || 'Failed to fetch event'
|
|
})
|
|
}
|
|
}) |