2020-08-28 07:34:50 +03:00
|
|
|
import * as Serializers from "~/node_common/serializers";
|
2020-08-28 01:05:20 +03:00
|
|
|
|
2020-08-26 04:27:05 +03:00
|
|
|
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 [];
|
|
|
|
}
|
|
|
|
|
2020-08-26 06:32:40 +03:00
|
|
|
const sanitized = r
|
|
|
|
.filter((each) => each.data.public)
|
2020-08-28 01:05:20 +03:00
|
|
|
.map((each) => Serializers.slate(each));
|
2020-08-26 06:13:06 +03:00
|
|
|
return JSON.parse(JSON.stringify(sanitized));
|
2020-08-26 04:27:05 +03:00
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
2020-09-01 02:47:53 +03:00
|
|
|
console.log({
|
2020-09-13 01:08:36 +03:00
|
|
|
error: true,
|
|
|
|
decorator: "QUERY_SLATES",
|
2020-09-01 02:47:53 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
return [];
|
2020-08-26 04:27:05 +03:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|