mirror of
https://github.com/filecoin-project/slate.git
synced 2024-12-18 22:51:32 +03:00
31 lines
737 B
JavaScript
31 lines
737 B
JavaScript
import * as Serializers from "~/common/serializers";
|
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
export default async ({ query }) => {
|
|
return await runQuery({
|
|
label: "QUERY_SLATES",
|
|
queryFn: async (DB) => {
|
|
const r = await DB.select("id", "slatename", "data")
|
|
.from("slates")
|
|
.where("slatename", "like", `%${query}%`)
|
|
.limit(24);
|
|
|
|
if (!r || r.error) {
|
|
return [];
|
|
}
|
|
|
|
const sanitized = r
|
|
.filter((each) => each.data.public)
|
|
.map((each) => Serializers.slate(each));
|
|
return JSON.parse(JSON.stringify(sanitized));
|
|
},
|
|
errorFn: async (e) => {
|
|
return {
|
|
error: "QUERY_SLATES",
|
|
source: e,
|
|
};
|
|
},
|
|
});
|
|
};
|