From 05f4de86d3605ed932e83cd3dc0342c3279911d9 Mon Sep 17 00:00:00 2001 From: Kelly Date: Wed, 3 Dec 2025 21:09:37 -0700 Subject: [PATCH] Fix detection query to include dutchie stores missing platform_id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When onlyUnknown=true and onlyMissingPlatformId=true, the query now uses OR logic instead of AND to include: - Stores with unknown menu_type (new stores needing detection) - Stores with menu_type='dutchie' but no platform_dispensary_id This allows re-detection to: 1. Resolve platform IDs for actual Dutchie stores 2. Reclassify stores that migrated away from Dutchie (e.g. to Curaleaf) Also changed default for onlyMissingPlatformId to true so scheduled detection jobs always attempt to resolve missing platform IDs. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- .../src/dutchie-az/services/menu-detection.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/src/dutchie-az/services/menu-detection.ts b/backend/src/dutchie-az/services/menu-detection.ts index 74f32add..18ff23c9 100644 --- a/backend/src/dutchie-az/services/menu-detection.ts +++ b/backend/src/dutchie-az/services/menu-detection.ts @@ -816,11 +816,16 @@ export async function runBulkDetection(options: { params.push(state); } - if (onlyUnknown) { + // Handle the combination of onlyUnknown and onlyMissingPlatformId + // If both are set, include: unknown menu_type OR (dutchie without platform_id) + if (onlyUnknown && onlyMissingPlatformId) { + whereClause += ` AND ( + (menu_type IS NULL OR menu_type = '' OR menu_type = 'unknown') + OR (menu_type = 'dutchie' AND platform_dispensary_id IS NULL) + )`; + } else if (onlyUnknown) { whereClause += ` AND (menu_type IS NULL OR menu_type = '' OR menu_type = 'unknown')`; - } - - if (onlyMissingPlatformId) { + } else if (onlyMissingPlatformId) { whereClause += ` AND (menu_type = 'dutchie' AND platform_dispensary_id IS NULL)`; } @@ -892,7 +897,8 @@ export async function executeMenuDetectionJob(config: Record = {}): }> { const state = config.state || 'AZ'; const onlyUnknown = config.onlyUnknown !== false; - const onlyMissingPlatformId = config.onlyMissingPlatformId || false; + // Default to true - always try to resolve platform IDs for dutchie stores + const onlyMissingPlatformId = config.onlyMissingPlatformId !== false; console.log(`[MenuDetection] Executing scheduled job for state=${state}...`);