import type { Purchase } from '@/types/nostr' import { getCachedObjectById } from './helpers/queryHelpers' import { objectCache } from './objectCache' export async function getPurchaseById(purchaseId: string, _timeoutMs: number = 5000): Promise { return getCachedObjectById('purchase', purchaseId) } export async function getPurchasesForArticle(articleId: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allPurchases = await objectCache.getAll('purchase') const purchases = allPurchases as Purchase[] // Filter by articleId const articlePurchases = purchases.filter((purchase) => purchase.articleId === articleId) // Sort by creation date descending return articlePurchases.sort((a, b) => b.createdAt - a.createdAt) } export async function getPurchasesByPayer(payerPubkey: string, _timeoutMs: number = 5000): Promise { // Read only from IndexedDB cache const allPurchases = await objectCache.getAll('purchase') const purchases = allPurchases as Purchase[] // Filter by payerPubkey const payerPurchases = purchases.filter((purchase) => purchase.payerPubkey === payerPubkey) // Sort by creation date descending return payerPurchases.sort((a, b) => b.createdAt - a.createdAt) }