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

+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> {