mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
feat(#54): Add credit usage dashboard
This commit is contained in:
@@ -451,6 +451,28 @@ const getUserCredits = async (userId: string) => {
|
||||
return creditData.credits_remaining;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches the credit transaction history for a specific user.
|
||||
*
|
||||
* @param userId - The ID of the user whose transactions are to be fetched.
|
||||
* @returns Array of transaction records containing credits_change, description, and created_at.
|
||||
*/
|
||||
export const getUserCreditTransactions = async (userId: string) => {
|
||||
if (!userId) throw new Error('User ID is required');
|
||||
|
||||
const { data, error } = await supabaseAdmin
|
||||
.from('credit_transactions')
|
||||
.select('credits_change, description, created_at')
|
||||
.eq('user_id', userId)
|
||||
.order('created_at', { ascending: false }); // Orders transactions with the latest ones first
|
||||
|
||||
if (error) {
|
||||
throw new Error(`Error fetching transactions: ${error.message}`);
|
||||
}
|
||||
|
||||
return data || [];
|
||||
};
|
||||
|
||||
type ProductWithPrices = Product & {
|
||||
prices: Price[];
|
||||
actualPrice?: number;
|
||||
|
||||
Reference in New Issue
Block a user