From b3eb0644e0849196a17918ab7c1da4664aa8601a Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Mon, 8 Sep 2025 15:20:14 +0000 Subject: [PATCH] Fix issues with creating new entries and improve data validation Update server route error handling and Zod schemas for optional fields to resolve creation errors. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/9fcf4b21-eb0c-4e53-a567-e2ce4a6ad869/p0qYuko --- ...tent-Merci-1757344715388_1757344715388.txt | 204 ++++++++++++++++++ server/routes.ts | 3 +- shared/schema.ts | 4 +- 3 files changed, 208 insertions(+), 3 deletions(-) create mode 100644 attached_assets/Pasted-ctions-id-16-title-Mise-jour-Prix-content-Merci-1757344715388_1757344715388.txt diff --git a/attached_assets/Pasted-ctions-id-16-title-Mise-jour-Prix-content-Merci-1757344715388_1757344715388.txt b/attached_assets/Pasted-ctions-id-16-title-Mise-jour-Prix-content-Merci-1757344715388_1757344715388.txt new file mode 100644 index 0000000..ca56937 --- /dev/null +++ b/attached_assets/Pasted-ctions-id-16-title-Mise-jour-Prix-content-Merci-1757344715388_1757344715388.txt @@ -0,0 +1,204 @@ +ctions + + + + + { + + id: 16, + + title: 'Mise à jour Prix', + + content: 'Merci de mettre vos prix a jour tous les matins, certain magasin ne le font pas.', + + type: 'success', + + storeId: null, + + createdBy: 'admin', + + createdAt: 2025-08-18T10:45:08.585Z + + }, + + { + + id: 8, + + title: 'Bon de Livraison', + + content: 'Lorsque vous rentrez un numéro de bon de livraison, faite le a l identique, même les majuscules. Pour My candy Shop, prendre le numéro de commande.', + + type: 'info', + + storeId: null, + + createdBy: 'admin_local', + + createdAt: 2025-08-07T11:04:38.123Z + + } + +] + +🔍 [PRODUCTION] Looking for user with username: admin + +🔍 [PRODUCTION] Looking for user with username: admin_local + +📋 PUBLICITIES RETURNED: { count: 29 } + +GET /api/publicities 304 in 74ms + +🔍 [PRODUCTION] User search result: Not found + +❌ [PRODUCTION] User not found with username: admin_local + +🔍 [PRODUCTION] User search result: Found + +🎯 [PRODUCTION] Found announcements: 2 + +GET /api/announcements 304 in 86ms + +GET /api/user 304 in 4ms + +Orders API called with: { + + startDate: undefined, + + endDate: undefined, + + storeId: '1', + + userRole: 'admin' + +} + +🔍 Admin orders filtering by store: { storeId: '1', groupIds: [ 1 ], role: 'admin' } + +Fetching all orders + +Deliveries API called with: { + + startDate: undefined, + + endDate: undefined, + + storeId: '1', + + withBL: undefined, + + userRole: 'admin' + +} + +🔍 Admin deliveries filtering by store: { storeId: '1', groupIds: [ 1 ], role: 'admin' } + +Fetching all deliveries + +📢 [SERVER] Fetching announcements for user: admin_local environment: production + +Customer Orders API called with: { groupIds: [ 1 ], userRole: 'admin' } + +📢 [SERVER] User found: { username: 'admin', role: 'admin' } + +🎯 [PRODUCTION] Using PostgreSQL DASHBOARD_MESSAGES table + +🔗 PRODUCTION: getOrders() récupéré 64 commandes avec relations + +Orders returned: 64 items + +GET /api/orders 304 in 115ms + +🔍 [PRODUCTION] Raw messages from DB: 2 items: [ + + { + + id: 16, + + title: 'Mise à jour Prix', + + content: 'Merci de mettre vos prix a jour tous les matins, certain magasin ne le font pas.', + + type: 'success', + + storeId: null, + + createdBy: 'admin', + + createdAt: 2025-08-18T10:45:08.585Z + + }, + + { + + id: 8, + + title: 'Bon de Livraison', + + content: 'Lorsque vous rentrez un numéro de bon de livraison, faite le a l identique, même les majuscules. Pour My candy Shop, prendre le numéro de commande.', + + type: 'info', + + storeId: null, + + createdBy: 'admin_local', + + createdAt: 2025-08-07T11:04:38.123Z + + } + +] + +🔍 [PRODUCTION] Looking for user with username: admin + +🔍 [PRODUCTION] Looking for user with username: admin_local + +Customer Orders returned: 11 items + +GET /api/customer-orders 304 in 147ms + +🔗 PRODUCTION: getDeliveries() récupéré 82 livraisons avec relations + +Deliveries returned: 82 items + +🔍 [PRODUCTION] User search result: Not found + +❌ [PRODUCTION] User not found with username: admin_local + +GET /api/deliveries 304 in 187ms + +🔍 [PRODUCTION] User search result: Found + +🎯 [PRODUCTION] Found announcements: 2 + +GET /api/announcements 304 in 185ms + +GET /api/groups 304 in 140ms + +GET /api/user 304 in 4ms + +GET /api/suppliers 304 in 7ms + +🔍 Avoirs API called with: { groupIds: undefined, userRole: 'admin' } + +📋 Avoirs returned: 0 items + +GET /api/avoirs 304 in 14ms + +🔍 [POST AVOIR] Données reçues: { + + "supplierId": 34, + + "groupId": 1, + + "invoiceReference": "", + + "comment": "", + + "commercialProcessed": false + +} + +🔍 [POST AVOIR] User: { id: 'admin_local', role: 'admin' } + +POST /api/avoirs 400 in 9ms \ No newline at end of file diff --git a/server/routes.ts b/server/routes.ts index f15523f..c096368 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -2471,9 +2471,10 @@ export async function registerRoutes(app: Express): Promise { res.json(avoir); } catch (error) { if (error instanceof z.ZodError) { + console.error('❌ [POST AVOIR] ERREURS VALIDATION ZOD:', JSON.stringify(error.errors, null, 2)); return res.status(400).json({ message: "Validation error", errors: error.errors }); } - console.error("Error creating avoir:", error); + console.error("❌ [POST AVOIR] Erreur générale:", error); res.status(500).json({ message: "Failed to create avoir" }); } }); diff --git a/shared/schema.ts b/shared/schema.ts index 2dcc23f..9e70bb5 100644 --- a/shared/schema.ts +++ b/shared/schema.ts @@ -585,8 +585,8 @@ export const insertAvoirSchema = createInsertSchema(avoirs).omit({ processedAt: true, }).extend({ status: z.enum(["En attente de demande", "Demandé", "Reçu"]).default("En attente de demande"), - amount: z.coerce.number().positive(), // Montant doit être positif - invoiceReference: z.string().min(1, "La référence facture est obligatoire"), + amount: z.coerce.number().positive().optional(), // Montant optionnel et positif si présent + invoiceReference: z.string().optional(), // Référence facture optionnelle comment: z.string().optional(), commercialProcessed: z.boolean().default(false), });