FIX: Order result set of category search (#24027)

The previous order was too different from the logic we have on the
frontend.
This commit is contained in:
Bianca Nenciu 2023-10-19 20:28:23 +03:00 committed by GitHub
parent e31859a33a
commit ad433daf3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -352,12 +352,13 @@ class CategoriesController < ApplicationController
categories = categories.order(<<~SQL) if prioritized_category_id.present?
CASE
WHEN id = #{prioritized_category_id} OR parent_category_id = #{prioritized_category_id} THEN 0
ELSE 1
WHEN id = #{prioritized_category_id} THEN 1
WHEN parent_category_id = #{prioritized_category_id} THEN 2
ELSE 3
END
SQL
categories = categories.order(:read_restricted)
categories.order(:id)
render json: categories, each_serializer: SiteCategorySerializer
end