From 3072d4a33305c888b6650bd895526319c942f40e Mon Sep 17 00:00:00 2001 From: Nicolas Date: Tue, 3 Sep 2024 21:02:41 -0300 Subject: [PATCH] Nick: fixed .sort coupons and sentry to withAuth --- apps/api/src/lib/withAuth.ts | 2 ++ apps/api/src/services/billing/credit_billing.ts | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/apps/api/src/lib/withAuth.ts b/apps/api/src/lib/withAuth.ts index 1979907e..90cfb449 100644 --- a/apps/api/src/lib/withAuth.ts +++ b/apps/api/src/lib/withAuth.ts @@ -1,5 +1,6 @@ import { AuthResponse } from "../../src/types"; import { Logger } from "./logger"; +import * as Sentry from "@sentry/node"; let warningCount = 0; @@ -18,6 +19,7 @@ export function withAuth( try { return await originalFunction(...args); } catch (error) { + Sentry.captureException(error); Logger.error(`Error in withAuth function: ${error}`); return { success: false, error: error.message } as T; } diff --git a/apps/api/src/services/billing/credit_billing.ts b/apps/api/src/services/billing/credit_billing.ts index d828a54e..2cfea85a 100644 --- a/apps/api/src/services/billing/credit_billing.ts +++ b/apps/api/src/services/billing/credit_billing.ts @@ -40,14 +40,15 @@ export async function supaBillTeam(team_id: string, credits: number) { ]); let couponCredits = 0; + let sortedCoupons = []; + if (coupons && coupons.length > 0) { couponCredits = coupons.reduce( (total, coupon) => total + coupon.credits, 0 ); + sortedCoupons = [...coupons].sort((a, b) => b.credits - a.credits); } - - let sortedCoupons = coupons.sort((a, b) => b.credits - a.credits); // using coupon credits: if (couponCredits > 0) { // if there is no subscription and they have enough coupon credits