mirror of
https://github.com/R0m1k3/LogiFlow.git
synced 2026-10-11 17:27:31 +02:00
Fix error when updating announcements by adding missing get announcement functionality
Add the `getAnnouncement` method to `AnnouncementStorage` implementations and update the `IAnnouncementStorage` interface to resolve a `TypeError` during announcement updates. Replit-Commit-Author: Agent Replit-Commit-Session-Id: cc2d271b-82f0-4d6a-9302-a0b067ffb429 Replit-Commit-Checkpoint-Type: full_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/1957c339-2757-4d1f-8e92-e9f71a1ce58e/cc2d271b-82f0-4d6a-9302-a0b067ffb429/JTP6mhE
This commit is contained in:
1 parent
978cff1c53
commit
81a51c6540
4 files changed
+200
-1
No files matched your search
@@ -11,6 +11,7 @@ type AnnouncementWithRelations = DashboardMessageWithRelations;
|
||||
// Interface commune pour le stockage
|
||||
interface IAnnouncementStorage {
|
||||
getAnnouncements(groupIds?: number[]): Promise<AnnouncementWithRelations[]>;
|
||||
getAnnouncement(id: number): Promise<AnnouncementWithRelations | null>;
|
||||
createAnnouncement(announcement: InsertAnnouncement): Promise<DashboardMessage>;
|
||||
updateAnnouncement(id: number, announcement: Partial<InsertAnnouncement>): Promise<DashboardMessage>;
|
||||
deleteAnnouncement(id: number): Promise<void>;
|
||||
@@ -59,6 +60,56 @@ class AnnouncementDatabaseStorage implements IAnnouncementStorage {
|
||||
}));
|
||||
}
|
||||
|
||||
async getAnnouncement(id: number): Promise<AnnouncementWithRelations | null> {
|
||||
console.log('🔍 [DB] Getting single announcement:', id);
|
||||
|
||||
const result = await db
|
||||
.select({
|
||||
id: dashboardMessages.id,
|
||||
title: dashboardMessages.title,
|
||||
content: dashboardMessages.content,
|
||||
type: dashboardMessages.type,
|
||||
storeId: dashboardMessages.storeId,
|
||||
createdBy: dashboardMessages.createdBy,
|
||||
createdAt: dashboardMessages.createdAt,
|
||||
author: {
|
||||
id: users.id,
|
||||
firstName: users.firstName,
|
||||
lastName: users.lastName,
|
||||
username: users.username,
|
||||
},
|
||||
group: {
|
||||
id: groups.id,
|
||||
name: groups.name,
|
||||
},
|
||||
})
|
||||
.from(dashboardMessages)
|
||||
.leftJoin(users, eq(dashboardMessages.createdBy, users.username))
|
||||
.leftJoin(groups, eq(dashboardMessages.storeId, groups.id))
|
||||
.where(eq(dashboardMessages.id, id))
|
||||
.limit(1);
|
||||
|
||||
if (result.length === 0) {
|
||||
console.log('❌ [DB] Announcement not found:', id);
|
||||
return null;
|
||||
}
|
||||
|
||||
const announcement = result[0];
|
||||
console.log('✅ [DB] Found announcement:', announcement.id, announcement.title);
|
||||
|
||||
return {
|
||||
id: announcement.id,
|
||||
title: announcement.title,
|
||||
content: announcement.content,
|
||||
type: announcement.type,
|
||||
storeId: announcement.storeId,
|
||||
createdBy: announcement.createdBy,
|
||||
createdAt: announcement.createdAt,
|
||||
author: announcement.author as User,
|
||||
group: announcement.group as Group | undefined,
|
||||
};
|
||||
}
|
||||
|
||||
async createAnnouncement(announcement: InsertAnnouncement): Promise<DashboardMessage> {
|
||||
const [created] = await db
|
||||
.insert(dashboardMessages)
|
||||
@@ -133,6 +184,26 @@ class AnnouncementMemoryStorage implements IAnnouncementStorage {
|
||||
this.announcements.set(testAnnouncement2.id, testAnnouncement2);
|
||||
}
|
||||
|
||||
async getAnnouncement(id: number): Promise<AnnouncementWithRelations | null> {
|
||||
const announcement = this.announcements.get(id);
|
||||
if (!announcement) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Ajouter les relations
|
||||
const users = await this.usersGetter();
|
||||
const groups = await this.groupsGetter();
|
||||
|
||||
const author = users.find(u => u.id === announcement.createdBy || u.username === announcement.createdBy);
|
||||
const group = announcement.storeId ? groups.find(g => g.id === announcement.storeId) : undefined;
|
||||
|
||||
return {
|
||||
...announcement,
|
||||
author: author || { id: announcement.createdBy, firstName: 'Utilisateur', lastName: 'Inconnu', username: announcement.createdBy } as User,
|
||||
group,
|
||||
};
|
||||
}
|
||||
|
||||
async getAnnouncements(groupIds?: number[]): Promise<AnnouncementWithRelations[]> {
|
||||
const announcements = Array.from(this.announcements.values());
|
||||
|
||||
|
||||
Reference in new issue
Block a user