Добавлены модели WildberriesSupply и WildberriesSupplyCard в схему Prisma, а также соответствующие мутации и запросы в GraphQL для управления поставками Wildberries. Обновлены компоненты создания поставки для поддержки выбора карточек товаров и улучшен интерфейс. Реализована логика обработки карточек товаров и их отображения.

This commit is contained in:
Bivekich
2025-07-21 12:45:03 +03:00
parent 39c1499f72
commit d74b4c1266
9 changed files with 1115 additions and 7 deletions

View File

@ -11,8 +11,57 @@ interface WildberriesWarehousesResponse {
data: WildberriesWarehouse[]
}
interface WildberriesCard {
nmID: number
vendorCode: string
sizes: Array<{
chrtID: number
techSize: string
wbSize: string
price: number
discountedPrice: number
quantity: number
}>
mediaFiles: string[]
object: string
parent: string
countryProduction: string
supplierVendorCode: string
brand: string
title: string
description: string
}
interface WildberriesCardsResponse {
cursor: {
total: number
updatedAt: string
limit: number
nmID: number
}
cards: WildberriesCard[]
}
interface WildberriesCardFilter {
sort?: {
cursor?: {
limit?: number
nmID?: number
updatedAt?: string
}
filter?: {
textSearch?: string
withPhoto?: number
objectIDs?: number[]
tagIDs?: number[]
brandIDs?: number[]
}
}
}
export class WildberriesService {
private static baseUrl = 'https://marketplace-api.wildberries.ru'
private static contentUrl = 'https://content-api.wildberries.ru'
/**
* Получить список складов WB
@ -39,6 +88,56 @@ export class WildberriesService {
}
}
/**
* Получить карточки товаров
*/
static async getCards(apiKey: string, filter?: WildberriesCardFilter): Promise<WildberriesCard[]> {
try {
const response = await fetch(`${this.contentUrl}/content/v1/cards/cursor/list`, {
method: 'POST',
headers: {
'Authorization': apiKey,
'Content-Type': 'application/json',
},
body: JSON.stringify(filter || {
sort: {
cursor: {
limit: 100
}
}
})
})
if (!response.ok) {
throw new Error(`WB API Error: ${response.status} ${response.statusText}`)
}
const data: WildberriesCardsResponse = await response.json()
return data.cards || []
} catch (error) {
console.error('Error fetching WB cards:', error)
throw new Error('Ошибка получения карточек товаров')
}
}
/**
* Поиск карточек товаров по тексту
*/
static async searchCards(apiKey: string, searchText: string, limit: number = 100): Promise<WildberriesCard[]> {
const filter: WildberriesCardFilter = {
sort: {
cursor: {
limit
},
filter: {
textSearch: searchText
}
}
}
return this.getCards(apiKey, filter)
}
/**
* Валидация API ключа WB
*/