Return threads for API workspace calls (#1978)

* Return threads for API workspace calls

* remove import
This commit is contained in:
Timothy Carambat 2024-07-26 14:18:40 -07:00 committed by GitHub
parent 013c0b9575
commit ae58a2cb0d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 65 additions and 6 deletions

View File

@ -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);

View File

@ -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 };

View File

@ -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": []
}
}
}