credits_get_add_pattern
Generate code to add credits to users programmatically by specifying transaction types like purchase, refund, or bonus.
Instructions
Get the code snippet for programmatically adding credits to a user with a specific transaction type.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| transactionType | Yes | The CreditTransactionType to use |
Implementation Reference
- src/tools/credits.ts:15-54 (handler)The handler implementation for the `credits_get_add_pattern` tool.
server.tool( 'credits_get_add_pattern', 'Get the code snippet for programmatically adding credits to a user with a specific transaction type.', { transactionType: z .enum(['INITIAL', 'PURCHASE', 'USAGE', 'REFUND', 'BONUS', 'EXPIRY', 'REDEMPTION']) .describe('The CreditTransactionType to use'), }, async ({ transactionType }) => { const descriptions: Record<string, string> = { INITIAL: 'Grant starting credits to a new user', PURCHASE: 'Credit top-up purchased by the user', USAGE: 'Manual usage deduction (prefer CreditsGuard for route-level deduction)', REFUND: 'Refund credits after a failed or cancelled operation', BONUS: 'Promotional or reward credits', EXPIRY: 'Expire/remove unused credits', REDEMPTION: 'Redeem credits (e.g. voucher, referral)', }; const snippet = `// ${descriptions[transactionType]} import { CreditsService } from '../credits/credits.service'; import { CreditTransactionType } from '../credits/entities/credit-transaction.entity'; // Inject in constructor: constructor(private readonly creditsService: CreditsService) {} // Call: await this.creditsService.addCredits( user, // User entity 100, // amount (positive to add, negative to deduct) CreditTransactionType.${transactionType}, 'Optional description', // optional 'optional-ref-id', // optional — external reference (e.g. Polar order ID) );`; return { content: [{ type: 'text', text: snippet }], }; } );