2020-08-03 01:06:46 +03:00
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
|
|
|
|
export default async ({ userId }) => {
|
|
|
|
return await runQuery({
|
|
|
|
label: "DELETE_SLATES_FOR_USER_ID",
|
|
|
|
queryFn: async (DB) => {
|
2020-08-07 05:17:49 +03:00
|
|
|
const hasUser = (id) =>
|
|
|
|
DB.raw(`?? @> ?::jsonb`, ["data", JSON.stringify({ ownerId: id })]);
|
|
|
|
const data = await DB.select("*")
|
|
|
|
.from("slates")
|
|
|
|
.where(hasUser(userId))
|
|
|
|
.del();
|
2020-08-03 01:06:46 +03:00
|
|
|
|
|
|
|
return 1 === data;
|
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
|
|
|
return {
|
2020-09-13 01:08:36 +03:00
|
|
|
error: true,
|
|
|
|
decorator: "DELETE_SLATES_FOR_USER_ID",
|
2020-08-03 01:06:46 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|