mirror of
https://github.com/R0m1k3/Regisflow.git
synced 2026-10-23 07:08:18 +02:00
Enable administrators to manage users and stores more effectively
Implements CRUD operations for users and stores with UI updates and server route handling. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 91318273-c764-4fd4-be04-bdc12c38af32 Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/0715008c-7244-40f4-befc-26c014852236/ab880d72-1a34-4d36-b5be-9f44df85ed1a.jpg
This commit is contained in:
1 parent
462ebeb816
commit
a5336a5919
3 files changed
+762
-243
No files matched your search
@@ -217,6 +217,27 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/admin/users/:id', requireRole(['admin']), async (req, res) => {
|
||||
try {
|
||||
const userId = parseInt(req.params.id);
|
||||
|
||||
// Don't allow deletion of the last administrator
|
||||
const users = await storage.getAllUsers();
|
||||
const adminUsers = users.filter(u => u.role === 'administrator');
|
||||
const userToDelete = users.find(u => u.id === userId);
|
||||
|
||||
if (userToDelete?.role === 'administrator' && adminUsers.length <= 1) {
|
||||
return res.status(400).json({ error: "Cannot delete the last administrator" });
|
||||
}
|
||||
|
||||
await storage.deleteUser(userId);
|
||||
res.json({ message: "User deleted successfully" });
|
||||
} catch (error) {
|
||||
console.error('Delete user error:', error);
|
||||
res.status(500).json({ error: "Failed to delete user" });
|
||||
}
|
||||
});
|
||||
|
||||
// Admin routes - Stores
|
||||
app.get('/api/admin/stores', requireRole(['admin']), async (req, res) => {
|
||||
try {
|
||||
@@ -260,6 +281,29 @@ export async function registerRoutes(app: Express): Promise<Server> {
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/admin/stores/:id', requireRole(['admin']), async (req, res) => {
|
||||
try {
|
||||
const storeId = parseInt(req.params.id);
|
||||
|
||||
// Check if there are users assigned to this store
|
||||
const users = await storage.getAllUsers();
|
||||
const usersInStore = users.filter(u => u.storeId === storeId);
|
||||
|
||||
if (usersInStore.length > 0) {
|
||||
return res.status(400).json({
|
||||
error: "Cannot delete store with assigned users",
|
||||
details: `${usersInStore.length} user(s) are assigned to this store`
|
||||
});
|
||||
}
|
||||
|
||||
await storage.deleteStore(storeId);
|
||||
res.json({ message: "Store deleted successfully" });
|
||||
} catch (error) {
|
||||
console.error('Delete store error:', error);
|
||||
res.status(500).json({ error: "Failed to delete store" });
|
||||
}
|
||||
});
|
||||
|
||||
const httpServer = createServer(app);
|
||||
return httpServer;
|
||||
}
|
||||
Reference in new issue
Block a user