Skip to content

Commit

Permalink
fix: token collection sort by type is require (#1879)
Browse files Browse the repository at this point in the history
Signed-off-by: Miles Zhang <[email protected]>
  • Loading branch information
zmcNotafraid authored May 23, 2024
1 parent 14cd518 commit 9e1c4e7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/api/v2/nft/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def sort_collections(records)
order = "asc"
end
if sort == "block_timestamp"
TokenCollection.left_joins(:cell).order("cell_outputs.#{sort} #{order}")
records.left_joins(:cell).order("cell_outputs.#{sort} #{order}")
else
records.order("#{sort} #{order}")
end
Expand Down
8 changes: 4 additions & 4 deletions test/controllers/api/v2/nft/collections_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class NFT::CollectionsControllerTest < ActionDispatch::IntegrationTest
cell1 = create(:cell_output, block_timestamp: timestamp, block: block1, ckb_transaction: transaction1)
cell3 = create(:cell_output, block_timestamp: 1.day.ago.to_i * 1000, block: block3, ckb_transaction: transaction3)
tc1 = create :token_collection, name: "token1", cell_id: cell1.id
tc2 = create :token_collection, name: "token2"
_tc3 = create :token_collection, name: "token3", cell_id: cell3.id
_tc2 = create :token_collection, name: "token2", standard: "cota"
tc3 = create :token_collection, name: "token3", cell_id: cell3.id

get api_v2_nft_collections_url, params: { sort: "timestamp.desc" }
get api_v2_nft_collections_url, params: { sort: "timestamp.desc", type: "nrc721" }
assert_response :success
assert_equal tc2.id, json["data"].first["id"]
assert_equal tc3.id, json["data"].first["id"]
assert_equal tc1.id, json["data"].last["id"]
assert_equal timestamp, json["data"].last["timestamp"]
end
Expand Down

0 comments on commit 9e1c4e7

Please sign in to comment.