Skip to content

Commit f299f4c

Browse files
committed
Fix Steam inventory sync bugs - use market_name and lowestPrice
- Fix bug using item.name instead of item.market_name (was storing 'AK-47' instead of 'AK-47 | Redline (FT)') - Fix bug using cachedPrice.price instead of cachedPrice.lowestPrice - Add duplicate item checking before insert - Add logging for better debugging - Skip non-weapon items (stickers, cases) automatically - Show detailed error messages for each failed item
1 parent 3da57f3 commit f299f4c

1 file changed

Lines changed: 29 additions & 5 deletions

File tree

index.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4100,13 +4100,35 @@ app.post('/api/steam/inventory/sync', requireAuth, async (req, res) => {
41004100
// Add each item to portfolio
41014101
for (const item of itemsToSync) {
41024102
try {
4103+
// Skip non-weapon items (stickers, cases, etc.) if they have no wear
4104+
if (!item.wear_full && item.weapon_type !== 'Knife' && item.weapon_type !== 'Gloves') {
4105+
winston.debug(`Skipping non-weapon item: ${item.market_name}`);
4106+
continue;
4107+
}
4108+
41034109
// Get market price
41044110
let price = 0;
41054111
if (item.marketable && item.market_hash_name) {
41064112
const cachedPrice = await postgres.getCachedPrice(item.market_hash_name);
4107-
price = cachedPrice?.price || 0;
4113+
price = cachedPrice?.lowestPrice || 0;
4114+
}
4115+
4116+
// Check for duplicates
4117+
const duplicateCheck = await postgres.pool.query(`
4118+
SELECT id FROM portfolio_investments
4119+
WHERE user_steam_id = $1 AND item_name = $2 AND is_sold = false
4120+
LIMIT 1
4121+
`, [steamId, item.market_name]);
4122+
4123+
if (duplicateCheck.rows.length > 0) {
4124+
winston.debug(`Skipping duplicate item: ${item.market_name}`);
4125+
errors.push({
4126+
item: item.market_name,
4127+
error: 'Item already exists in portfolio'
4128+
});
4129+
continue;
41084130
}
4109-
4131+
41104132
// Insert into portfolio
41114133
await postgres.pool.query(`
41124134
INSERT INTO portfolio_investments (
@@ -4116,18 +4138,20 @@ app.post('/api/steam/inventory/sync', requireAuth, async (req, res) => {
41164138
`, [
41174139
'steam_' + steamId,
41184140
steamId,
4119-
item.name,
4141+
item.market_name,
41204142
price,
41214143
1,
41224144
'Steam',
41234145
item.is_stattrak || false,
41244146
'Imported from Steam inventory'
41254147
]);
4126-
4148+
4149+
winston.info(`Added to portfolio: ${item.market_name} - $${price}`);
41274150
added++;
41284151
} catch (error) {
4152+
winston.error(`Error adding ${item.market_name}:`, error);
41294153
errors.push({
4130-
item: item.name,
4154+
item: item.market_name,
41314155
error: error.message
41324156
});
41334157
}

0 commit comments

Comments
 (0)