mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-20 05:28:22 +02:00
Add ability for administrators to edit existing announcements
Implement update functionality for announcements via a PUT API endpoint, including necessary backend storage and client-side UI adjustments. Replit-Commit-Author: Agent Replit-Commit-Session-Id: e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/e437ffed-c31b-44eb-9fd5-b6f9faa8e7ce/HjMubBV
This commit is contained in:
1 parent
ad396339f0
commit
a3889dd088
5 files changed
+208
-28
No files matched your search
@@ -3078,6 +3078,58 @@ RÉSUMÉ DU SCAN
|
||||
}
|
||||
});
|
||||
|
||||
// PUT /api/announcements/:id - Update announcement (admin only)
|
||||
app.put('/api/announcements/:id', isAuthenticated, async (req: any, res) => {
|
||||
console.log('📝 [SERVER] PUT /api/announcements/:id endpoint hit');
|
||||
console.log('📝 [SERVER] Request body:', JSON.stringify(req.body, null, 2));
|
||||
|
||||
try {
|
||||
const userId = req.user.claims ? req.user.claims.sub : req.user.id;
|
||||
console.log('📝 [SERVER] Extracted userId:', userId);
|
||||
|
||||
const user = await storage.getUserWithGroups(userId);
|
||||
if (!user) {
|
||||
console.error('📝 [SERVER] User not found for ID:', userId);
|
||||
return res.status(404).json({ message: "User not found" });
|
||||
}
|
||||
|
||||
console.log('📝 [SERVER] User found:', { username: user.username, role: user.role, id: user.id });
|
||||
|
||||
// Only admin can edit announcements
|
||||
if (user.role !== 'admin') {
|
||||
console.error('📝 [SERVER] Access denied - user role:', user.role);
|
||||
return res.status(403).json({ message: "Only administrators can edit announcements" });
|
||||
}
|
||||
|
||||
const id = parseInt(req.params.id);
|
||||
console.log('📝 [SERVER] Announcement ID:', id);
|
||||
|
||||
// Verify announcement exists
|
||||
const existingAnnouncement = await storage.getAnnouncement(id);
|
||||
if (!existingAnnouncement) {
|
||||
console.error('📝 [SERVER] Announcement not found:', id);
|
||||
return res.status(404).json({ message: "Announcement not found" });
|
||||
}
|
||||
|
||||
console.log('📝 [SERVER] User is admin, proceeding with validation');
|
||||
|
||||
const announcementData = insertAnnouncementSchema.partial().parse(req.body);
|
||||
console.log('📝 [SERVER] Announcement data validated:', announcementData);
|
||||
|
||||
const updatedAnnouncement = await storage.updateAnnouncement(id, announcementData);
|
||||
console.log('📝 [SERVER] Announcement updated successfully:', updatedAnnouncement);
|
||||
|
||||
res.json(updatedAnnouncement);
|
||||
} catch (error) {
|
||||
console.error('📝 [SERVER] Error updating announcement:', error);
|
||||
if (error instanceof z.ZodError) {
|
||||
console.error('📝 [SERVER] Validation errors:', error.errors);
|
||||
return res.status(400).json({ message: "Validation error", errors: error.errors });
|
||||
}
|
||||
res.status(500).json({ message: "Failed to update announcement" });
|
||||
}
|
||||
});
|
||||
|
||||
app.delete('/api/announcements/:id', isAuthenticated, async (req: any, res) => {
|
||||
try {
|
||||
const userId = req.user.claims ? req.user.claims.sub : req.user.id;
|
||||
|
||||
Reference in new issue
Block a user