From b7fa10d432ec1a0a0e658a4c376305f5b2552091 Mon Sep 17 00:00:00 2001 From: panhachom Date: Fri, 27 Oct 2023 18:00:17 +0700 Subject: [PATCH] close #760 show request booking order when payment_state is not paid --- .../storefront/order_request_notifications_controller.rb | 2 +- app/models/spree_cm_commissioner/notification.rb | 7 +++---- app/models/spree_cm_commissioner/order_decorator.rb | 9 +++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/controllers/spree/api/v2/storefront/order_request_notifications_controller.rb b/app/controllers/spree/api/v2/storefront/order_request_notifications_controller.rb index f76a23634..8cc8c8083 100644 --- a/app/controllers/spree/api/v2/storefront/order_request_notifications_controller.rb +++ b/app/controllers/spree/api/v2/storefront/order_request_notifications_controller.rb @@ -11,7 +11,7 @@ def collection def serialize_collection(collection) options_data = collection_options(collection).merge(params: serializer_params) - options_data[:meta][:unread_count] = collection.select(&:unread?).count + options_data[:meta][:unread_count] = spree_current_user.notifications.request_notifications.where(read_at: nil).size collection_serializer.new( collection, diff --git a/app/models/spree_cm_commissioner/notification.rb b/app/models/spree_cm_commissioner/notification.rb index ea38c70ac..5130238bc 100644 --- a/app/models/spree_cm_commissioner/notification.rb +++ b/app/models/spree_cm_commissioner/notification.rb @@ -3,10 +3,9 @@ class Notification < SpreeCmCommissioner::Base include Noticed::Model scope :request_notifications, lambda { - where( - type: %w[order_requested_notification order_rejected_notification order_accepted_notification], - read_at: nil - ).newest_first + select('DISTINCT ON (notificable_id) *') + .where(type: %w[order_requested_notification order_rejected_notification order_accepted_notification], read_at: nil) + .order('notificable_id, created_at DESC') } scope :user_notifications, lambda { diff --git a/app/models/spree_cm_commissioner/order_decorator.rb b/app/models/spree_cm_commissioner/order_decorator.rb index a37ec14ae..b818a7100 100644 --- a/app/models/spree_cm_commissioner/order_decorator.rb +++ b/app/models/spree_cm_commissioner/order_decorator.rb @@ -8,10 +8,11 @@ def self.prepended(base) base.scope :paid, -> { where(payment_state: :paid) } base.scope :filter_by_request_state, lambda { - where(state: :complete, payment_state: :paid) - .where.not(request_state: nil) - .order(created_at: :desc) - } + where(state: :complete) + .where.not(request_state: nil) + .where.not(payment_state: :paid) + .order(created_at: :desc) + } base.before_create :link_by_phone_number base.before_create :associate_customer