Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion platforms/pictique-api/src/services/MessageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ export class MessageService {
private chatRepository = AppDataSource.getRepository(Chat);

async findById(id: string): Promise<Message | null> {
return await this.messageRepository.findOneBy({ id });
return await this.messageRepository.findOne({
where: { id },
relations: ["chat", "sender"]
});
}

async createMessage(senderId: string | null, chatId: string, text: string, isSystemMessage: boolean = false): Promise<Message> {
Expand Down
18 changes: 18 additions & 0 deletions platforms/pictique-api/src/web3adapter/watchers/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,24 @@ export class PostgresSubscriber implements EntitySubscriberInterface {
enrichedEntity.author = author;
}

// For messages, enrich sender and chat relations
if (entity.sender && entity.sender.id) {
const sender = await AppDataSource.getRepository(
"User"
).findOne({ where: { id: entity.sender.id } });
enrichedEntity.sender = sender;
}

if (entity.chat && entity.chat.id) {
const chat = await AppDataSource.getRepository(
"Chat"
).findOne({
where: { id: entity.chat.id },
relations: ["participants", "messages"]
});
enrichedEntity.chat = chat;
}

return this.entityToPlain(enrichedEntity);
} catch (error) {
console.error("Error loading relations:", error);
Expand Down
Loading
Loading