diff --git a/server/endpoints/api/workspace/index.js b/server/endpoints/api/workspace/index.js index 1974b4bc..719b73ba 100644 --- a/server/endpoints/api/workspace/index.js +++ b/server/endpoints/api/workspace/index.js @@ -103,7 +103,8 @@ function apiWorkspaceEndpoints(app) { "openAiTemp": null, "lastUpdatedAt": "2023-08-17 00:45:03", "openAiHistory": 20, - "openAiPrompt": null + "openAiPrompt": null, + "threads": [] } ], } @@ -118,7 +119,17 @@ function apiWorkspaceEndpoints(app) { } */ try { - const workspaces = await Workspace.where(); + const workspaces = await Workspace._findMany({ + where: {}, + include: { + threads: { + select: { + user_id: true, + slug: true, + }, + }, + }, + }); response.status(200).json({ workspaces }); } catch (e) { console.error(e.message, e); @@ -152,7 +163,8 @@ function apiWorkspaceEndpoints(app) { "lastUpdatedAt": "2023-08-17 00:45:03", "openAiHistory": 20, "openAiPrompt": null, - "documents": [] + "documents": [], + "threads": [] } } } @@ -167,7 +179,21 @@ function apiWorkspaceEndpoints(app) { */ try { const { slug } = request.params; - const workspace = await Workspace.get({ slug }); + const workspace = await Workspace._findMany({ + where: { + slug: String(slug), + }, + include: { + documents: true, + threads: { + select: { + user_id: true, + slug: true, + }, + }, + }, + }); + response.status(200).json({ workspace }); } catch (e) { console.error(e.message, e); diff --git a/server/models/workspace.js b/server/models/workspace.js index d80f00dd..b9b0c036 100644 --- a/server/models/workspace.js +++ b/server/models/workspace.js @@ -302,6 +302,37 @@ const Workspace = { ); return; }, + + // Direct DB queries for API use only. + /** + * Generic prisma FindMany query for workspaces collections + * @param {import("../node_modules/.prisma/client/index.d.ts").Prisma.TypeMap['model']['workspaces']['operations']['findMany']['args']} prismaQuery + * @returns + */ + _findMany: async function (prismaQuery = {}) { + try { + const results = await prisma.workspaces.findMany(prismaQuery); + return results; + } catch (error) { + console.error(error.message); + return null; + } + }, + + /** + * Generic prisma query for .get of workspaces collections + * @param {import("../node_modules/.prisma/client/index.d.ts").Prisma.TypeMap['model']['workspaces']['operations']['findFirst']['args']} prismaQuery + * @returns + */ + _findFirst: async function (prismaQuery = {}) { + try { + const results = await prisma.workspaces.findFirst(prismaQuery); + return results; + } catch (error) { + console.error(error.message); + return null; + } + }, }; module.exports = { Workspace }; diff --git a/server/swagger/openapi.json b/server/swagger/openapi.json index 7831bd55..554bd67b 100644 --- a/server/swagger/openapi.json +++ b/server/swagger/openapi.json @@ -1476,7 +1476,8 @@ "openAiTemp": null, "lastUpdatedAt": "2023-08-17 00:45:03", "openAiHistory": 20, - "openAiPrompt": null + "openAiPrompt": null, + "threads": [] } ] } @@ -1539,7 +1540,8 @@ "lastUpdatedAt": "2023-08-17 00:45:03", "openAiHistory": 20, "openAiPrompt": null, - "documents": [] + "documents": [], + "threads": [] } } }