feat(feedback): add validation for feedback creation and update (#4260)

* feat(feedback): add validation for feedback creation and update

Introduced validation functions for feedback creation and update in the new validation service.
Updated feedback controller to utilize these validation functions before processing requests.

* 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.
This commit is contained in:
Mehdi
2025-04-14 19:38:02 +01:00
committed by GitHub
parent 9d9b40a326
commit 54d1b5e3bb
2 changed files with 130 additions and 0 deletions
@@ -1,5 +1,6 @@
import { Request, Response, NextFunction } from 'express'
import feedbackService from '../../services/feedback'
import { validateFeedbackForCreation, validateFeedbackForUpdate } from '../../services/feedback/validation'
import { InternalFlowiseError } from '../../errors/internalFlowiseError'
import { StatusCodes } from 'http-status-codes'
@@ -31,6 +32,7 @@ const createChatMessageFeedbackForChatflow = async (req: Request, res: Response,
`Error: feedbackController.createChatMessageFeedbackForChatflow - body not provided!`
)
}
await validateFeedbackForCreation(req.body)
const apiResponse = await feedbackService.createChatMessageFeedbackForChatflow(req.body)
return res.json(apiResponse)
} catch (error) {
@@ -52,6 +54,7 @@ const updateChatMessageFeedbackForChatflow = async (req: Request, res: Response,
`Error: feedbackController.updateChatMessageFeedbackForChatflow - id not provided!`
)
}
await validateFeedbackForUpdate(req.params.id, req.body)
const apiResponse = await feedbackService.updateChatMessageFeedbackForChatflow(req.params.id, req.body)
return res.json(apiResponse)
} catch (error) {