2020-07-17 13:24:20 +03:00
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
|
|
|
|
export default async ({ username }) => {
|
|
|
|
return await runQuery({
|
|
|
|
label: "DELETE_USER_BY_USERNAME",
|
|
|
|
queryFn: async (DB) => {
|
2020-09-13 07:47:20 +03:00
|
|
|
const query = await DB.select("id")
|
|
|
|
.from("users")
|
|
|
|
.where({ username })
|
|
|
|
.first();
|
|
|
|
|
|
|
|
if (!query || query.error || !query.id) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const id = query.id;
|
|
|
|
|
|
|
|
const deletedSubscriptions = await DB.from("subscriptions")
|
|
|
|
.where({ owner_user_id: id })
|
|
|
|
.orWhere({ target_user_id: id })
|
|
|
|
.del();
|
|
|
|
const deletedTrusted = await DB.from("trusted")
|
|
|
|
.where({ owner_user_id: id })
|
|
|
|
.orWhere({ target_user_id: id })
|
|
|
|
.del();
|
|
|
|
|
2020-09-13 01:08:36 +03:00
|
|
|
const data = await DB.from("users").where({ username }).del();
|
2020-07-17 13:24:20 +03:00
|
|
|
|
|
|
|
return 1 === data;
|
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
|
|
|
return {
|
2020-09-13 01:08:36 +03:00
|
|
|
error: true,
|
|
|
|
decorator: "DELETE_USER_BY_USERNAME",
|
2020-07-17 13:24:20 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|