Skip to content

Commit

Permalink
🐛 Fix news fetching for the exemple
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Sep 17, 2024
1 parent 415fc06 commit e99b0fc
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
4 changes: 2 additions & 2 deletions iac/DashboardWebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function DashboardWebApp({ stack }: StackContext) {
sessionEncryptionKey,
mongoBusinessUri,
contentMinterPrivateKey,
backendUrl
backendUrl,
} = use(ConfigStack);
const configs = [
alchemyApiKey,
Expand All @@ -26,7 +26,7 @@ export function DashboardWebApp({ stack }: StackContext) {
sessionEncryptionKey,
mongoBusinessUri,
contentMinterPrivateKey,
backendUrl
backendUrl,
];

// Base domain for our whole app
Expand Down
4 changes: 2 additions & 2 deletions iac/WalletWebApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function WalletAppStack({ stack }: StackContext) {
nexusRpcSecret,
vapidPublicKey,
vapidPrivateKey,
backendUrl
backendUrl,
} = use(ConfigStack);
const configs = [
sessionEncryptionKey,
Expand All @@ -32,7 +32,7 @@ export function WalletAppStack({ stack }: StackContext) {
nexusRpcSecret,
vapidPublicKey,
vapidPrivateKey,
backendUrl
backendUrl,
];

// Get the interaction queue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ export class NewsRepository {
/**
* Get a random news
*/
public async getRandomNews() {
const documents = await this.collection
.aggregate<WithId<NewsDocument>>([{ $sample: { size: 1 } }])
public async getRandomNews({ count }: { count: number }) {
return await this.collection
.aggregate<WithId<NewsDocument>>([{ $sample: { size: count } }])
.toArray();
return documents[0];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class WorldNewsApiRepository {
url.searchParams.append("language", "en");
url.searchParams.append(
"categories",
"sports,business,technology,science,environment,health"
"sports,technology,science,environment,health"
);
url.searchParams.append("min-sentiment", "-0.2");
url.searchParams.append("max-sentiment", "0.9");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const newsRoutes = (app: NewsPaperContextApp) =>
// Get top 10 positive news
const latestPositiveNews =
await newsDbRepository.getMostPositiveNews({
limit: 5,
limit: 10,
offset: 0,
});

Expand All @@ -37,17 +37,20 @@ export const newsRoutes = (app: NewsPaperContextApp) =>
const featuredNews = latestPositiveNews.slice(5, 10);

// Get a random news
const randomNews = await newsDbRepository.getRandomNews();
const randomNews = await newsDbRepository.getRandomNews({
count: 2,
});

// Get a hero news
const heroNews = await newsDbRepository.getRandomNews();
// Get a hero news + quick bytes one
const hero = newsDocumentToLightNews(randomNews[0]);
const quickByte = newsDocumentToLightNews(randomNews[1]);

return {
positives: positiveNews.map(newsDocumentToLightNews),
featured: featuredNews.map(newsDocumentToLightNews),
latest: latestNews.map(newsDocumentToLightNews),
quickByte: newsDocumentToLightNews(randomNews),
hero: newsDocumentToLightNews(heroNews),
quickByte,
hero,
};
},
{
Expand Down

0 comments on commit e99b0fc

Please sign in to comment.