shellphone.app/app/settings/queries/get-payments.ts
2021-10-01 00:59:35 +02:00

21 lines
610 B
TypeScript

import { resolver } from "blitz";
import db, { SubscriptionStatus } from "db";
import { getPayments } from "integrations/paddle";
export default resolver.pipe(resolver.authorize(), async (_ = null, { session }) => {
if (!session.orgId) {
return [];
}
const subscription = await db.subscription.findFirst({
where: { organizationId: session.orgId, status: SubscriptionStatus.active },
});
if (!subscription) {
return [];
}
const payments = await getPayments({ subscriptionId: subscription.paddleSubscriptionId });
return payments.sort((a, b) => b.payout_date.localeCompare(a.payout_date));
});