Files
LogiFlow/PRODUCTION-STORAGE-DEBUG-URGENT.md
T
michaelschal 78f4c36515 Fix issue where customer orders and DLCs are incorrectly assigned to the wrong store
Add extensive logging to the storage layer and backend routes to diagnose and resolve an issue where customer orders and DLC products are being assigned to store #1 instead of the intended store #2, even when created by users associated with store #2. This includes detailed console logs within the `createCustomerOrder` and `createDlcProduct` functions in both the routes and storage layers, focusing on the `groupId` before and after database operations.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: b163d4c0-de5e-4f4e-a9c0-aed4c7049718
Replit-Commit-Checkpoint-Type: full_checkpoint
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/b163d4c0-de5e-4f4e-a9c0-aed4c7049718/32z3sin
2025-08-12 15:19:40 +00:00

2.2 KiB

Debug Production Storage - GroupId Mystery

Problème Production

Utilisateur assigné magasin #2 crée DLC/commandes → apparaît magasin #1

Analyse Couche Storage

Il y a 2 implémentations storage :

1. MemStorage (Développement)

async createDlcProduct(dlcProduct: any): Promise<any> { 
    const newProduct = { id, ...dlcProduct, createdAt, updatedAt };
    // Enregistre directement les données passées
}

2. Drizzle ORM (Production)

async createDlcProduct(dlcProductData: InsertDlcProductFrontend): Promise<DlcProductFrontend> {
    const { dlcDate, ...restData } = dlcProductData as any;
    const [dlcProduct] = await db.insert(dlcProducts).values({
        ...restData, // ⚠️ SI restData.groupId = 1, il sera enregistré tel quel
        expiryDate: dlcDate,
    });
}

Hypothèses du Problème

  1. Frontend envoie groupId: 1 malgré les corrections
  2. Backend force finalGroupId: 2 mais quelque chose le rechange
  3. Storage reçoit groupId: 1 et l'enregistre tel quel
  4. Base de données a une contrainte/trigger qui force groupId: 1

Debug Ajouté

1. Logs Storage Drizzle (Production)

console.log("🔍 STORAGE DEBUG - DLC insertData:", insertData);
console.log("🔍 STORAGE DEBUG - DLC insertData.groupId:", insertData.groupId, typeof insertData.groupId);
console.log("🔍 STORAGE DEBUG - DLC returned from DB:", dlcProduct);
console.log("🔍 STORAGE DEBUG - DLC returned groupId:", dlcProduct.groupId, typeof dlcProduct.groupId);

2. Même Logs pour Customer Orders

Plan de Debug Production

  1. ✅ Logs routse backend - Voir finalGroupId calculé
  2. ✅ Logs storage layer - Voir données envoyées à DB
  3. ✅ Logs retour DB - Voir ce que la DB retourne
  4. 🔄 Déployer en production
  5. 🧪 Tester création DLC/commande avec employé magasin #2
  6. 📋 Analyser logs complets pour identifier où groupId change

Résultat Attendu

Les logs révéleront :

  • Frontend calcule-t-il groupId: 2 ?
  • Backend force-t-il finalGroupId: 2 ?
  • Storage reçoit-il groupId: 2 ?
  • DB retourne-t-elle groupId: 1 ou 2 ?

POINT DE RUPTURE IDENTIFIÉ = PROBLÈME RÉSOLU