mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-19 13:08:23 +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
@@ -114,6 +114,60 @@ class AnnouncementMemoryStorage {
|
||||
return announcement;
|
||||
}
|
||||
|
||||
async getAnnouncement(id: number): Promise<AnnouncementWithRelations | undefined> {
|
||||
const announcement = this.announcements.get(id);
|
||||
if (!announcement) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
// Récupérer les utilisateurs et groupes pour les relations
|
||||
const [users, groups] = await Promise.all([
|
||||
this.usersGetter(),
|
||||
this.groupsGetter()
|
||||
]);
|
||||
|
||||
const usersMap = new Map(users.map(u => [u.id, u]));
|
||||
const groupsMap = new Map(groups.map(g => [g.id, g]));
|
||||
|
||||
const author = usersMap.get(announcement.authorId);
|
||||
const group = announcement.groupId ? groupsMap.get(announcement.groupId) : undefined;
|
||||
|
||||
if (!author) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return {
|
||||
...announcement,
|
||||
author,
|
||||
group,
|
||||
};
|
||||
}
|
||||
|
||||
async updateAnnouncement(id: number, announcementData: Partial<InsertAnnouncement>): Promise<AnnouncementWithRelations> {
|
||||
const existingAnnouncement = this.announcements.get(id);
|
||||
if (!existingAnnouncement) {
|
||||
throw new Error(`Announcement with ID ${id} not found`);
|
||||
}
|
||||
|
||||
const updatedAnnouncement: Announcement = {
|
||||
...existingAnnouncement,
|
||||
...announcementData,
|
||||
id, // Ensure ID doesn't change
|
||||
updatedAt: new Date(),
|
||||
};
|
||||
|
||||
this.announcements.set(id, updatedAnnouncement);
|
||||
console.log(`✏️ Annonce mise à jour: ${updatedAnnouncement.title} (ID: ${id})`);
|
||||
|
||||
// Return the announcement with relations
|
||||
const announcementWithRelations = await this.getAnnouncement(id);
|
||||
if (!announcementWithRelations) {
|
||||
throw new Error(`Failed to get updated announcement with relations`);
|
||||
}
|
||||
|
||||
return announcementWithRelations;
|
||||
}
|
||||
|
||||
async deleteAnnouncement(id: number): Promise<boolean> {
|
||||
const existed = this.announcements.has(id);
|
||||
const deleted = this.announcements.delete(id);
|
||||
|
||||
Reference in new issue
Block a user