Skip to content

Commit

Permalink
Make userId actually optional for workspaceThread endpoint (#2276)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat authored Sep 12, 2024
1 parent 906eb70 commit 0cbe4d0
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions server/endpoints/api/workspaceThread/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ const { WorkspaceThread } = require("../../../models/workspaceThread");
const { Workspace } = require("../../../models/workspace");
const { validApiKey } = require("../../../utils/middleware/validApiKey");
const { reqBody, multiUserMode } = require("../../../utils/http");
const {
streamChatWithWorkspace,
VALID_CHAT_MODE,
} = require("../../../utils/chats/stream");
const { VALID_CHAT_MODE } = require("../../../utils/chats/stream");
const { Telemetry } = require("../../../models/telemetry");
const { EventLogs } = require("../../../models/eventLogs");
const {
Expand Down Expand Up @@ -71,14 +68,19 @@ function apiWorkspaceThreadEndpoints(app) {
*/
try {
const { slug } = request.params;
const { userId } = reqBody(request);
let { userId = null } = reqBody(request);
const workspace = await Workspace.get({ slug });

if (!workspace) {
response.sendStatus(400).end();
return;
}

// If the system is not multi-user and you pass in a userId
// it needs to be nullified as no users exist. This can still fail validation
// as we don't check if the userID is valid.
if (!response.locals.multiUserMode && !!userId) userId = null;

const { thread, message } = await WorkspaceThread.new(
workspace,
userId ? Number(userId) : null
Expand Down

0 comments on commit 0cbe4d0

Please sign in to comment.