20 lines
836 B
TypeScript
20 lines
836 B
TypeScript
import type { Sponsoring } from '@/types/nostr'
|
|
import { objectCache } from './objectCache'
|
|
import { getCachedObjectById } from './helpers/queryHelpers'
|
|
|
|
export async function getSponsoringById(sponsoringId: string, _timeoutMs: number = 5000): Promise<Sponsoring | null> {
|
|
return getCachedObjectById<Sponsoring>('sponsoring', sponsoringId)
|
|
}
|
|
|
|
export async function getSponsoringByAuthor(authorPubkey: string, _timeoutMs: number = 5000): Promise<Sponsoring[]> {
|
|
// Read only from IndexedDB cache
|
|
const allSponsoring = await objectCache.getAll('sponsoring')
|
|
const sponsoring = allSponsoring as Sponsoring[]
|
|
|
|
// Filter by authorPubkey
|
|
const authorSponsoring = sponsoring.filter((s) => s.authorPubkey === authorPubkey)
|
|
|
|
// Sort by creation date descending
|
|
return authorSponsoring.sort((a, b) => b.createdAt - a.createdAt)
|
|
}
|