2020-08-26 00:23:45 +03:00
|
|
|
import { runQuery } from "~/node_common/data/utilities";
|
|
|
|
|
2020-08-26 01:09:12 +03:00
|
|
|
export default async ({ subscriberUserId, slateId, userId }) => {
|
2020-08-26 06:13:06 +03:00
|
|
|
const whereQuery = { owner_user_id: subscriberUserId };
|
|
|
|
|
|
|
|
if (slateId) {
|
|
|
|
whereQuery.target_slate_id = slateId;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (userId) {
|
|
|
|
whereQuery.target_user_id = userId;
|
|
|
|
}
|
|
|
|
|
2020-08-26 00:23:45 +03:00
|
|
|
return await runQuery({
|
|
|
|
label: "GET_SUBSCRIPTION_BY_ID",
|
|
|
|
queryFn: async (DB) => {
|
|
|
|
const query = await DB.select("*")
|
|
|
|
.from("subscriptions")
|
2020-08-26 06:13:06 +03:00
|
|
|
.where(whereQuery)
|
2020-08-26 00:23:45 +03:00
|
|
|
.first();
|
|
|
|
|
|
|
|
if (!query || query.error) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query.id) {
|
|
|
|
return JSON.parse(JSON.stringify(query));
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
errorFn: async (e) => {
|
|
|
|
return {
|
2020-09-13 01:08:36 +03:00
|
|
|
error: true,
|
|
|
|
decorator: "GET_SUBSCRIPTION_BY_ID",
|
2020-08-26 00:23:45 +03:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|