Fix topic message history persistence

This commit is contained in:
2026-03-12 19:21:37 +04:00
parent 23faeef738
commit b7fa489d24
7 changed files with 420 additions and 52 deletions

View File

@@ -1,4 +1,4 @@
import { and, asc, desc, eq, gte, isNotNull } from 'drizzle-orm'
import { and, desc, eq, gte, isNotNull } from 'drizzle-orm'
import { instantFromDatabaseValue, instantToDate } from '@household/domain'
import { createDbClient, schema } from '@household/db'
@@ -72,10 +72,10 @@ export function createDbTopicMessageHistoryRepository(databaseUrl: string): {
gte(schema.topicMessages.messageSentAt, instantToDate(input.sentAtOrAfter))
)
)
.orderBy(asc(schema.topicMessages.messageSentAt), asc(schema.topicMessages.createdAt))
.orderBy(desc(schema.topicMessages.messageSentAt), desc(schema.topicMessages.createdAt))
.limit(input.limit)
return rows.map((row) => ({
return rows.reverse().map((row) => ({
householdId: row.householdId,
telegramChatId: row.telegramChatId,
telegramThreadId: row.telegramThreadId,