Skip to content

Commit 2ab0611

Browse files
committed
refactor(feedback): update validation to return feedback object
- Modified validateFeedbackExists to return the ChatMessageFeedback object instead of a boolean. - Updated validateFeedbackForUpdate to utilize the returned feedback object for setting default values.
1 parent 47c4948 commit 2ab0611

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/server/src/services/feedback/validation.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,17 @@ export const validateMessageExists = async (messageId: string): Promise<ChatMess
2626
* Validates that the feedback ID exists
2727
* @param {string} feedbackId
2828
*/
29-
export const validateFeedbackExists = async (feedbackId: string): Promise<boolean> => {
29+
export const validateFeedbackExists = async (feedbackId: string): Promise<ChatMessageFeedback> => {
3030
const appServer = getRunningExpressApp()
31-
const feedbackExists = await appServer.AppDataSource.getRepository(ChatMessageFeedback).exists({
31+
const feedbackExists = await appServer.AppDataSource.getRepository(ChatMessageFeedback).findOne({
3232
where: { id: feedbackId }
3333
})
3434

3535
if (!feedbackExists) {
3636
throw new InternalFlowiseError(StatusCodes.NOT_FOUND, `Feedback with ID ${feedbackId} not found`)
3737
}
3838

39-
return true
39+
return feedbackExists
4040
}
4141

4242
/**
@@ -91,7 +91,11 @@ export const validateFeedbackForUpdate = async (
9191
feedback: Partial<IChatMessageFeedback>
9292
): Promise<Partial<IChatMessageFeedback>> => {
9393
// First validate the feedback exists
94-
await validateFeedbackExists(feedbackId)
94+
const existingFeedback = await validateFeedbackExists(feedbackId)
95+
96+
feedback.messageId = feedback.messageId ?? existingFeedback.messageId
97+
feedback.chatId = feedback.chatId ?? existingFeedback.chatId
98+
feedback.chatflowid = feedback.chatflowid ?? existingFeedback.chatflowid
9599

96100
// If messageId is provided, validate it exists and get the message
97101
let message: ChatMessage | null = null

0 commit comments

Comments
 (0)