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
This commit is contained in:
michaelschal committed 2025-07-19 11:22:13 +00:00
1 parent 39d409203d
commit 58a06455f6
1 file changed
+32 -2
+32 -2
View File
@@ -172,6 +172,8 @@ export class DatabaseStorage implements IStorage {
}
async getSalesByStore(storeId: number, startDate?: string, endDate?: string): Promise<Sale[]> {
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;
}