mirror of
https://github.com/clucraft/PriceGhost.git
synced 2026-05-07 06:42:40 +02:00
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:
parent
bf111e13d8
commit
8c5d20707d
9 changed files with 274 additions and 44 deletions
|
|
@ -35,6 +35,8 @@ export const userQueries = {
|
|||
};
|
||||
|
||||
// Product types and queries
|
||||
export type StockStatus = 'in_stock' | 'out_of_stock' | 'unknown';
|
||||
|
||||
export interface Product {
|
||||
id: number;
|
||||
user_id: number;
|
||||
|
|
@ -43,6 +45,7 @@ export interface Product {
|
|||
image_url: string | null;
|
||||
refresh_interval: number;
|
||||
last_checked: Date | null;
|
||||
stock_status: StockStatus;
|
||||
created_at: Date;
|
||||
}
|
||||
|
||||
|
|
@ -159,13 +162,14 @@ export const productQueries = {
|
|||
url: string,
|
||||
name: string | null,
|
||||
imageUrl: string | null,
|
||||
refreshInterval: number = 3600
|
||||
refreshInterval: number = 3600,
|
||||
stockStatus: StockStatus = 'unknown'
|
||||
): Promise<Product> => {
|
||||
const result = await pool.query(
|
||||
`INSERT INTO products (user_id, url, name, image_url, refresh_interval)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
`INSERT INTO products (user_id, url, name, image_url, refresh_interval, stock_status)
|
||||
VALUES ($1, $2, $3, $4, $5, $6)
|
||||
RETURNING *`,
|
||||
[userId, url, name, imageUrl, refreshInterval]
|
||||
[userId, url, name, imageUrl, refreshInterval, stockStatus]
|
||||
);
|
||||
return result.rows[0];
|
||||
},
|
||||
|
|
@ -215,6 +219,13 @@ export const productQueries = {
|
|||
);
|
||||
},
|
||||
|
||||
updateStockStatus: async (id: number, stockStatus: StockStatus): Promise<void> => {
|
||||
await pool.query(
|
||||
'UPDATE products SET stock_status = $1 WHERE id = $2',
|
||||
[stockStatus, id]
|
||||
);
|
||||
},
|
||||
|
||||
findDueForRefresh: async (): Promise<Product[]> => {
|
||||
const result = await pool.query(
|
||||
`SELECT * FROM products
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue