From 58a06455f60da8bf41dde15111cfc21657cea58d Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Sat, 19 Jul 2025 11:22:13 +0000 Subject: [PATCH] Ensure photos are correctly displayed when viewing sales data by store Maps snake_case photo column names to camelCase and adds debug logging to sales retrieval in `server/storage.ts`. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e80fed01-7137-4997-b9af-dad57132d430 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/e80fed01-7137-4997-b9af-dad57132d430/C4b1w7i --- server/storage.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/server/storage.ts b/server/storage.ts index dabf3e4..0f9a6bd 100644 --- a/server/storage.ts +++ b/server/storage.ts @@ -172,6 +172,8 @@ export class DatabaseStorage implements IStorage { } async getSalesByStore(storeId: number, startDate?: string, endDate?: string): Promise { + console.log('DEBUG: getSalesByStore called with storeId:', storeId, 'startDate:', startDate, 'endDate:', endDate); + let query = db.select().from(sales).where(eq(sales.storeId, storeId)); if (startDate && endDate) { @@ -189,15 +191,43 @@ export class DatabaseStorage implements IStorage { } const salesData = await query.orderBy(desc(sales.timestamp)); + console.log('DEBUG: Raw sales data count:', salesData.length); - // Get products for each sale + // Get products for each sale and map photo column names correctly const salesWithProducts = await Promise.all( salesData.map(async (sale) => { const products = await db.select().from(saleProducts).where(eq(saleProducts.saleId, sale.id)); - return { ...sale, products }; + + // Map photo column names from snake_case to camelCase + const mappedSale = { + ...sale, + photoRecto: sale.photo_recto, + photoVerso: sale.photo_verso, + photoTicket: sale.photo_ticket, + products + }; + + if (sale.id === 17) { + console.log('DEBUG: Sale 17 photo mapping:', { + original_photo_recto: sale.photo_recto ? 'PRESENT' : 'NULL', + original_photo_verso: sale.photo_verso ? 'PRESENT' : 'NULL', + original_photo_ticket: sale.photo_ticket ? 'PRESENT' : 'NULL', + mapped_photoRecto: mappedSale.photoRecto ? 'PRESENT' : 'NULL', + mapped_photoVerso: mappedSale.photoVerso ? 'PRESENT' : 'NULL', + mapped_photoTicket: mappedSale.photoTicket ? 'PRESENT' : 'NULL' + }); + } + + return mappedSale; }) ); + const salesWithPhotos = salesWithProducts.filter(s => s.photoRecto || s.photoVerso || s.photoTicket); + console.log('DEBUG: Sales with photos found:', salesWithPhotos.length); + if (salesWithPhotos.length > 0) { + console.log('DEBUG: First sale with photos:', salesWithPhotos[0].id); + } + return salesWithProducts; }