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/accounts/search.ts
Views: 687
1
/*
2
Search for accounts matching a given query.
3
4
If user is signed in, then their account_id is used to prioritize the search.
5
*/
6
7
import userSearch from "@cocalc/server/accounts/search";
8
import type { User } from "@cocalc/server/accounts/search";
9
import getParams from "lib/api/get-params";
10
11
import { apiRoute, apiRouteOperation } from "lib/api";
12
import {
13
AccountSearchInputSchema,
14
AccountSearchOutputSchema,
15
} from "lib/api/schema/accounts/search";
16
17
async function handle(req, res) {
18
try {
19
return res.json(await doUserSearch(req));
20
} catch (err) {
21
res.json({ error: err.message });
22
}
23
}
24
25
async function doUserSearch(req): Promise<User[]> {
26
const { query } = getParams(req);
27
return await userSearch({ query });
28
}
29
30
export default apiRoute({
31
search: apiRouteOperation({
32
method: "POST",
33
openApiOperation: {
34
tags: ["Accounts"],
35
},
36
})
37
.input({
38
contentType: "application/json",
39
body: AccountSearchInputSchema,
40
})
41
.outputs([
42
{
43
status: 200,
44
contentType: "application/json",
45
body: AccountSearchOutputSchema,
46
},
47
])
48
.handler(handle),
49
});
50
51