32 lines
1.3 KiB
TypeScript
32 lines
1.3 KiB
TypeScript
import type { ReviewTip } from '@/types/nostr'
|
|
import { objectCache } from './objectCache'
|
|
import { getCachedObjectById } from './helpers/queryHelpers'
|
|
|
|
export async function getReviewTipById(reviewTipId: string, _timeoutMs: number = 5000): Promise<ReviewTip | null> {
|
|
return await getCachedObjectById<ReviewTip>('review_tip', reviewTipId)
|
|
}
|
|
|
|
export async function getReviewTipsForArticle(articleId: string, _timeoutMs: number = 5000): Promise<ReviewTip[]> {
|
|
// Read only from IndexedDB cache
|
|
const allReviewTips = await objectCache.getAll('review_tip')
|
|
const reviewTips = allReviewTips as ReviewTip[]
|
|
|
|
// Filter by articleId
|
|
const articleReviewTips = reviewTips.filter((tip) => tip.articleId === articleId)
|
|
|
|
// Sort by creation date descending
|
|
return articleReviewTips.sort((a, b) => b.createdAt - a.createdAt)
|
|
}
|
|
|
|
export async function getReviewTipsForReview(reviewId: string, _timeoutMs: number = 5000): Promise<ReviewTip[]> {
|
|
// Read only from IndexedDB cache
|
|
const allReviewTips = await objectCache.getAll('review_tip')
|
|
const reviewTips = allReviewTips as ReviewTip[]
|
|
|
|
// Filter by reviewId
|
|
const reviewReviewTips = reviewTips.filter((tip) => tip.reviewId === reviewId)
|
|
|
|
// Sort by creation date descending
|
|
return reviewReviewTips.sort((a, b) => b.createdAt - a.createdAt)
|
|
}
|