Browse Source

filter time period events on startup (#21)

Klaudiusz Dembler 3 years ago
parent
commit
0c5d30c87c
2 changed files with 6 additions and 2 deletions
  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))
     array.sort((a, b) => (a.views > b.views ? -1 : 1))
   }
   }
 
 
-  public filterEventsByPeriod(timePeriodDays: number) {
+  public filterEventsByPeriod(timePeriodDays: 7 | 30) {
     const mappedPeriod = mapPeriods(timePeriodDays)
     const mappedPeriod = mapPeriods(timePeriodDays)
     const viewEvents = this.timePeriodEvents[mappedPeriod]
     const viewEvents = this.timePeriodEvents[mappedPeriod]
 
 
@@ -150,6 +150,10 @@ export class ViewsAggregate {
     events.forEach((event) => {
     events.forEach((event) => {
       aggregate.applyEvent(event)
       aggregate.applyEvent(event)
     })
     })
+
+    aggregate.filterEventsByPeriod(7)
+    aggregate.filterEventsByPeriod(30)
+
     return aggregate
     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',
     description: 'timePeriodDays must take one of the following values: 7, 30',
   })
   })
   @IsIn([7, 30])
   @IsIn([7, 30])
-  timePeriodDays: number
+  timePeriodDays: 7 | 30
 
 
   @Field(() => Int, { nullable: true })
   @Field(() => Int, { nullable: true })
   limit?: number
   limit?: number