mirror of
https://github.com/System-End/theseus.git
synced 2026-04-19 16:38:18 +00:00
search by tracking number on publicID
This commit is contained in:
parent
8e83da598d
commit
1ad81bcd9f
2 changed files with 23 additions and 2 deletions
|
|
@ -4,7 +4,8 @@ module Public
|
|||
|
||||
def show
|
||||
@lsv = LSV::SLUGS[params[:slug].to_sym]&.find(params[:id])
|
||||
raise ActiveRecord::RecordNotFound unless @lsv && @lsv.email == current_public_user&.email
|
||||
raise ActiveRecord::RecordNotFound unless @lsv
|
||||
raise ActiveRecord::RecordNotFound unless @lsv.email == current_public_user&.email || current_user
|
||||
rescue Norairrecord::RecordNotFoundError
|
||||
raise ActiveRecord::RecordNotFound
|
||||
end
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class PublicIdsController < ApplicationController
|
|||
clazzes = ActiveRecord::Base.descendants.select { |c| c.included_modules.include?(PublicIdentifiable) }
|
||||
clazz = clazzes.find { |c| c.public_id_prefix == prefix }
|
||||
unless clazz.present?
|
||||
return redirect_to public_ids_path, alert: "don't think we have that prefix: #{prefix}"
|
||||
return search_by_tracking_number(params[:id])
|
||||
end
|
||||
@record = clazz.find_by_public_id(params[:id])
|
||||
unless @record.present?
|
||||
|
|
@ -58,4 +58,24 @@ class PublicIdsController < ApplicationController
|
|||
flash[:alert] = "Record not found"
|
||||
redirect_to public_ids_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def search_by_tracking_number(tracking_number)
|
||||
# Search for warehouse orders by tracking number
|
||||
warehouse_order = Warehouse::Order.find_by(tracking_number: tracking_number)
|
||||
if warehouse_order
|
||||
return redirect_to warehouse_order_path(warehouse_order)
|
||||
end
|
||||
|
||||
lsv = LSV::MarketingShipmentRequest.first_where("{Warehouse–Tracking Number} = '#{tracking_number.gsub("'", "\\'")}'")
|
||||
|
||||
if lsv
|
||||
return redirect_to show_lsv_path(LSV.slug_for(lsv), lsv.id)
|
||||
end
|
||||
|
||||
# No package found with this tracking number
|
||||
flash[:alert] = "nothing found at all."
|
||||
redirect_to public_ids_path
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue