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:
clucraft 2026-01-22 14:23:55 -05:00
parent 4928d6b9d3
commit 6c2aece1e8
8 changed files with 528 additions and 6 deletions

View file

@ -122,6 +122,31 @@ export const pricesApi = {
),
};
// Stock Status History API
export interface StockStatusHistoryEntry {
id: number;
product_id: number;
status: StockStatus;
changed_at: string;
}
export interface StockStatusStats {
availability_percent: number;
outage_count: number;
avg_outage_days: number | null;
longest_outage_days: number | null;
current_status: StockStatus;
days_in_current_status: number;
}
export const stockHistoryApi = {
getHistory: (productId: number, days?: number) =>
api.get<{ history: StockStatusHistoryEntry[]; stats: StockStatusStats | null }>(
`/products/${productId}/stock-history`,
{ params: days ? { days } : undefined }
),
};
// Settings API
export interface NotificationSettings {
telegram_configured: boolean;