1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2024-11-28 09:24:24 +01:00

(bug) fix notification with slots

This commit is contained in:
Sylvain 2022-07-20 16:20:09 +02:00
parent 29b9399ca3
commit 7134b8ffac
8 changed files with 45 additions and 24 deletions

View File

@ -1,5 +1,5 @@
json.title notification.notification_type
json.description t('.USER_s_reservation_on_the_DATE_was_cancelled_remember_to_generate_a_refund_invoice_if_applicable_html',
USER: notification.attached_object.reservation.user&.profile&.full_name || t('api.notifications.deleted_user'),
DATE: I18n.l(notification.attached_object.start_at, format: :long))
DATE: I18n.l(notification.attached_object&.slot&.start_at, format: :long))

View File

@ -2,6 +2,5 @@
json.title notification.notification_type
json.description t('.your_reservation_RESERVABLE_of_DATE_was_successfully_cancelled',
RESERVABLE: notification.attached_object.reservation&.reservable&.name,
DATE: I18n.l(notification.attached_object.start_at, format: :long))
RESERVABLE: notification.attached_object&.reservation&.reservable&.name,
DATE: I18n.l(notification.attached_object&.start_at, format: :long))

View File

@ -2,8 +2,8 @@
<p><%= t('.body.member_cancelled', NAME: @attached_object.reservation.user&.profile&.full_name || t('api.notifications.deleted_user')) %></p>
<p><%= t('.body.item_details',
START: I18n.l(@attached_object.slot.start_at, format: :long),
END: I18n.l(@attached_object.slot.end_at, format: :hour_minute),
RESERVABLE: @attached_object.reservation.reservable.name) %>
START: I18n.l(@attached_object&.slot&.start_at, format: :long),
END: I18n.l(@attached_object&.slot&.end_at, format: :hour_minute),
RESERVABLE: @attached_object&.reservation&.reservable&.name) %>
</p>
<p><%= t('.body.generate_refund') %></p>

View File

@ -1,5 +1,5 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p><%= t('.body.slot_modified', NAME: @attached_object.reservation.user&.profile&.full_name || t('api.notifications.deleted_user')) %></p>
<p><%= t('.body.new_date') %> <%= "#{I18n.l(@attached_object.slot.start_at, format: :long)} - #{I18n.l(@attached_object.slot.end_at, format: :hour_minute)}" %></p>
<p><small><%= t('.body.old_date') %> <%= "#{I18n.l(@attached_object.ex_start_at, format: :long)} - #{I18n.l(@attached_object.ex_end_at, format: :hour_minute)}" %></small></p>
<p><%= t('.body.slot_modified', NAME: @attached_object&.reservation.user&.profile&.full_name || t('api.notifications.deleted_user')) %></p>
<p><%= t('.body.new_date') %> <%= "#{I18n.l(@attached_object&.slot&.start_at, format: :long)} - #{I18n.l(@attached_object&.slot.end_at, format: :hour_minute)}" %></p>
<p><small><%= t('.body.old_date') %> <%= "#{I18n.l(@attached_object&.ex_start_at, format: :long)} - #{I18n.l(@attached_object&.ex_end_at, format: :hour_minute)}" %></small></p>

View File

@ -1,4 +1,4 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p><%= t('.body.reservation_canceled', RESERVABLE: @attached_object.reservation.reservable.name ) %></p>
<p><%= "#{I18n.l(@attached_object.slot.start_at, format: :long)} - #{I18n.l(@attached_object.slot.end_at, format: :hour_minute)}" %></p>
<p><%= t('.body.reservation_canceled', RESERVABLE: @attached_object&.reservation&.reservable&.name ) %></p>
<p><%= "#{I18n.l(@attached_object&.slot&.start_at, format: :long)} - #{I18n.l(@attached_object&.slot&.end_at, format: :hour_minute)}" %></p>

View File

