Skip to content

Commit 5ef8065

Browse files
pbibraPriya Bibra
and
Priya Bibra
authored
update date filter to pass integers to graphql (#5087)
* update date filter to pass ints to graphql Signed-off-by: Priya Bibra <[email protected]> * revert go mod Signed-off-by: Priya Bibra <[email protected]> * sign Signed-off-by: Priya Bibra <[email protected]> * gofmt Signed-off-by: Priya Bibra <[email protected]> * revert go ver Signed-off-by: Priya Bibra <[email protected]> --------- Signed-off-by: Priya Bibra <[email protected]> Co-authored-by: Priya Bibra <[email protected]>
1 parent e9db75b commit 5ef8065

File tree

2 files changed

+29
-6
lines changed
  • chaoscenter/graphql/server/pkg

2 files changed

+29
-6
lines changed

chaoscenter/graphql/server/pkg/chaos_experiment/handler/handler.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,28 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
592592

593593
// Filtering based on date range (workflow's last updated time)
594594
if request.Filter.DateRange != nil {
595-
endDate := strconv.FormatInt(time.Now().UnixMilli(), 10)
595+
endDate := time.Now().UnixMilli()
596596
if request.Filter.DateRange.EndDate != nil {
597-
endDate = *request.Filter.DateRange.EndDate
597+
parsedEndDate, err := strconv.ParseInt(*request.Filter.DateRange.EndDate, 10, 64)
598+
if err != nil {
599+
return nil, errors.New("unable to parse end date")
600+
}
601+
602+
endDate = parsedEndDate
603+
}
604+
605+
// Note: StartDate cannot be passed in blank, must be "0"
606+
startDate, err := strconv.ParseInt(request.Filter.DateRange.StartDate, 10, 64)
607+
if err != nil {
608+
return nil, errors.New("unable to parse start date")
598609
}
599610

600611
filterWfDateStage := bson.D{
601612
{
602613
"$match",
603614
bson.D{{"updated_at", bson.D{
604615
{"$lte", endDate},
605-
{"$gte", request.Filter.DateRange.StartDate},
616+
{"$gte", startDate},
606617
}}},
607618
},
608619
}

chaoscenter/graphql/server/pkg/chaos_experiment_run/handler/handler.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -419,16 +419,28 @@ func (c *ChaosExperimentRunHandler) ListExperimentRun(projectID string, request
419419

420420
// Filtering based on date range
421421
if request.Filter.DateRange != nil {
422-
endDate := strconv.FormatInt(time.Now().UnixMilli(), 10)
422+
endDate := time.Now().UnixMilli()
423423
if request.Filter.DateRange.EndDate != nil {
424-
endDate = *request.Filter.DateRange.EndDate
424+
parsedEndDate, err := strconv.ParseInt(*request.Filter.DateRange.EndDate, 10, 64)
425+
if err != nil {
426+
return nil, errors.New("unable to parse end date")
427+
}
428+
429+
endDate = parsedEndDate
425430
}
431+
432+
// Note: StartDate cannot be passed in blank, must be "0"
433+
startDate, err := strconv.ParseInt(request.Filter.DateRange.StartDate, 10, 64)
434+
if err != nil {
435+
return nil, errors.New("unable to parse start date")
436+
}
437+
426438
filterWfRunDateStage := bson.D{
427439
{
428440
"$match",
429441
bson.D{{"updated_at", bson.D{
430442
{"$lte", endDate},
431-
{"$gte", request.Filter.DateRange.StartDate},
443+
{"$gte", startDate},
432444
}}},
433445
},
434446
}

0 commit comments

Comments
 (0)