chore: update function parameters planId instead of priceId

This commit is contained in:
javayhu 2025-08-23 20:07:32 +08:00
parent 669ac94bad
commit 1ff42009d8

View File

@ -2,7 +2,7 @@ import { randomUUID } from 'crypto';
import { websiteConfig } from '@/config/website'; import { websiteConfig } from '@/config/website';
import { getDb } from '@/db'; import { getDb } from '@/db';
import { creditTransaction, userCredit } from '@/db/schema'; import { creditTransaction, userCredit } from '@/db/schema';
import { findPlanByPriceId } from '@/lib/price-plan'; import { findPlanByPlanId, findPlanByPriceId } from '@/lib/price-plan';
import { addDays, isAfter } from 'date-fns'; import { addDays, isAfter } from 'date-fns';
import { and, asc, eq, gt, isNull, not, or } from 'drizzle-orm'; import { and, asc, eq, gt, isNull, not, or } from 'drizzle-orm';
import { CREDIT_TRANSACTION_TYPE } from './types'; import { CREDIT_TRANSACTION_TYPE } from './types';
@ -442,11 +442,11 @@ export async function addRegisterGiftCredits(userId: string) {
/** /**
* Add free monthly credits * Add free monthly credits
* @param userId - User ID * @param userId - User ID
* @param priceId - Price ID * @param planId - Plan ID
*/ */
export async function addMonthlyFreeCredits(userId: string, priceId: string) { export async function addMonthlyFreeCredits(userId: string, planId: string) {
// NOTICE: make sure the free plan is not disabled and has credits enabled // NOTICE: make sure the free plan is not disabled and has credits enabled
const pricePlan = findPlanByPriceId(priceId); const pricePlan = findPlanByPlanId(planId);
if ( if (
!pricePlan || !pricePlan ||
pricePlan.disabled || pricePlan.disabled ||
@ -455,7 +455,7 @@ export async function addMonthlyFreeCredits(userId: string, priceId: string) {
!pricePlan.credits.enable !pricePlan.credits.enable
) { ) {
console.log( console.log(
`addMonthlyFreeCredits, no credits configured for plan ${priceId}` `addMonthlyFreeCredits, no credits configured for plan ${planId}`
); );
return; return;
} }