Telegram Bot + Mini App for city walking quests. - React 19 + TypeScript + Vite 6 frontend - Express 5 + PostgreSQL backend - grammY Telegram bot with DeepSeek AI - GitLab CI/CD: lint, build, deploy to production Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
35 lines
966 B
TypeScript
35 lines
966 B
TypeScript
import type { ApiRequest, ApiResponse } from '../_lib/types.js'
|
|
import { cors, withTelegramAuth } from '../_lib/auth.js'
|
|
import { findUserByTelegramId, getFullQuestState } from '../_lib/db.js'
|
|
|
|
async function handler(req: ApiRequest, res: ApiResponse) {
|
|
cors(req, res)
|
|
|
|
if (req.method === 'OPTIONS') {
|
|
return res.status(200).end()
|
|
}
|
|
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' })
|
|
}
|
|
|
|
const telegramUser = req.telegramUser
|
|
if (!telegramUser) {
|
|
return res.status(401).json({ error: 'Not authenticated' })
|
|
}
|
|
|
|
const user = await findUserByTelegramId(telegramUser.id)
|
|
if (!user) {
|
|
return res.status(404).json({ error: 'User not found', code: 'USER_NOT_FOUND' })
|
|
}
|
|
|
|
const state = await getFullQuestState(user.id)
|
|
if (!state) {
|
|
return res.status(404).json({ error: 'No active quest', code: 'NO_ACTIVE_QUEST' })
|
|
}
|
|
|
|
return res.json(state)
|
|
}
|
|
|
|
export default withTelegramAuth(handler)
|