Class: Api::Partner::ReservationSummarySerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- Api::Partner::ReservationSummarySerializer
- Defined in:
- app/serializers/api/partner/reservation_summary_serializer.rb
Instance Method Summary collapse
-
#allow_mark_status ⇒ Hash
Allow mark status permissions using ReservationSummaryPolicy.
-
#booking_details ⇒ Hash
Booking creation and modification details.
-
#charge_price ⇒ String
Formatted charge price.
-
#charge_price_v2 ⇒ Integer, Float
Formatted charge price v2.
-
#max_editable_time ⇒ Time
Reservation time plus 24 hours.
-
#other ⇒ Hash
Other permissions using ReservationSummaryPolicy.
-
#reservation_status ⇒ Hash
Reservation status information with dynamic localization.
-
#selected_special_menus ⇒ Array
Selected special menus information with dynamic localization.
-
#total_price ⇒ String
Financial attributes using consistent price formatting.
-
#total_price_v2 ⇒ Integer, Float
Formatted total price v2.
-
#we_travel_together ⇒ Hash
We Travel Together information matching legacy behavior.
Methods inherited from BaseSerializer
enable_caching, mtime, record_cache_options
Instance Method Details
#allow_mark_status ⇒ Hash
Allow mark status permissions using ReservationSummaryPolicy
Uses ReservationSummaryPolicy to calculate permissions in real-time with current staff while avoiding N+1 queries by using summary data.
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 237 attribute :allow_mark_status do |object, | current_staff = [:current_staff] || [:params]&.dig(:current_staff) model_policy = ReservationSummaryPolicy.new(current_staff, object) status_as_symbol = object.status_as_symbol&.to_sym service_type = object.service_type active = object.active arrived = object.arrived dine_in = object.dine_in? # Calculate permission flags based on reservation status and policy is_pending_or_reject = [:rejected, :pending_confirmation].include?(status_as_symbol) # Use ReservationSummaryPolicy for permission calculations allow_mark_arrived = model_policy.editable? && dine_in && model_policy.mark_arrived?(by_owner: true) allow_mark_no_show = model_policy.editable? && dine_in && model_policy.mark_no_show?(by_owner: true) # Check if cancellation is allowed based on time and status now = Time.now_in_tz(object.restaurant.time_zone) allow_mark_cancel = arrived && active && now < object.reservation_time && dine_in allowed_to_confirm = (status_as_symbol == :rejected && service_type == 'dine_in') || (status_as_symbol == :pending_confirmation && service_type == 'dine_in') allowed_to_reject = status_as_symbol == :pending_confirmation && service_type == 'dine_in' { allow_mark_arrived: is_pending_or_reject ? false : allow_mark_arrived, allow_mark_no_show: is_pending_or_reject ? false : allow_mark_no_show, allow_mark_cancel: is_pending_or_reject ? false : allow_mark_cancel, allowed_to_reject: allowed_to_reject, allowed_to_confirm: allowed_to_confirm, } end |
#booking_details ⇒ Hash
Booking creation and modification details
76 77 78 79 80 81 82 83 84 85 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 76 attribute :booking_details do |object| # Use restaurant timezone for consistent time formatting time_zone = object.restaurant.time_zone { created_at: object.created_at_reservation&.in_time_zone(time_zone)&.strftime('%d %b %y %H:%M'), create_by: object.created_by ? object.created_by.capitalize : nil, cancelled_by: object.cancelled_by.present? ? object.cancelled_by.titleize : nil, modified_by: object.modified_by.present? ? object.modified_by.titleize : nil, } end |
#charge_price ⇒ String
Returns formatted charge price.
44 45 46 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 44 attribute :charge_price do |object| format_price(object.charge_price_v1) end |
#charge_price_v2 ⇒ Integer, Float
Returns formatted charge price v2.
50 51 52 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 50 attribute :charge_price_v2 do |object| format_price(object.charge_price_v2) end |
#max_editable_time ⇒ Time
Returns reservation time plus 24 hours.
277 278 279 280 281 282 283 284 285 286 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 277 attribute :max_editable_time do |object| # Use summary's reservation_time method (same logic as original Reservation model) object.reservation_time.twenty_four_hours_later rescue StandardError => e BUSINESS_LOGGER.warn('Error calculating max_editable_time for reservation summary', { reservation_id: object.reservation_id, error_message: e., }) 24.hours.from_now end |
#other ⇒ Hash
Other permissions using ReservationSummaryPolicy
Uses ReservationSummaryPolicy to calculate permissions in real-time with current staff while avoiding N+1 queries by using summary data.
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 303 attribute :other do |object, | current_staff = [:current_staff] || [:params]&.dig(:current_staff) model_policy = ReservationSummaryPolicy.new(current_staff, object) active = object.active no_show = object.no_show # Calculate permission flags for various actions # Check if confirmation can be sent (not for delivery reservations) send_confirmation_user = model_policy.be_reminded? && model_policy.editable? && !object.delivery? # Use ReservationSummaryPolicy for permission calculations mark_no_show_allowed = model_policy.mark_no_show?(by_owner: true) mark_arrived_allowed = model_policy.mark_arrived?(by_owner: true) # Use policy method for consistency with original serializer # The policy method handles past reservations correctly allowed_to_send_sms = if mark_no_show_allowed && mark_arrived_allowed true elsif model_policy.owner_has_sent_custom_sms? && active && !no_show true else false end { allowed_to_send_sms: allowed_to_send_sms, send_review_link: object.past?, send_confirmation_user: send_confirmation_user, edit_table_number: model_policy.editable?, } end |
#reservation_status ⇒ Hash
Reservation status information with dynamic localization
58 59 60 61 62 63 64 65 66 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 58 attribute :reservation_status do |object| # Use pre-computed reservation_status_data from summary table with dynamic localization status_data = object.reservation_status_data if status_data.present? && status_data.is_a?(Hash) Api::Partner::ReservationSummarySerializer.localize_reservation_status_data(status_data) else {} end end |
#selected_special_menus ⇒ Array
Selected special menus information with dynamic localization
437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 437 attribute :selected_special_menus do |object, params| # Use pre-calculated menu data from sync and convert to symbol keys = object. || [] if .is_a?(Array) = .map do || if .is_a?(Hash) # Convert string keys to symbol keys for consistent API format .deep_symbolize_keys else end end # Apply multilingual localization if cache data is available multilingual_data = params[:multilingual_data] current_locale = params[:current_locale] if multilingual_data.present? Api::Partner::ReservationSummarySerializer.( , multilingual_data, current_locale ) else end else [] end end |
#total_price ⇒ String
Financial attributes using consistent price formatting
32 33 34 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 32 attribute :total_price do |object| format_price(object.total_price_v1) end |
#total_price_v2 ⇒ Integer, Float
Returns formatted total price v2.
38 39 40 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 38 attribute :total_price_v2 do |object| format_price(object.total_price_v2) end |
#we_travel_together ⇒ Hash
We Travel Together information matching legacy behavior
477 478 479 480 481 482 483 484 485 486 487 488 489 |
# File 'app/serializers/api/partner/reservation_summary_serializer.rb', line 477 attribute :we_travel_together do |object| # Use pre-computed WTT data from summary table wtt_data = object.wtt_data || {} has_wtt_data = object.accept_we_travel_together && wtt_data.present? { accept_we_travel_together: object.accept_we_travel_together || false, wtt_icon: has_wtt_data ? AdminSetting.wtt_image_url.strip : nil, wtt_label_text: has_wtt_data ? 'Half‑Half Thai Travel' : nil, wtt_id_card: has_wtt_data ? wtt_data['wtt_id_card'] : nil, wtt_phone: has_wtt_data ? wtt_data['wtt_phone'] : nil, } end |