Skip to content

Commit 7908c10

Browse files
add user id to chat feedback
update JSDOC on middleware for typedef GHSA-2qmm-82f7-8qj5
1 parent f203034 commit 7908c10

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

server/endpoints/workspaces.js

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff 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();

server/utils/http/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff 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+
*/
3339
async function userFromSession(request, response = null) {
3440
if (!!response && !!response.locals?.user) {
3541
return response.locals.user;

0 commit comments

Comments
 (0)