Ver Fonte

filter time period events on startup (#21)

Klaudiusz Dembler há 3 anos atrás
pai
commit
0c5d30c87c
2 ficheiros alterados com 6 adições e 2 exclusões
  1. 5 1
      src/aggregates/views.ts
  2. 1 1
      src/resolvers/viewsInfo.ts

+ 5 - 1
src/aggregates/views.ts

@@ -65,7 +65,7 @@ export class ViewsAggregate {
     array.sort((a, b) => (a.views > b.views ? -1 : 1))
   }
 
-  public filterEventsByPeriod(timePeriodDays: number) {
+  public filterEventsByPeriod(timePeriodDays: 7 | 30) {
     const mappedPeriod = mapPeriods(timePeriodDays)
     const viewEvents = this.timePeriodEvents[mappedPeriod]
 
@@ -150,6 +150,10 @@ export class ViewsAggregate {
     events.forEach((event) => {
       aggregate.applyEvent(event)
     })
+
+    aggregate.filterEventsByPeriod(7)
+    aggregate.filterEventsByPeriod(30)
+
     return aggregate
   }
 

+ 1 - 1
src/resolvers/viewsInfo.ts

@@ -24,7 +24,7 @@ class MostViewedArgs {
     description: 'timePeriodDays must take one of the following values: 7, 30',
   })
   @IsIn([7, 30])
-  timePeriodDays: number
+  timePeriodDays: 7 | 30
 
   @Field(() => Int, { nullable: true })
   limit?: number