Добавлено получение информации о деталях из Parts Index и обновлены компоненты для отображения этой информации. Включены новые типы для работы с данными Parts Index.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { PartsIndexCatalogsResponse, PartsIndexGroup } from '@/types/partsindex';
|
||||
import { PartsIndexCatalogsResponse, PartsIndexGroup, PartsIndexEntityInfoResponse } from '@/types/partsindex';
|
||||
|
||||
const PARTS_INDEX_API_BASE = 'https://api.parts-index.com';
|
||||
const API_KEY = 'PI-E1C0ADB7-E4A8-4960-94A0-4D9C0A074DAE';
|
||||
@ -54,6 +54,41 @@ class PartsIndexService {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Получить информацию о детали по артикулу и бренду
|
||||
*/
|
||||
async getEntityInfo(code: string, brand?: string, lang: string = 'ru'): Promise<PartsIndexEntityInfoResponse> {
|
||||
try {
|
||||
const params = new URLSearchParams({
|
||||
code: code,
|
||||
lang: lang
|
||||
});
|
||||
|
||||
if (brand) {
|
||||
params.append('brand', brand);
|
||||
}
|
||||
|
||||
const response = await fetch(
|
||||
`${PARTS_INDEX_API_BASE}/v1/entities?${params.toString()}`,
|
||||
{
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Authorization': API_KEY,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
|
||||
return await response.json();
|
||||
} catch (error) {
|
||||
console.error(`Ошибка получения информации о детали ${code}:`, error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const partsIndexService = new PartsIndexService();
|
Reference in New Issue
Block a user