@ -1,5 +1,5 @@
<%= render 'notifications_mailer/shared/hello', recipient: @recipient %>
<p><%= t('.body.reservation_changed_to') %></p>
<p><%= "#{I18n.l(@attached_object.slot.start_at, format: :long)} - #{I18n.l(@attached_object.slot.end_at, format: :hour_minute)}" %></p>
<p><small><%= t('.body.previous_date') %> <%= "#{I18n.l(@attached_object.ex_start_at, format: :long)} - #{I18n.l(@attached_object.ex_end_at, format: :hour_minute)}" %></small></p>
<p><%= "#{I18n.l(@attached_object&.slot&.start_at, format: :long)} - #{I18n.l(@attached_object&.slot&.end_at, format: :hour_minute)}" %></p>
<p><small><%= t('.body.previous_date') %> <%= "#{I18n.l(@attached_object&.ex_start_at, format: :long)} - #{I18n.l(@attached_object&.ex_end_at, format: :hour_minute)}" %></small></p>

View File

@ -0,0 +1,22 @@
# frozen_string_literal: true
# We migrate existing notifications to be attached to a SlotsReservation instead of a Slot,
# because these notifications are now expecting a SlotsReservation
class MigrateSlotsNotifications < ActiveRecord::Migration[5.2]
def up
Notification.where(attached_object_type: 'Slot').each do |notification|
slot = notification.attached_object
slots_reservation = slot&.slots_reservations
&.includes(:reservation)
&.where('reservations.statistic_profile_id': notification.receiver.statistic_profile.id)
&.first
notification.update(attached_object: slots_reservation)
end
end
def down
Notification.where(attached_object_type: 'SlotsReservation').each do |notification|
notification.update(attached_object: notification.attached_object&.slot)
end
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_07_05_125232) do
ActiveRecord::Schema.define(version: 2022_07_20_135828) do
# These are extensions that must be enabled in order to support this database
enable_extension "fuzzystrmatch"
@ -19,8 +19,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
enable_extension "unaccent"
create_table "abuses", id: :serial, force: :cascade do |t|
t.string "signaled_type"
t.integer "signaled_id"
t.string "signaled_type"
t.string "first_name"
t.string "last_name"
t.string "email"
@ -49,8 +49,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
t.string "locality"
t.string "country"
t.string "postal_code"
t.string "placeable_type"
t.integer "placeable_id"
t.string "placeable_type"
t.datetime "created_at"
t.datetime "updated_at"
end
@ -64,8 +64,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
end
create_table "assets", id: :serial, force: :cascade do |t|
t.string "viewable_type"
t.integer "viewable_id"
t.string "viewable_type"
t.string "attachment"
t.string "type"
t.datetime "created_at"
@ -146,8 +146,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
end
create_table "credits", id: :serial, force: :cascade do |t|
t.string "creditable_type"
t.integer "creditable_id"
t.string "creditable_type"
t.integer "plan_id"
t.integer "hours"
t.datetime "created_at"
@ -369,15 +369,15 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
create_table "notifications", id: :serial, force: :cascade do |t|
t.integer "receiver_id"
t.string "attached_object_type"
t.integer "attached_object_id"
t.string "attached_object_type"
t.integer "notification_type_id"
t.boolean "is_read", default: false
t.datetime "created_at"
t.datetime "updated_at"
t.string "receiver_type"
t.boolean "is_send", default: false
t.jsonb "meta_data", default: "{}"
t.jsonb "meta_data", default: {}
t.index ["notification_type_id"], name: "index_notifications_on_notification_type_id"
t.index ["receiver_id"], name: "index_notifications_on_receiver_id"
end
@ -570,8 +570,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
create_table "prices", id: :serial, force: :cascade do |t|
t.integer "group_id"
t.integer "plan_id"
t.string "priceable_type"
t.integer "priceable_id"
t.string "priceable_type"
t.integer "amount"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
@ -729,8 +729,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
t.text "message"
t.datetime "created_at"
t.datetime "updated_at"
t.string "reservable_type"
t.integer "reservable_id"
t.string "reservable_type"
t.integer "nb_reserve_places"
t.integer "statistic_profile_id"
t.index ["reservable_type", "reservable_id"], name: "index_reservations_on_reservable_type_and_reservable_id"
@ -739,8 +739,8 @@ ActiveRecord::Schema.define(version: 2022_07_05_125232) do
create_table "roles", id: :serial, force: :cascade do |t|
t.string "name"
t.string "resource_type"
t.integer "resource_id"
t.string "resource_type"
t.datetime "created_at"
t.datetime "updated_at"
t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"