refactor: remove updateUserLastRefreshAt function and its calls to streamline credit update logic
This commit is contained in:
parent
258ddad399
commit
afdaeba2be
@ -49,23 +49,6 @@ export async function updateUserCredits(userId: string, credits: number) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Update user's last refresh time
|
|
||||||
* @param userId - User ID
|
|
||||||
* @param date - Last refresh time
|
|
||||||
*/
|
|
||||||
export async function updateUserLastRefreshAt(userId: string, date: Date) {
|
|
||||||
try {
|
|
||||||
const db = await getDb();
|
|
||||||
await db
|
|
||||||
.update(userCredit)
|
|
||||||
.set({ lastRefreshAt: date, updatedAt: new Date() })
|
|
||||||
.where(eq(userCredit.userId, userId));
|
|
||||||
} catch (error) {
|
|
||||||
console.error('updateUserLastRefreshAt, error:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Write a credit transaction record
|
* Write a credit transaction record
|
||||||
* @param params - Credit transaction parameters
|
* @param params - Credit transaction parameters
|
||||||
@ -483,9 +466,6 @@ export async function addMonthlyFreeCredits(userId: string, planId: string) {
|
|||||||
expireDays,
|
expireDays,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update last refresh time for free monthly credits
|
|
||||||
await updateUserLastRefreshAt(userId, now);
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`addMonthlyFreeCredits, ${credits} credits for user ${userId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
`addMonthlyFreeCredits, ${credits} credits for user ${userId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
||||||
);
|
);
|
||||||
@ -535,9 +515,6 @@ export async function addSubscriptionCredits(userId: string, priceId: string) {
|
|||||||
expireDays,
|
expireDays,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update last refresh time for subscription credits
|
|
||||||
await updateUserLastRefreshAt(userId, now);
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`addSubscriptionCredits, ${credits} credits for user ${userId}, priceId: ${priceId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
`addSubscriptionCredits, ${credits} credits for user ${userId}, priceId: ${priceId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
||||||
);
|
);
|
||||||
@ -591,9 +568,6 @@ export async function addLifetimeMonthlyCredits(
|
|||||||
expireDays,
|
expireDays,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Update last refresh time for lifetime credits
|
|
||||||
await updateUserLastRefreshAt(userId, now);
|
|
||||||
|
|
||||||
console.log(
|
console.log(
|
||||||
`addLifetimeMonthlyCredits, ${credits} credits for user ${userId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
`addLifetimeMonthlyCredits, ${credits} credits for user ${userId}, date: ${now.getFullYear()}-${now.getMonth() + 1}`
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user