slate/pages/api/search/[query].js
2020-09-02 17:35:41 -07:00

23 lines
549 B
JavaScript

import * as Strings from "~/common/strings";
import * as Data from "~/node_common/data";
export default async (req, res) => {
if (Strings.isEmpty(req.query.query)) {
return {
decorator: "SERVER_SEARCH_NO_QUERY",
data: { results: [] },
};
}
const { query } = req.query;
const users = await Data.queryUsers({ query });
const slates = await Data.querySlates({ query });
let results = [...users, ...slates];
return res.status(200).send({
decorator: "SERVER_SEARCH_QUERY",
data: { query, results },
});
};