[bugfix] remove leading zeros from number
This commit is contained in:
@@ -219,7 +219,7 @@ from (
|
||||
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name,
|
||||
coalesce(o.rarity_name, t.rarity_name) as rarity_name, coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id,
|
||||
coalesce(o.card_type, t.card_type) as card_type, coalesce(o.energy_type, t.energy_type) as energy_type,
|
||||
coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
|
||||
coalesce(o.number, regexp_replace(t.number,'^0+','')) as number, coalesce(o.artist, t.artist) as artist
|
||||
from tcg_cards t
|
||||
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
||||
left join tcg_overrides o on t.product_id = o.product_id
|
||||
@@ -239,7 +239,7 @@ select t.product_id, b.variant,
|
||||
coalesce(o.product_name, regexp_replace(regexp_replace(coalesce(nullif(t.product_name, ''), t.product_url_name),' \\\\(.*\\\\)',''),' - .*$','')) as product_name,
|
||||
coalesce(o.product_line_name, t.product_line_name) as product_line_name, coalesce(o.product_url_name, t.product_url_name) as product_url_name, coalesce(o.rarity_name, t.rarity_name) as rarity_name,
|
||||
coalesce(o.sealed, t.sealed) as sealed, coalesce(o.set_id, t.set_id) as set_id, coalesce(o.card_type, t.card_type) as card_type,
|
||||
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, t.number) as number, coalesce(o.artist, t.artist) as artist
|
||||
coalesce(o.energy_type, t.energy_type) as energy_type, coalesce(o.number, regexp_replace(t.number,'^0+','')) as number, coalesce(o.artist, t.artist) as artist
|
||||
from tcg_cards t
|
||||
join (select distinct product_id, variant from skus) b on t.product_id = b.product_id
|
||||
left join tcg_overrides o on t.product_id = o.product_id
|
||||
|
||||
@@ -76,11 +76,30 @@ const syncProductLine = async (
|
||||
|
||||
log(` - ${item.productName} (ID: ${item.productId})`);
|
||||
|
||||
const detailResponse = await fetch(`https://mp-search-api.tcgplayer.com/v2/product/${item.productId}/details`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (!detailResponse.ok) {
|
||||
throw new Error(`Error fetching product details for ${item.productId}: ${detailResponse.statusText}`);
|
||||
let detailResponse: Response | null = null;
|
||||
let lastError: unknown = null;
|
||||
for (let attempt = 1; attempt <= 3; attempt++) {
|
||||
try {
|
||||
const r = await fetch(`https://mp-search-api.tcgplayer.com/v2/product/${item.productId}/details`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (r.ok) {
|
||||
detailResponse = r;
|
||||
break;
|
||||
}
|
||||
lastError = new Error(`Error fetching product details for ${item.productId}: ${r.statusText}`);
|
||||
} catch (err) {
|
||||
lastError = err;
|
||||
}
|
||||
if (attempt < 3) {
|
||||
log(` retry ${attempt}/2 for product ${item.productId} in 5s...`);
|
||||
await helper.Sleep(5000);
|
||||
}
|
||||
}
|
||||
if (!detailResponse) {
|
||||
throw lastError instanceof Error
|
||||
? lastError
|
||||
: new Error(`Error fetching product details for ${item.productId}: ${String(lastError)}`);
|
||||
}
|
||||
const detailData = await detailResponse.json();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user