paxton-front/server/api/yandex_pvz.ts
alsaze 2e01f58e67
Some checks failed
Deploy / build (push) Has been cancelled
refactoring
2025-11-21 12:48:00 +03:00

33 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { YandexPvzRequest, YandexPvzResponse } from '#shared/yandex_pvz'
import axios from 'axios'
import { defineEventHandler, readBody } from 'h3'
export default defineEventHandler(async (event): Promise<YandexPvzResponse | { error: string }> => {
try {
const data = await readBody<YandexPvzRequest>(event)
const apiUrl = import.meta.env.VITE_YANDEX_B2B_BASE_URL!
const token = import.meta.env.VITE_YANDEX_B2B_TOKEN!
const response = await axios.post<YandexPvzResponse>(
`${apiUrl}/pickup-points/list`,
{
geo_id: data?.geo_id,
type: 'pickup_point',
},
{
headers: {
'Content-Type': 'application/json',
'Accept-Language': 'ru-RU',
'Authorization': `Bearer ${token}`,
},
},
)
return response.data
}
catch (error) {
console.error('Ошибка при запросе к Яндекс API:', error)
return { error: `Не удалось получить точки ПВЗ: ${error}` }
}
})