2020-08-28 01:05:20 +03:00
|
|
|
import * as Serializers from "~/common/serializers";
|
|
|
|
|
2020-08-26 04:27:05 +03:00
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
|
|
|
|
export default async ({ query }) => {
|
|
|
|
return await runQuery({
|
|
|
|
label: "QUERY_USERS",
|
|
|
|
queryFn: async (DB) => {
|
|
|
|
const r = await DB.select("id", "username", "data")
|
|
|
|
.from("users")
|
|
|
|
.where("username", "like", `%${query}%`)
|
|
|
|
.limit(24);
|
|
|
|
|
|
|
|
if (!r || r.error) {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
2020-08-28 01:05:20 +03:00
|
|
|
const sanitized = r.map((each) => Serializers.user(each));
|
2020-08-26 04:34:32 +03:00
|
|
|
return JSON.parse(JSON.stringify(sanitized));
|
2020-08-26 04:27:05 +03:00
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
|
|
|
return {
|
|
|
|
error: "QUERY_USERS",
|
|
|
|
source: e,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|