[chore] price sync updates index

This commit is contained in:
2026-03-03 07:59:44 -05:00
parent 1f521afa3a
commit 11dfcd38c1
2 changed files with 87 additions and 58 deletions

View File

@@ -130,10 +130,10 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
for (const item of data.results[0].results) {
// Check if productId already exists and skip if it does (to avoid hitting the API too much)
if (allProductIds.has(item.productId)) {
continue;
}
// // Check if productId already exists and skip if it does (to avoid hitting the API too much)
// if (allProductIds.has(item.productId)) {
// continue;
// }
console.log(chalk.blue(` - ${item.productName} (ID: ${item.productId})`));
@@ -150,76 +150,76 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
await db.insert(schema.tcgcards).values({
productId: item.productId,
productName: item.productName,
productName: detailData.productName,
//productName: cleanProductName(item.productName),
rarityName: item.rarityName,
productLineName: item.productLineName,
productLineUrlName: item.productLineUrlName,
productStatusId: item.productStatusId,
productTypeId: item.productTypeId,
productUrlName: item.productUrlName,
setId: item.setId,
shippingCategoryId: item.shippingCategoryId,
sealed: item.sealed,
sellerListable: item.sellerListable,
foilOnly: item.foilOnly,
productLineName: detailData.productLineName,
productLineUrlName: detailData.productLineUrlName,
productStatusId: detailData.productStatusId,
productTypeId: detailData.productTypeId,
productUrlName: detailData.productUrlName,
setId: detailData.setId,
shippingCategoryId: detailData.shippingCategoryId,
sealed: detailData.sealed,
sellerListable: detailData.sellerListable,
foilOnly: detailData.foilOnly,
attack1: item.customAttributes.attack1 || null,
attack2: item.customAttributes.attack2 || null,
attack3: item.customAttributes.attack3 || null,
attack4: item.customAttributes.attack4 || null,
cardType: item.customAttributes.cardType?.[0] || null,
cardTypeB: item.customAttributes.cardTypeB || null,
energyType: item.customAttributes.energyType?.[0] || null,
flavorText: item.customAttributes.flavorText || null,
energyType: detailData.customAttributes.energyType?.[0] || null,
flavorText: detailData.customAttributes.flavorText || null,
hp: getNumberOrNull(item.customAttributes.hp),
number: item.customAttributes.number || '',
releaseDate: item.customAttributes.releaseDate ? new Date(item.customAttributes.releaseDate) : null,
number: detailData.customAttributes.number || '',
releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null,
resistance: item.customAttributes.resistance || null,
retreatCost: item.customAttributes.retreatCost || null,
stage: item.customAttributes.stage || null,
weakness: item.customAttributes.weakness || null,
lowestPrice: item.lowestPrice,
lowestPriceWithShipping: item.lowestPriceWithShipping,
marketPrice: item.marketPrice,
maxFulfillableQuantity: item.maxFulfillableQuantity,
medianPrice: item.medianPrice,
lowestPrice: detailData.lowestPrice,
lowestPriceWithShipping: detailData.lowestPriceWithShipping,
marketPrice: detailData.marketPrice,
maxFulfillableQuantity: detailData.maxFulfillableQuantity,
medianPrice: detailData.medianPrice,
totalListings: item.totalListings,
Artist: detailData.formattedAttributes.Artist || null,
}).onDuplicateKeyUpdate({
set: {
productName: item.productName,
productName: detailData.productName,
//productName: cleanProductName(item.productName),
rarityName: item.rarityName,
productLineName: item.productLineName,
productLineUrlName: item.productLineUrlName,
productStatusId: item.productStatusId,
productTypeId: item.productTypeId,
productUrlName: item.productUrlName,
setId: item.setId,
shippingCategoryId: item.shippingCategoryId,
sealed: item.sealed,
sellerListable: item.sellerListable,
foilOnly: item.foilOnly,
productLineName: detailData.productLineName,
productLineUrlName: detailData.productLineUrlName,
productStatusId: detailData.productStatusId,
productTypeId: detailData.productTypeId,
productUrlName: detailData.productUrlName,
setId: detailData.setId,
shippingCategoryId: detailData.shippingCategoryId,
sealed: detailData.sealed,
sellerListable: detailData.sellerListable,
foilOnly: detailData.foilOnly,
attack1: item.customAttributes.attack1 || null,
attack2: item.customAttributes.attack2 || null,
attack3: item.customAttributes.attack3 || null,
attack4: item.customAttributes.attack4 || null,
cardType: item.customAttributes.cardType?.[0] || null,
cardTypeB: item.customAttributes.cardTypeB || null,
energyType: item.customAttributes.energyType?.[0] || null,
flavorText: item.customAttributes.flavorText || null,
energyType: detailData.customAttributes.energyType?.[0] || null,
flavorText: detailData.customAttributes.flavorText || null,
hp: getNumberOrNull(item.customAttributes.hp),
number: item.customAttributes.number || '',
releaseDate: item.customAttributes.releaseDate ? new Date(item.customAttributes.releaseDate) : null,
number: detailData.customAttributes.number || '',
releaseDate: detailData.customAttributes.releaseDate ? new Date(detailData.customAttributes.releaseDate) : null,
resistance: item.customAttributes.resistance || null,
retreatCost: item.customAttributes.retreatCost || null,
stage: item.customAttributes.stage || null,
weakness: item.customAttributes.weakness || null,
lowestPrice: item.lowestPrice,
lowestPriceWithShipping: item.lowestPriceWithShipping,
marketPrice: item.marketPrice,
maxFulfillableQuantity: item.maxFulfillableQuantity,
medianPrice: item.medianPrice,
lowestPrice: detailData.lowestPrice,
lowestPriceWithShipping: detailData.lowestPriceWithShipping,
marketPrice: detailData.marketPrice,
maxFulfillableQuantity: detailData.maxFulfillableQuantity,
medianPrice: detailData.medianPrice,
totalListings: item.totalListings,
Artist: detailData.formattedAttributes.Artist || null,
},
@@ -272,7 +272,7 @@ async function syncProductLine(productLine: string, field: string, fieldValue: s
}
// be nice to the API and not send too many requests in a short time
await sleep(100);
await sleep(300);
}