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
This commit is contained in:
michaelschal committed 2025-08-12 15:19:40 +00:00
1 parent c419733954
commit 78f4c36515
3 files changed
+114 -17

No files matched your search

+15 -5
View File
@@ -2019,15 +2019,18 @@ RÉSUMÉ DU SCAN
console.log("Backend data mapped:", backendData);
// REMOVED: All role restrictions - tous les rôles peuvent créer des commandes client
console.log("Creating customer order - no role restrictions:", {
console.log("🔍 PRODUCTION DEBUG - Creating customer order with data:", {
userId,
userRole: user.role,
userGroups: user.userGroups?.map(ug => ({groupId: ug.groupId, groupName: ug.group?.name})),
originalGroupId: req.body.groupId,
finalGroupId: backendData.groupId
finalGroupId: backendData.groupId,
backendDataGroupId: backendData.groupId
});
console.log("🔍 PRODUCTION DEBUG - Calling storage.createCustomerOrder with groupId:", backendData.groupId);
const customerOrder = await storage.createCustomerOrder(backendData);
console.log("🔍 PRODUCTION DEBUG - Customer order created with groupId:", customerOrder.groupId, "- Should be:", finalGroupId);
res.status(201).json(customerOrder);
} catch (error) {
console.error("Error creating customer order:", error);
@@ -2406,15 +2409,22 @@ RÉSUMÉ DU SCAN
combined: { ...req.body, createdBy: userId, groupId: finalGroupId }
});
const validatedData = insertDlcProductFrontendSchema.parse({
const dataToValidate = {
...req.body,
createdBy: userId,
groupId: finalGroupId,
});
};
console.log("🔍 PRODUCTION DEBUG - Data before validation:", dataToValidate);
const validatedData = insertDlcProductFrontendSchema.parse(dataToValidate);
console.log("✅ Post-validation data:", validatedData);
console.log("✅ PRODUCTION DEBUG - Post-validation data:", validatedData);
console.log("🔍 PRODUCTION DEBUG - GroupId after validation:", validatedData.groupId, typeof validatedData.groupId);
console.log("🔍 PRODUCTION DEBUG - Calling storage.createDlcProduct with groupId:", validatedData.groupId);
const dlcProduct = await storage.createDlcProduct(validatedData);
console.log("🔍 PRODUCTION DEBUG - DLC created with groupId:", dlcProduct.groupId, "- Should be:", finalGroupId);
console.log("📦 Raw returned DLC product:", dlcProduct);
console.log('✅ DLC Product created successfully:', {
id: dlcProduct.id,
+33 -12
View File
@@ -1252,14 +1252,23 @@ export class DatabaseStorage implements IStorage {
}
async createCustomerOrder(customerOrderData: InsertCustomerOrder): Promise<CustomerOrder> {
const insertData = {
...customerOrderData,
createdAt: new Date(),
updatedAt: new Date(),
};
console.log("🔍 STORAGE DEBUG - Customer Order insertData:", insertData);
console.log("🔍 STORAGE DEBUG - Customer Order insertData.groupId:", insertData.groupId, typeof insertData.groupId);
const [customerOrder] = await db
.insert(customerOrders)
.values({
...customerOrderData,
createdAt: new Date(),
updatedAt: new Date(),
})
.values(insertData)
.returning();
console.log("🔍 STORAGE DEBUG - Customer Order returned from DB:", customerOrder);
console.log("🔍 STORAGE DEBUG - Customer Order returned groupId:", customerOrder.groupId, typeof customerOrder.groupId);
return customerOrder;
}
@@ -1471,21 +1480,33 @@ export class DatabaseStorage implements IStorage {
async createDlcProduct(dlcProductData: InsertDlcProductFrontend): Promise<DlcProductFrontend> {
// Convert dlcDate to expiryDate for Drizzle schema compatibility
const { dlcDate, ...restData } = dlcProductData as any;
const insertData = {
...restData,
expiryDate: dlcDate,
createdAt: new Date(),
updatedAt: new Date(),
};
console.log("🔍 STORAGE DEBUG - DLC insertData:", insertData);
console.log("🔍 STORAGE DEBUG - DLC insertData.groupId:", insertData.groupId, typeof insertData.groupId);
const [dlcProduct] = await db
.insert(dlcProducts)
.values({
...restData,
expiryDate: dlcDate,
createdAt: new Date(),
updatedAt: new Date(),
})
.values(insertData)
.returning();
console.log("🔍 STORAGE DEBUG - DLC returned from DB:", dlcProduct);
console.log("🔍 STORAGE DEBUG - DLC returned groupId:", dlcProduct.groupId, typeof dlcProduct.groupId);
// Return with dlcDate field for frontend compatibility
return {
const result = {
...dlcProduct,
dlcDate: dlcProduct.expiryDate,
} as any;
console.log("🔍 STORAGE DEBUG - DLC final result:", result);
return result;
}
async updateDlcProduct(id: number, dlcProductData: Partial<InsertDlcProductFrontend>): Promise<DlcProductFrontend> {