Skip to content

Commit

Permalink
Fix user order history sorting (#859)
Browse files Browse the repository at this point in the history
* Fix user order history sorting

* Revert .gitignore

Co-authored-by: Guido de Jong <[email protected]>

---------

Co-authored-by: Guido de Jong <[email protected]>
  • Loading branch information
wilco375 and guidojw authored Mar 24, 2023
1 parent 4acc927 commit dfe9ba5
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def activities # rubocop:disable Metrics/AbcSize
authorize user

user_orders = policy_scope(Order).orders_for(user)
activities = Activity.select(%i[id title start_time]).joins(:orders).merge(user_orders).distinct
activities = Activity.select(%i[id title start_time]).joins(:orders).merge(user_orders).distinct.order(start_time: :desc, id: :desc)
activity_totals = user_orders.joins(:order_rows).group(:activity_id).sum('product_count * price_per_product')
activities_hash = activities.map { |a| { id: a.id, title: a.title, start_time: a.start_time, order_total: activity_totals[a.id] } }

Expand Down
3 changes: 1 addition & 2 deletions app/javascript/components/user/OrderHistory.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ export default {
let promise = axios.get('/users/'+this.user.id+'/activities');
promise.then((response) => {
const activities = response.data;
activities.sort((activity1, activity2) => activity2.start_time - activity1.start_time);
let activities = response.data;
activities.forEach(activity => {
activity.detailsShowing = false;
activity.toggleDetails = (() => activity.detailsShowing = !activity.detailsShowing);
Expand Down

0 comments on commit dfe9ba5

Please sign in to comment.