import { requireUserSession } from '../../../utils/auth'
import { getNotificationsByUserId } from '../../../database/queries/notifications'
import { handleApiError, createSuccessResponse } from '../../../utils/errors'

export default eventHandler(async (event) => {
  try {
    const session = await requireUserSession(event)
    const notifications = await getNotificationsByUserId(session.user.id)
    return createSuccessResponse(notifications, 'Notifications retrieved successfully')
  } catch (error) {
    throw handleApiError(error)
  }
})
