From 172541c2b7bffcaa921708672f219dea9f79b222 Mon Sep 17 00:00:00 2001 From: michaelschal <35957947-michaelschal@users.noreply.replit.com> Date: Thu, 21 Aug 2025 11:10:06 +0000 Subject: [PATCH] Make managers see orders from their assigned store automatically Update manager role logic in routes.ts to automatically use the first assigned store for orders and deliveries, and handle cases where no stores are assigned. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 0ec86cdf-a5be-4b0e-84a3-07b926f5cc80 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/0ec86cdf-a5be-4b0e-84a3-07b926f5cc80/PHXoZau --- server/routes.ts | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/server/routes.ts b/server/routes.ts index 0cbd284..87fbf0b 100644 --- a/server/routes.ts +++ b/server/routes.ts @@ -384,15 +384,23 @@ export async function registerRoutes(app: Express): Promise { return res.json([]); } } else { - // For manager role, when no specific store is selected, show orders from all their assigned groups + // For manager role, automatically use their assigned store if (user.role === 'manager') { - groupIds = userGroupIds.length > 0 ? userGroupIds : undefined; - console.log('🔍 Manager orders - showing all accessible stores:', { - userId: user.id, - role: user.role, - userGroups: userGroupIds, - groupIds - }); + if (userGroupIds.length > 0) { + groupIds = [userGroupIds[0]]; // Use first assigned store automatically + console.log('🔍 Manager orders - using assigned store automatically:', { + userId: user.id, + role: user.role, + assignedStore: userGroupIds[0], + allUserGroups: userGroupIds + }); + } else { + console.log('🚫 Manager has no assigned stores:', { + userId: user.id, + role: user.role + }); + return res.json([]); + } } else { // For employee role, require explicit store selection console.log('🔍 Employee orders - no store selection, returning empty:', { @@ -707,15 +715,23 @@ export async function registerRoutes(app: Express): Promise { return res.json([]); } } else { - // For manager role, when no specific store is selected, show deliveries from all their assigned groups + // For manager role, automatically use their assigned store if (user.role === 'manager') { - groupIds = userGroupIds.length > 0 ? userGroupIds : undefined; - console.log('🔍 Manager deliveries - showing all accessible stores:', { - userId: user.id, - role: user.role, - userGroups: userGroupIds, - groupIds - }); + if (userGroupIds.length > 0) { + groupIds = [userGroupIds[0]]; // Use first assigned store automatically + console.log('🔍 Manager deliveries - using assigned store automatically:', { + userId: user.id, + role: user.role, + assignedStore: userGroupIds[0], + allUserGroups: userGroupIds + }); + } else { + console.log('🚫 Manager has no assigned stores:', { + userId: user.id, + role: user.role + }); + return res.json([]); + } } else { // For employee role, require explicit store selection console.log('🔍 Employee deliveries - no store selection, returning empty:', {