mirror of
https://github.com/farcasclaudiu/Flowise.git
synced 2026-06-28 23:01:09 +03:00
Update how chat message feedback are queried for view messages dialog
This commit is contained in:
@@ -1536,21 +1536,36 @@ export class App {
|
|||||||
if (endDate) toDate = setDateToStartOrEndOfDay(endDate, 'end')
|
if (endDate) toDate = setDateToStartOrEndOfDay(endDate, 'end')
|
||||||
|
|
||||||
if (feedback) {
|
if (feedback) {
|
||||||
const messages = await this.AppDataSource.getRepository(ChatMessage)
|
const query = this.AppDataSource.getRepository(ChatMessage).createQueryBuilder('chat_message')
|
||||||
.createQueryBuilder('chat_message')
|
|
||||||
|
// do the join with chat message feedback based on messageId for each chat message in the chatflow
|
||||||
|
query
|
||||||
.leftJoinAndMapOne('chat_message.feedback', ChatMessageFeedback, 'feedback', 'feedback.messageId = chat_message.id')
|
.leftJoinAndMapOne('chat_message.feedback', ChatMessageFeedback, 'feedback', 'feedback.messageId = chat_message.id')
|
||||||
.where('chat_message.chatflowid = :chatflowid', { chatflowid })
|
.where('chat_message.chatflowid = :chatflowid', { chatflowid })
|
||||||
.andWhere(chatType ? 'chat_message.chatType = :chatType' : 'TRUE', { chatType })
|
|
||||||
.andWhere(chatId ? 'chat_message.chatId = :chatId' : 'TRUE', { chatId })
|
// based on which parameters are available add `andWhere` clauses to the query
|
||||||
.andWhere(memoryType ? 'chat_message.memoryType = :memoryType' : 'TRUE', { memoryType })
|
if (chatType) {
|
||||||
.andWhere(sessionId ? 'chat_message.sessionId = :sessionId' : 'TRUE', { sessionId })
|
query.andWhere('chat_message.chatType = :chatType', { chatType })
|
||||||
.andWhere('chat_message.createdDate BETWEEN :fromDate AND :toDate', {
|
}
|
||||||
|
if (chatId) {
|
||||||
|
query.andWhere('chat_message.chatId = :chatId', { chatId })
|
||||||
|
}
|
||||||
|
if (memoryType) {
|
||||||
|
query.andWhere('chat_message.memoryType = :memoryType', { memoryType })
|
||||||
|
}
|
||||||
|
if (sessionId) {
|
||||||
|
query.andWhere('chat_message.sessionId = :sessionId', { sessionId })
|
||||||
|
}
|
||||||
|
|
||||||
|
// set date range
|
||||||
|
query.andWhere('chat_message.createdDate BETWEEN :fromDate AND :toDate', {
|
||||||
fromDate: fromDate ?? new Date().setMonth(new Date().getMonth() - 1),
|
fromDate: fromDate ?? new Date().setMonth(new Date().getMonth() - 1),
|
||||||
toDate: toDate ?? new Date()
|
toDate: toDate ?? new Date()
|
||||||
})
|
})
|
||||||
.orderBy('chat_message.createdDate', sortOrder === 'DESC' ? 'DESC' : 'ASC')
|
// sort
|
||||||
.getMany()
|
query.orderBy('chat_message.createdDate', sortOrder === 'DESC' ? 'DESC' : 'ASC')
|
||||||
|
|
||||||
|
const messages = await query.getMany()
|
||||||
return messages
|
return messages
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user