mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-18 13:55:16 +02:00
Add stock status history tracking and timeline visualization
- Create stock_status_history table to track status changes over time - Add stockStatusHistoryQueries with getByProductId, recordChange, getStats - Update scheduler to record status changes - Update product creation and manual refresh to record initial/changed status - Add GET /products/:id/stock-history API endpoint - Create StockTimeline component with: - Visual timeline bar showing in-stock (green) vs out-of-stock (red) - Availability percentage - Outage count and duration stats - Integrate timeline into ProductDetail page Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
4928d6b9d3
commit
6c2aece1e8
8 changed files with 528 additions and 6 deletions
|
|
@ -1,5 +1,5 @@
|
|||
import cron from 'node-cron';
|
||||
import { productQueries, priceHistoryQueries, userQueries } from '../models';
|
||||
import { productQueries, priceHistoryQueries, userQueries, stockStatusHistoryQueries } from '../models';
|
||||
import { scrapeProduct } from './scraper';
|
||||
import { sendNotifications, NotificationPayload } from './notifications';
|
||||
|
||||
|
|
@ -29,9 +29,13 @@ async function checkPrices(): Promise<void> {
|
|||
const wasOutOfStock = product.stock_status === 'out_of_stock';
|
||||
const nowInStock = scrapedData.stockStatus === 'in_stock';
|
||||
|
||||
// Update stock status
|
||||
// Update stock status and record to history
|
||||
if (scrapedData.stockStatus !== product.stock_status) {
|
||||
await productQueries.updateStockStatus(product.id, scrapedData.stockStatus);
|
||||
|
||||
// Record the status change in history
|
||||
await stockStatusHistoryQueries.recordChange(product.id, scrapedData.stockStatus);
|
||||
|
||||
console.log(
|
||||
`Stock status changed for product ${product.id}: ${product.stock_status} -> ${scrapedData.stockStatus}`
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue