smol changes

This commit is contained in:
m5r 2021-10-01 23:05:07 +02:00
parent 771fea4d7b
commit 300bfa8e65
3 changed files with 9 additions and 8 deletions

View File

@ -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,
});
}

View File

@ -78,7 +78,7 @@ export const getServerSideProps: GetServerSideProps<Props> = async ({ req, res }
const subscription = await db.subscription.findFirst({
where: {
organizationId: session.orgId,
status: SubscriptionStatus.active,
status: { not: SubscriptionStatus.deleted },
},
});
if (!subscription) {

View File

@ -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));
});