File tree Expand file tree Collapse file tree 2 files changed +13
-12
lines changed
Expand file tree Collapse file tree 2 files changed +13
-12
lines changed Original file line number Diff line number Diff line change @@ -498,21 +498,16 @@ function workspaceEndpoints(app) {
498498 try {
499499 const { chatId } = request . params ;
500500 const { feedback = null } = reqBody ( request ) ;
501+ const user = await userFromSession ( request , response ) ;
501502 const existingChat = await WorkspaceChats . get ( {
502503 id : Number ( chatId ) ,
503504 workspaceId : response . locals . workspace . id ,
505+ user_id : user ?. id ,
504506 } ) ;
505507
506- if ( ! existingChat ) {
507- response . status ( 404 ) . end ( ) ;
508- return ;
509- }
510-
511- const result = await WorkspaceChats . updateFeedbackScore (
512- chatId ,
513- feedback
514- ) ;
515- response . status ( 200 ) . json ( { success : result } ) ;
508+ if ( ! existingChat ) return response . status ( 404 ) . json ( { success : false } ) ;
509+ await WorkspaceChats . updateFeedbackScore ( chatId , feedback ) ;
510+ return response . status ( 200 ) . json ( { success : true } ) ;
516511 } catch ( error ) {
517512 console . error ( "Error updating chat feedback:" , error ) ;
518513 response . status ( 500 ) . end ( ) ;
Original file line number Diff line number Diff line change @@ -28,8 +28,14 @@ function makeJWT(info = {}, expiry = "30d") {
2828 return JWT . sign ( info , process . env . JWT_SECRET , { expiresIn : expiry } ) ;
2929}
3030
31- // Note: Only valid for finding users in multi-user mode
32- // as single-user mode with password is not a "user"
31+ /**
32+ * Gets the user from the session
33+ * Note: Only valid for multi-user mode
34+ * as single-user mode with password is not a "user"
35+ * @param {import("express").Request } request - The request object
36+ * @param {import("express").Response } response - The response object
37+ * @returns {Promise<import("@prisma/client").users | null> } The user
38+ */
3339async function userFromSession ( request , response = null ) {
3440 if ( ! ! response && ! ! response . locals ?. user ) {
3541 return response . locals . user ;
You can’t perform that action at this time.
0 commit comments