Skip to content

Commit

Permalink
Fix #380 View logs list api sort based on Descending order
Browse files Browse the repository at this point in the history
  • Loading branch information
albinpa authored and georgepadayatti committed Oct 27, 2023
1 parent b9e21fe commit b8a24da
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/v2/handler/audit/audit_admin_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,24 @@ func AuditGetOrgLogs(w http.ResponseWriter, r *http.Request) {
actionLogRepo := actionlog.ActionLogRepository{}
actionLogRepo.Init(organisationId)

var filter primitive.M
var pipeline []primitive.M

logType, err := ParseListActionLogQueryParams(r)
if err != nil && errors.Is(err, ActionLogTypeIsMissingError) {
filter = actionLogRepo.DefaultFilter
pipeline = []bson.M{{"$sort": bson.M{"timestamp": -1}}}
} else {
filter = common.CombineFilters(actionLogRepo.DefaultFilter, bson.M{"type": logType})
pipeline = []bson.M{{"$match": bson.M{"type": logType}}, {"$sort": bson.M{"timestamp": -1}}}
}

// Return all action logs
var actionLogs []actionlog.ActionLog
query := paginate.PaginateDBObjectsQuery{
Filter: filter,
query := paginate.PaginateDBObjectsQueryUsingPipeline{
Pipeline: pipeline,
Collection: actionlog.Collection(),
Context: context.Background(),
Limit: limit,
Offset: offset,
}
result, err := paginate.PaginateDBObjects(query, &actionLogs)
result, err := paginate.PaginateDBObjectsUsingPipeline(query, &actionLogs)
if err != nil {
if errors.Is(err, paginate.EmptyDBError) {
emptyActionLogs := make([]interface{}, 0)
Expand Down

0 comments on commit b8a24da

Please sign in to comment.