add user id to chat feedback

update JSDOC on middleware for typedef
GHSA-2qmm-82f7-8qj5
This commit is contained in:
Timothy Carambat
2026-03-13 16:51:02 -07:00
parent f2030343d7
commit 7908c10379
2 changed files with 13 additions and 12 deletions

View File

@@ -498,21 +498,16 @@ function workspaceEndpoints(app) {
try {
const { chatId } = request.params;
const { feedback = null } = reqBody(request);
const user = await userFromSession(request, response);
const existingChat = await WorkspaceChats.get({
id: Number(chatId),
workspaceId: response.locals.workspace.id,
user_id: user?.id,
});
if (!existingChat) {
response.status(404).end();
return;
}
const result = await WorkspaceChats.updateFeedbackScore(
chatId,
feedback
);
response.status(200).json({ success: result });
if (!existingChat) return response.status(404).json({ success: false });
await WorkspaceChats.updateFeedbackScore(chatId, feedback);
return response.status(200).json({ success: true });
} catch (error) {
console.error("Error updating chat feedback:", error);
response.status(500).end();

View File

@@ -28,8 +28,14 @@ function makeJWT(info = {}, expiry = "30d") {
return JWT.sign(info, process.env.JWT_SECRET, { expiresIn: expiry });
}
// Note: Only valid for finding users in multi-user mode
// as single-user mode with password is not a "user"
/**
* Gets the user from the session
* Note: Only valid for multi-user mode
* as single-user mode with password is not a "user"
* @param {import("express").Request} request - The request object
* @param {import("express").Response} response - The response object
* @returns {Promise<import("@prisma/client").users | null>} The user
*/
async function userFromSession(request, response = null) {
if (!!response && !!response.locals?.user) {
return response.locals.user;