docs: catalog population implementation plans (schema migration + ingestion script)
This commit is contained in:
@@ -429,48 +429,7 @@ main().catch((err) => {
|
||||
});
|
||||
```
|
||||
|
||||
- [ ] **Step 3: Add market prices upsert after the bulk upsert**
|
||||
|
||||
After `upsertItems`, add a call to also upsert `marketPrices` for each item that has a price. This requires knowing the item IDs returned from the bulk upsert and the manufacturer's country/currency. Add this helper after `upsertItems`:
|
||||
|
||||
```typescript
|
||||
async function upsertMarketPrices(
|
||||
globalItemIds: number[],
|
||||
items: CatalogItem[],
|
||||
): Promise<void> {
|
||||
for (let i = 0; i < globalItemIds.length; i++) {
|
||||
const item = items[i];
|
||||
const globalItemId = globalItemIds[i];
|
||||
if (!item?.priceCents || !globalItemId) continue;
|
||||
|
||||
// Derive market from currency
|
||||
const market = item.priceCurrency === "EUR" ? "EU"
|
||||
: item.priceCurrency === "USD" ? "US"
|
||||
: item.priceCurrency === "GBP" ? "GB"
|
||||
: item.priceCurrency;
|
||||
|
||||
await fetch(`${GEARBOX_URL}/api/global-items/${globalItemId}/market-prices`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
"X-API-Key": GEARBOX_API_KEY,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
market,
|
||||
currency: item.priceCurrency,
|
||||
priceCents: item.priceCents,
|
||||
source: "manufacturer-crawl",
|
||||
}),
|
||||
});
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Call `upsertMarketPrices` in `main()` after the bulk upsert, passing the item IDs from the API response.
|
||||
|
||||
Note: The bulk upsert response returns `items[]` with IDs. Store those and pass them here. Update the `upsertItems` function return type to also return `itemIds: number[]`.
|
||||
|
||||
- [ ] **Step 4: Commit**
|
||||
- [ ] **Step 3: Commit**
|
||||
|
||||
```bash
|
||||
git add scripts/crawl-manufacturer.ts
|
||||
|
||||
Reference in New Issue
Block a user