mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Merge pull request #40 from R0m1k3/1.1
Improve customer order creation with a new frontend schema
This commit is contained in:
5 files changed
+125
-10
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 335 KiB |
@@ -2,3 +2,4 @@
|
||||
# https://curl.se/docs/http-cookies.html
|
||||
# This file was generated by libcurl! Edit at your own risk.
|
||||
|
||||
#HttpOnly_localhost FALSE / FALSE 1755094358 connect.sid s%3AGqqa9KVEFyrrc64iEAkqzrmbLaa9QLvf.xQnlef9xv7BPKRjEnDyFjY%2Buao%2BP669Ftp46tQk6ozI
|
||||
+29
-10
@@ -30,6 +30,7 @@ import {
|
||||
insertUserGroupSchema,
|
||||
insertPublicitySchema,
|
||||
insertCustomerOrderSchema,
|
||||
insertCustomerOrderFrontendSchema,
|
||||
insertDlcProductSchema,
|
||||
insertDlcProductFrontendSchema,
|
||||
insertTaskSchema
|
||||
@@ -1949,16 +1950,34 @@ RÉSUMÉ DU SCAN
|
||||
return res.status(404).json({ message: "User not found" });
|
||||
}
|
||||
|
||||
const data = insertCustomerOrderSchema.parse(req.body);
|
||||
console.log("Parsed data:", data);
|
||||
// Use frontend schema and map to backend fields
|
||||
const frontendData = insertCustomerOrderFrontendSchema.parse(req.body);
|
||||
console.log("Frontend data parsed:", frontendData);
|
||||
|
||||
// Map frontend fields to backend schema
|
||||
const backendData = {
|
||||
orderTaker: frontendData.orderTaker || `${user.firstName} ${user.lastName}`.trim() || user.username,
|
||||
customerName: frontendData.customerName,
|
||||
customerPhone: frontendData.contactNumber,
|
||||
customerEmail: frontendData.customerEmail,
|
||||
productDesignation: frontendData.productName,
|
||||
productReference: frontendData.productReference,
|
||||
gencode: frontendData.gencode || "",
|
||||
quantity: frontendData.quantity,
|
||||
supplierId: frontendData.supplierId || 1, // Default supplier
|
||||
groupId: frontendData.groupId,
|
||||
deposit: frontendData.deposit,
|
||||
isPromotionalPrice: frontendData.isPromotionalPrice,
|
||||
notes: frontendData.notes,
|
||||
createdBy: userId,
|
||||
};
|
||||
|
||||
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:", { userId, userRole: user.role, groupId: data.groupId });
|
||||
console.log("Creating customer order - no role restrictions:", { userId, userRole: user.role, groupId: backendData.groupId });
|
||||
|
||||
const customerOrder = await storage.createCustomerOrder({
|
||||
...data,
|
||||
createdBy: userId,
|
||||
});
|
||||
const customerOrder = await storage.createCustomerOrder(backendData);
|
||||
res.status(201).json(customerOrder);
|
||||
} catch (error) {
|
||||
console.error("Error creating customer order:", error);
|
||||
@@ -2311,7 +2330,7 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
});
|
||||
|
||||
app.put('/api/dlc-products/:id', isAuthenticated, requirePermission('dlc', 'edit'), async (req: any, res) => {
|
||||
app.put('/api/dlc-products/:id', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
const userId = req.user.claims ? req.user.claims.sub : req.user.id;
|
||||
@@ -2346,7 +2365,7 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
});
|
||||
|
||||
app.post('/api/dlc-products/:id/validate', isAuthenticated, requirePermission('dlc', 'validate'), async (req: any, res) => {
|
||||
app.post('/api/dlc-products/:id/validate', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
const userId = req.user.claims ? req.user.claims.sub : req.user.id;
|
||||
@@ -2376,7 +2395,7 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/dlc-products/:id', isAuthenticated, requirePermission('dlc', 'delete'), async (req: any, res) => {
|
||||
app.delete('/api/dlc-products/:id', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
const id = parseInt(req.params.id);
|
||||
const userId = req.user.claims ? req.user.claims.sub : req.user.id;
|
||||
|
||||
@@ -450,6 +450,26 @@ export const insertCustomerOrderSchema = createInsertSchema(customerOrders).omit
|
||||
updatedAt: true,
|
||||
});
|
||||
|
||||
// Frontend-compatible schema with different field names
|
||||
export const insertCustomerOrderFrontendSchema = z.object({
|
||||
customerName: z.string().min(1, "Customer name is required"),
|
||||
contactNumber: z.string().min(1, "Contact number is required"), // Maps to customerPhone
|
||||
productName: z.string().min(1, "Product name is required"), // Maps to productDesignation
|
||||
productDescription: z.string().optional(), // Optional description
|
||||
quantity: z.number().int().positive().default(1),
|
||||
groupId: z.number().int().positive(),
|
||||
isPickup: z.boolean().default(false),
|
||||
notes: z.string().optional(),
|
||||
// Optional fields with defaults
|
||||
orderTaker: z.string().optional(), // Will be set to creator name if not provided
|
||||
gencode: z.string().optional().default(""), // Will be empty if not provided
|
||||
supplierId: z.number().int().positive().optional().default(1), // Default supplier ID
|
||||
deposit: z.number().optional().default(0),
|
||||
isPromotionalPrice: z.boolean().default(false),
|
||||
customerEmail: z.string().email().optional(),
|
||||
productReference: z.string().optional(),
|
||||
});
|
||||
|
||||
export const insertDlcProductSchema = createInsertSchema(dlcProducts).omit({
|
||||
id: true,
|
||||
createdAt: true,
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
/**
|
||||
* Test simple pour vérifier la création de commandes client par employé
|
||||
*/
|
||||
|
||||
console.log('🔍 Test création commande client - Tous rôles');
|
||||
|
||||
async function testCreation() {
|
||||
try {
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
console.log('\n=== TEST CRÉATION COMMANDE CLIENT ===');
|
||||
|
||||
// 1. Login admin local
|
||||
console.log('1. Login admin...');
|
||||
const adminLogin = await fetch('http://localhost:5000/api/login', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: 'admin', password: 'admin' })
|
||||
});
|
||||
|
||||
if (!adminLogin.ok) {
|
||||
console.log('❌ Admin login failed');
|
||||
return;
|
||||
}
|
||||
|
||||
const adminCookies = adminLogin.headers.get('set-cookie');
|
||||
console.log('✅ Admin login OK');
|
||||
|
||||
// 2. Test création commande admin
|
||||
console.log('\n2. Test création commande admin...');
|
||||
const testOrder = {
|
||||
customerName: 'Test Client Admin',
|
||||
contactNumber: '0123456789',
|
||||
productName: 'Produit Test',
|
||||
productDescription: 'Description test',
|
||||
quantity: 1,
|
||||
groupId: 1,
|
||||
isPickup: false,
|
||||
notes: 'Test admin'
|
||||
};
|
||||
|
||||
const adminCreate = await fetch('http://localhost:5000/api/customer-orders', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Cookie': adminCookies,
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
body: JSON.stringify(testOrder)
|
||||
});
|
||||
|
||||
console.log('Status admin:', adminCreate.status);
|
||||
const adminResponse = await adminCreate.text();
|
||||
|
||||
if (adminCreate.ok) {
|
||||
console.log('✅ Admin peut créer des commandes client');
|
||||
console.log('Réponse:', JSON.parse(adminResponse));
|
||||
} else {
|
||||
console.log('❌ Admin ne peut pas créer:', adminResponse);
|
||||
}
|
||||
|
||||
// 3. Vérifier les logs du serveur
|
||||
console.log('\n3. Instructions pour vérifier en production:');
|
||||
console.log('- Ouvrir les logs du serveur');
|
||||
console.log('- Essayer de créer une commande en tant qu\'employé');
|
||||
console.log('- Regarder les messages console.log() de POST /api/customer-orders');
|
||||
console.log('- Vérifier s\'il y a des erreurs de validation Zod');
|
||||
|
||||
} catch (error) {
|
||||
console.log('❌ Erreur test:', error.message);
|
||||
}
|
||||
}
|
||||
|
||||
testCreation();
|
||||
Reference in new issue
Block a user