update date filter to pass integers to graphql (#5087)

* update date filter to pass ints to graphql

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>

* revert go mod

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>

* sign

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>

* gofmt

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>

* revert go ver

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>

---------

Signed-off-by: Priya Bibra <priya.bibra@airbnb.com>
Co-authored-by: Priya Bibra <priya.bibra@airbnb.com>
This commit is contained in:
pbibra 2025-04-09 23:29:56 -07:00 committed by GitHub
parent e9db75b884
commit 5ef8065704
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 6 deletions

View File

@ -592,9 +592,20 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
// Filtering based on date range (workflow's last updated time)
if request.Filter.DateRange != nil {
endDate := strconv.FormatInt(time.Now().UnixMilli(), 10)
endDate := time.Now().UnixMilli()
if request.Filter.DateRange.EndDate != nil {
endDate = *request.Filter.DateRange.EndDate
parsedEndDate, err := strconv.ParseInt(*request.Filter.DateRange.EndDate, 10, 64)
if err != nil {
return nil, errors.New("unable to parse end date")
}
endDate = parsedEndDate
}
// Note: StartDate cannot be passed in blank, must be "0"
startDate, err := strconv.ParseInt(request.Filter.DateRange.StartDate, 10, 64)
if err != nil {
return nil, errors.New("unable to parse start date")
}
filterWfDateStage := bson.D{
@ -602,7 +613,7 @@ func (c *ChaosExperimentHandler) ListExperiment(projectID string, request model.
"$match",
bson.D{{"updated_at", bson.D{
{"$lte", endDate},
{"$gte", request.Filter.DateRange.StartDate},
{"$gte", startDate},
}}},
},
}

View File

@ -419,16 +419,28 @@ func (c *ChaosExperimentRunHandler) ListExperimentRun(projectID string, request
// Filtering based on date range
if request.Filter.DateRange != nil {
endDate := strconv.FormatInt(time.Now().UnixMilli(), 10)
endDate := time.Now().UnixMilli()
if request.Filter.DateRange.EndDate != nil {
endDate = *request.Filter.DateRange.EndDate
parsedEndDate, err := strconv.ParseInt(*request.Filter.DateRange.EndDate, 10, 64)
if err != nil {
return nil, errors.New("unable to parse end date")
}
endDate = parsedEndDate
}
// Note: StartDate cannot be passed in blank, must be "0"
startDate, err := strconv.ParseInt(request.Filter.DateRange.StartDate, 10, 64)
if err != nil {
return nil, errors.New("unable to parse start date")
}
filterWfRunDateStage := bson.D{
{
"$match",
bson.D{{"updated_at", bson.D{
{"$lte", endDate},
{"$gte", request.Filter.DateRange.StartDate},
{"$gte", startDate},
}}},
},
}