Add out-of-stock detection and display

- Add stock_status column to products table (in_stock/out_of_stock/unknown)
- Detect out-of-stock status on Amazon by checking:
  - #availability text for "currently unavailable"
  - #outOfStock element presence
  - Missing "Add to Cart" button
- Add generic stock status detection for other sites
- Allow adding out-of-stock products (they just won't have a price)
- Update background scheduler to track stock status changes
- Display stock status badge in product list and detail pages
- Dim out-of-stock products in the dashboard
- Show "Currently Unavailable" badge instead of price when out of stock

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
clucraft 2026-01-20 20:54:12 -05:00
parent bf111e13d8
commit 8c5d20707d
9 changed files with 274 additions and 44 deletions

View file

@ -42,28 +42,32 @@ router.post('/', async (req: AuthRequest, res: Response) => {
// Scrape product info
const scrapedData = await scrapeProduct(url);
if (!scrapedData.price) {
// Allow adding out-of-stock products, but require a price for in-stock ones
if (!scrapedData.price && scrapedData.stockStatus !== 'out_of_stock') {
res.status(400).json({
error: 'Could not extract price from the provided URL',
});
return;
}
// Create product
// Create product with stock status
const product = await productQueries.create(
userId,
url,
scrapedData.name,
scrapedData.imageUrl,
refresh_interval || 3600
refresh_interval || 3600,
scrapedData.stockStatus
);
// Record initial price
await priceHistoryQueries.create(
product.id,
scrapedData.price.price,
scrapedData.price.currency
);
// Record initial price if available
if (scrapedData.price) {
await priceHistoryQueries.create(
product.id,
scrapedData.price.price,
scrapedData.price.currency
);
}
// Update last_checked timestamp
await productQueries.updateLastChecked(product.id);