From 300bfa8e659bd7366c775b096520c58adc26b6ed Mon Sep 17 00:00:00 2001 From: m5r Date: Fri, 1 Oct 2021 23:05:07 +0200 Subject: [PATCH] smol changes --- app/pages/_app.tsx | 2 +- app/settings/pages/settings/billing.tsx | 2 +- app/settings/queries/get-payments.ts | 13 +++++++------ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/app/pages/_app.tsx b/app/pages/_app.tsx index d698c68..0ed7c5e 100644 --- a/app/pages/_app.tsx +++ b/app/pages/_app.tsx @@ -26,7 +26,7 @@ export default function App({ Component, pageProps }: AppProps) { useEffect(() => { if (session.userId) { Sentry.setUser({ - id: session.userId.toString(), + id: session.userId, orgId: session.orgId, }); } diff --git a/app/settings/pages/settings/billing.tsx b/app/settings/pages/settings/billing.tsx index caede72..ceae33a 100644 --- a/app/settings/pages/settings/billing.tsx +++ b/app/settings/pages/settings/billing.tsx @@ -78,7 +78,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, res } const subscription = await db.subscription.findFirst({ where: { organizationId: session.orgId, - status: SubscriptionStatus.active, + status: { not: SubscriptionStatus.deleted }, }, }); if (!subscription) { diff --git a/app/settings/queries/get-payments.ts b/app/settings/queries/get-payments.ts index 2fbc496..5aa9aef 100644 --- a/app/settings/queries/get-payments.ts +++ b/app/settings/queries/get-payments.ts @@ -1,6 +1,6 @@ import { resolver } from "blitz"; -import db, { SubscriptionStatus } from "db"; +import db from "db"; import { getPayments } from "integrations/paddle"; export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => { @@ -8,13 +8,14 @@ export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) return []; } - const subscription = await db.subscription.findFirst({ - where: { organizationId: session.orgId, status: SubscriptionStatus.active }, - }); - if (!subscription) { + const subscriptions = await db.subscription.findMany({ where: { organizationId: session.orgId } }); + if (subscriptions.length === 0) { return []; } - const payments = await getPayments({ subscriptionId: subscription.paddleSubscriptionId }); + const paymentsBySubscription = await Promise.all( + subscriptions.map((subscription) => getPayments({ subscriptionId: subscription.paddleSubscriptionId })), + ); + const payments = paymentsBySubscription.flat(); return payments.sort((a, b) => b.payout_date.localeCompare(a.payout_date)); });