Enable support for multiple products within a single sale

Implements multi-product sales functionality by adding a `sale_products` table, updating the sales form, and modifying server-side logic.

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/58t7aEc
This commit is contained in:
michaelschal committed 2025-07-19 10:10:41 +00:00
1 parent 54595e75df
commit e91b8f1a8b
10 files changed
+1303 -50

No files matched your search

+18 -2
View File
@@ -243,9 +243,17 @@ export async function registerRoutes(app: Express): Promise<Server> {
targetStoreId = user.storeId;
}
// Extract products from request body
const { products = [], ...saleFields } = req.body;
// Validate products
if (!Array.isArray(products) || products.length === 0) {
return res.status(400).json({ error: "Au moins un produit est requis" });
}
// Map frontend camelCase to database snake_case for photos
const mappedBody = {
...req.body,
...saleFields,
};
// Add photo fields with proper mapping, only if they exist and are not empty
@@ -270,7 +278,15 @@ export async function registerRoutes(app: Express): Promise<Server> {
userId: user.id
});
const sale = await storage.createSale(saleData);
// Parse and validate products
const validatedProducts = products.map((product: any) => ({
typeArticle: product.typeArticle,
categorie: product.categorie,
quantite: parseInt(product.quantite),
gencode: product.gencode
}));
const sale = await storage.createSaleWithProducts(saleData, validatedProducts);
res.status(201).json(sale);
} catch (error) {
console.error('Create sale error:', error);