Skip to content

[Demo App] decrement credits only if user doesn't have subscription plan #425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vincanger
Copy link
Collaborator

Description

Fixes #418

@vincanger vincanger requested a review from sodic May 8, 2025 11:16
Copy link
Collaborator

@sodic sodic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, one small question.

console.log('Decrementing credits and saving response');
prisma.$transaction([decrementCredit, createResponse]);
await prisma.$transaction(transactions);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, I forgot this.

@@ -81,18 +74,35 @@ export const generateGptResponse: GenerateGptResponse<GenerateGptResponseInput,
},
});

const transactions: PrismaPromise<User | GptResponse>[] = [createResponse];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the explicit type annotation here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It complains when i try to push thedecrementCredits transaction if I already define it with [createResponse].

Instead, I could define an empty array and then push both transactions without needing the explicit type annotation, like this:

  const transactions = [];
  transactions.push(createResponse);
  
  if (!isUserSubscribed(context.user)) {
    //...
    transactions.push(decrementCredit);
  }

I'm not sure which is cleaner tbh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Demo AI app] Only decrement credits if there isn't an active subscription
2 participants