Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
fix: check if there is data (#28)
Browse files Browse the repository at this point in the history
* fix: check if there is data

* fix: remove the else

* fix: remove the function

* fix: use format for dates
  • Loading branch information
Bashamega authored Oct 18, 2024
1 parent 595791d commit d1cc055
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/app.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,19 @@ export class AppService {
constructor(private prisma: PrismaService) {}

async getStats(): Promise<any> {
return this.prisma.trending.groupBy({
const stats = await this.prisma.trending.groupBy({
by: ['createdAt', 'type'],
_count: { id: true },
});
if (stats.length > 0) {
return stats;
}
const yesterday = new Date();
yesterday.setDate(yesterday.getDate() - 1);

const getYesterdaysDate = format(yesterday, 'yyyy-MM-dd');

this.getTrending('daily', getYesterdaysDate);
}

async getTrending(type: string = 'daily', date: string): Promise<Trending[]> {
Expand Down

0 comments on commit d1cc055

Please sign in to comment.