slate/node_common/data/methods/get-slates-by-user-id.js
2020-07-26 18:51:51 -07:00

28 lines
610 B
JavaScript

import { runQuery } from "~/node_common/data/utilities";
export default async ({ userId }) => {
return await runQuery({
label: "GET_SLATES_BY_USER_ID",
queryFn: async (DB) => {
const hasUser = (id) =>
DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ ownerId: id })]);
let query = await DB.select("*")
.from("slates")
.where(hasUser(userId));
if (!query || query.error) {
return [];
}
return query;
},
errorFn: async (e) => {
return {
error: "GET_SLATES_BY_USER_ID",
source: e,
};
},
});
};