CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/next/pages/api/v2/user-query.ts
Views: 687
1
/*
2
User query endpoint.
3
*/
4
5
import userQuery from "@cocalc/database/user-query";
6
import getAccountId from "lib/account/get-account";
7
import getParams from "lib/api/get-params";
8
9
import { apiRoute, apiRouteOperation } from "lib/api";
10
import {
11
UserQueryInputSchema,
12
UserQueryOutputSchema,
13
} from "lib/api/schema/user-query";
14
15
async function handle(req, res) {
16
const account_id = await getAccountId(req);
17
// account_id = undefined <--> anonymous queries, which do exist.
18
19
const { query } = getParams(req);
20
21
try {
22
const result = await userQuery({ account_id, query });
23
res.json({ query: result });
24
} catch (err) {
25
res.json({ error: `${err.message ? err.message : err}` });
26
}
27
}
28
29
export default apiRoute({
30
userQuery: apiRouteOperation({
31
method: "POST",
32
openApiOperation: {
33
tags: ["Utils"],
34
},
35
})
36
.input({
37
contentType: "application/json",
38
body: UserQueryInputSchema,
39
})
40
.outputs([
41
{
42
status: 200,
43
contentType: "application/json",
44
body: UserQueryOutputSchema,
45
},
46
])
47
.handler(handle),
48
});
49
50