Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions backend/src/services/scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,11 @@ async function checkPrices(): Promise<void> {
// Get the latest recorded price to compare
const latestPrice = await priceHistoryQueries.getLatest(product.id);

// Only record if price has changed or it's the first entry
if (!latestPrice || latestPrice.price !== scrapedData.price.price) {
// Only record if price has changed or it's the first entry.
// latestPrice.price comes back from pg as a string (DECIMAL), while
// scrapedData.price.price is a number, so a raw !== is always true;
// coerce first (as the notification checks below already do).
if (!latestPrice || parseFloat(String(latestPrice.price)) !== scrapedData.price.price) {
Comment on lines +108 to +112
// Check for price drop notification before recording
if (latestPrice && product.price_drop_threshold) {
const oldPrice = parseFloat(String(latestPrice.price));
Expand Down