mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-12 01:37:40 +02:00
Fix ticket assignment to ensure it's assigned to the user's store
Correctly assigns SAV tickets to the user's group, resolving an issue where tickets were not being assigned to the creating user's store. Includes backend and frontend logic adjustments for accurate group assignment based on user roles and available groups. Replit-Commit-Author: Agent Replit-Commit-Session-Id: f9197b9b-a5b3-4469-a27d-930a9e9ee736 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/f9197b9b-a5b3-4469-a27d-930a9e9ee736/i2gFnxm
This commit is contained in:
1 parent
32161ae797
commit
2ff22c4821
2 files changed
+42
-6
No files matched your search
@@ -265,14 +265,24 @@ export default function SavTickets() {
|
||||
// Get user's available groups for auto-assignment
|
||||
const getUserGroups = () => {
|
||||
if (!user || user.role === 'admin') {
|
||||
console.log('🎫 [CLIENT] Admin user - can access all groups:', groupsData?.length || 0);
|
||||
return groupsData; // Admin can access all groups
|
||||
}
|
||||
|
||||
// For other users, get their assigned groups
|
||||
const userGroups = (user as any).userGroups || [];
|
||||
return groupsData.filter(group =>
|
||||
const filteredGroups = groupsData.filter(group =>
|
||||
userGroups.some((ug: any) => ug.groupId === group.id)
|
||||
);
|
||||
|
||||
console.log('🎫 [CLIENT] Non-admin user groups:', {
|
||||
userRole: user.role,
|
||||
userUsername: user.username,
|
||||
allUserGroups: userGroups,
|
||||
filteredGroups: filteredGroups.map(g => ({ id: g.id, name: g.name }))
|
||||
});
|
||||
|
||||
return filteredGroups;
|
||||
};
|
||||
|
||||
const availableGroups = getUserGroups();
|
||||
@@ -288,12 +298,20 @@ export default function SavTickets() {
|
||||
return;
|
||||
}
|
||||
|
||||
// Auto-assign group if user has only one group or if admin didn't select one
|
||||
// Auto-assign group based on user role and available groups
|
||||
let selectedGroupId = formData.groupId ? parseInt(formData.groupId) : null;
|
||||
|
||||
console.log('🎫 [CLIENT] User groups analysis:', {
|
||||
userRole: user?.role,
|
||||
formDataGroupId: formData.groupId,
|
||||
availableGroups: availableGroups.map(g => ({ id: g.id, name: g.name })),
|
||||
selectedGroupId
|
||||
});
|
||||
|
||||
if (!selectedGroupId && availableGroups.length > 0) {
|
||||
// Auto-assign first available group
|
||||
selectedGroupId = availableGroups[0].id;
|
||||
console.log('🎫 [CLIENT] Auto-assigned group:', selectedGroupId, availableGroups[0].name);
|
||||
}
|
||||
|
||||
const ticketData: InsertSavTicket = {
|
||||
@@ -311,7 +329,14 @@ export default function SavTickets() {
|
||||
clientPhone: formData.clientPhone || undefined,
|
||||
};
|
||||
|
||||
console.log('Creating ticket with data:', ticketData);
|
||||
console.log('🎫 [CLIENT] Creating ticket with data:', {
|
||||
...ticketData,
|
||||
userInfo: {
|
||||
role: user?.role,
|
||||
username: user?.username,
|
||||
availableGroups: availableGroups.length
|
||||
}
|
||||
});
|
||||
createTicketMutation.mutate(ticketData);
|
||||
};
|
||||
|
||||
|
||||
+14
-3
@@ -2688,8 +2688,8 @@ RÉSUMÉ DU SCAN
|
||||
return res.status(404).json({ message: "User not found" });
|
||||
}
|
||||
|
||||
// Check permissions: admin, manager, directeur can create
|
||||
if (!['admin', 'manager', 'directeur'].includes(user.role)) {
|
||||
// Check permissions: admin, manager, directeur, employee can create
|
||||
if (!['admin', 'manager', 'directeur', 'employee'].includes(user.role)) {
|
||||
return res.status(403).json({ message: "Insufficient permissions to create tickets" });
|
||||
}
|
||||
|
||||
@@ -2698,9 +2698,11 @@ RÉSUMÉ DU SCAN
|
||||
if (user.role === 'admin') {
|
||||
const allGroups = await storage.getGroups();
|
||||
availableGroupIds = allGroups.map(g => g.id);
|
||||
console.log(`🎫 [SAV] Admin ${user.username} can access all groups:`, availableGroupIds);
|
||||
} else {
|
||||
const userGroups = (user as any).userGroups;
|
||||
availableGroupIds = userGroups ? userGroups.map((ug: any) => ug.groupId) : [];
|
||||
console.log(`🎫 [SAV] User ${user.username} (${user.role}) has groups:`, availableGroupIds);
|
||||
}
|
||||
|
||||
if (availableGroupIds.length === 0) {
|
||||
@@ -2712,9 +2714,12 @@ RÉSUMÉ DU SCAN
|
||||
const ticketNumber = `SAV-${now.getFullYear()}${(now.getMonth() + 1).toString().padStart(2, '0')}${now.getDate().toString().padStart(2, '0')}-${Date.now().toString().slice(-6)}`;
|
||||
|
||||
// Parse and validate request body
|
||||
const assignedGroupId = req.body.groupId || availableGroupIds[0];
|
||||
console.log(`🎫 [SAV] Creating ticket for user ${user.username} with groupId: ${assignedGroupId} (requested: ${req.body.groupId}, available: ${availableGroupIds})`);
|
||||
|
||||
const ticketData = insertSavTicketSchema.parse({
|
||||
...req.body,
|
||||
groupId: req.body.groupId || availableGroupIds[0], // Use first available group if not specified
|
||||
groupId: assignedGroupId, // Use first available group if not specified
|
||||
createdBy: user.id,
|
||||
});
|
||||
|
||||
@@ -2730,6 +2735,12 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
|
||||
const ticket = await storage.createSavTicket(ticketDataWithNumber);
|
||||
console.log(`🎫 [SAV] Ticket created successfully:`, {
|
||||
ticketNumber: ticket.ticketNumber,
|
||||
groupId: ticket.groupId,
|
||||
createdBy: ticket.createdBy,
|
||||
userRole: user.role
|
||||
});
|
||||
res.status(201).json(ticket);
|
||||
} catch (error) {
|
||||
console.error("Error creating SAV ticket:", error);
|
||||
|
||||
Reference in new issue
Block a user