From c9ccfad35e77860a549b2f68ff71787431ebd47e Mon Sep 17 00:00:00 2001 From: abrakadobr Date: Mon, 21 Oct 2024 01:16:45 +0700 Subject: [PATCH 1/2] thread creation additional params name and slug, with api --- server/endpoints/api/workspaceThread/index.js | 15 +++++++++------ server/models/workspaceThread.js | 6 +++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/server/endpoints/api/workspaceThread/index.js b/server/endpoints/api/workspaceThread/index.js index e7f53698ad4..a4ea5f71ec8 100644 --- a/server/endpoints/api/workspaceThread/index.js +++ b/server/endpoints/api/workspaceThread/index.js @@ -31,12 +31,14 @@ function apiWorkspaceThreadEndpoints(app) { type: 'string' } #swagger.requestBody = { - description: 'Optional userId associated with the thread', + description: 'Optional userId associated with the thread, thread slug and thread name', required: false, content: { "application/json": { example: { - userId: 1 + userId: 1, + name: 'Name', + slug: 'thread-slug' } } } @@ -67,9 +69,9 @@ function apiWorkspaceThreadEndpoints(app) { } */ try { - const { slug } = request.params; - let { userId = null } = reqBody(request); - const workspace = await Workspace.get({ slug }); + const wslug = request.params.slug; + let { userId = null, name = null, slug = null } = reqBody(request); + const workspace = await Workspace.get({ wslug }); if (!workspace) { response.sendStatus(400).end(); @@ -83,7 +85,8 @@ function apiWorkspaceThreadEndpoints(app) { const { thread, message } = await WorkspaceThread.new( workspace, - userId ? Number(userId) : null + userId ? Number(userId) : null, + { name, slug } ); await Telemetry.sendTelemetry("workspace_thread_created", { diff --git a/server/models/workspaceThread.js b/server/models/workspaceThread.js index 32e9f89b68f..aeb1c714260 100644 --- a/server/models/workspaceThread.js +++ b/server/models/workspaceThread.js @@ -5,12 +5,12 @@ const WorkspaceThread = { defaultName: "Thread", writable: ["name"], - new: async function (workspace, userId = null) { + new: async function (workspace, userId = null, data = {}) { try { const thread = await prisma.workspace_threads.create({ data: { - name: this.defaultName, - slug: uuidv4(), + name: data.name || this.defaultName, + slug: data.slug || uuidv4(), user_id: userId ? Number(userId) : null, workspace_id: workspace.id, }, From 49d09c9c2b2e94844345fc18c7940983a7f1e942 Mon Sep 17 00:00:00 2001 From: abrakadobr Date: Mon, 21 Oct 2024 02:40:58 +0700 Subject: [PATCH 2/2] typo fix --- server/endpoints/api/workspaceThread/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/endpoints/api/workspaceThread/index.js b/server/endpoints/api/workspaceThread/index.js index a4ea5f71ec8..0d6eb59c67a 100644 --- a/server/endpoints/api/workspaceThread/index.js +++ b/server/endpoints/api/workspaceThread/index.js @@ -71,7 +71,7 @@ function apiWorkspaceThreadEndpoints(app) { try { const wslug = request.params.slug; let { userId = null, name = null, slug = null } = reqBody(request); - const workspace = await Workspace.get({ wslug }); + const workspace = await Workspace.get({ slug: wslug }); if (!workspace) { response.sendStatus(400).end();