33 lines
994 B
TypeScript
33 lines
994 B
TypeScript
import type { YandexPvzResponse } from '~/server/shared/types/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(event)
|
||
const apiUrl = process.env.VITE_YANDEX_B2B_BASE_URL!
|
||
const token = process.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}` }
|
||
}
|
||
})
|