Created
April 20, 2015 13:48
-
-
Save oleglukashev/4336451cd803aff64396 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module SampleForOrder | |
def create_order_status_history | |
order = current_user.has_role?(:guide) ? @order : @application | |
OrderStatusHistory.create!({ | |
user_id: current_user.id, | |
order_id: order.id, | |
status: Order.statuses[order.status] | |
}) | |
end | |
def view_order_for_guide order | |
viewed_order order | |
viewed_all_messages order | |
viewed_all_change_status order | |
end | |
def view_application_for_traveler application | |
viewed_all_messages application | |
viewed_all_change_status application | |
end | |
def viewed_order order | |
unless order.is_viewed | |
order.viewed! | |
end | |
end | |
def viewed_all_messages order | |
unless order.order_messages.unviewed_for_user(current_user.id).size == 0 | |
order.order_messages.unviewed_for_user(current_user.id).each do |message| | |
message.viewed! | |
end | |
end | |
end | |
def viewed_all_change_status order | |
unless order.order_status_histories.unviewed_for_user(current_user.id).size == 0 | |
order.order_status_histories.unviewed_for_user(current_user.id).each do |status_history| | |
status_history.viewed! | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment