- Arquitetura corrigida: templates agora pertencem à inbox (WhatsApp),
não à unidade PIX (que é uma config financeira, não de mensagens)
- Migration: troca FK captain_unit_id -> inbox_id (up/down explícito)
- Model: belongs_to :inbox; scope for_inbox
- Controller: escopo via account.inboxes.find(inbox_id)
- Rotas: move de captain/units/:id → inboxes/:id/notification_templates
- Scanner job: joins(:conversation).where(conversations: {inbox_id:})
- UI: página /captain/notifications com seletor de inbox no topo
(chips clicáveis, templates carregam por watch no selectedInboxId)
- i18n PT/EN: novas keys INBOX_LABEL, SELECT_INBOX_HINT, EMPTY
41 lines
1.3 KiB
Ruby
41 lines
1.3 KiB
Ruby
# == Schema Information
|
|
#
|
|
# Table name: captain_notification_templates
|
|
#
|
|
# id :bigint not null, primary key
|
|
# active :boolean default(TRUE), not null
|
|
# content :text not null
|
|
# label :string not null
|
|
# position :integer default(0), not null
|
|
# timing_direction :integer default("before"), not null
|
|
# timing_minutes :integer default(10), not null
|
|
# created_at :datetime not null
|
|
# updated_at :datetime not null
|
|
# inbox_id :bigint not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# idx_notif_templates_inbox_active (inbox_id,active)
|
|
#
|
|
# Foreign Keys
|
|
#
|
|
# fk_rails_... (inbox_id => inboxes.id)
|
|
#
|
|
class Captain::NotificationTemplate < ApplicationRecord
|
|
self.table_name = 'captain_notification_templates'
|
|
|
|
belongs_to :inbox, inverse_of: :captain_notification_templates
|
|
|
|
enum timing_direction: { before: 0, after: 1 }
|
|
|
|
validates :label, presence: true
|
|
validates :content, presence: true
|
|
validates :timing_minutes, presence: true, numericality: { greater_than: 0 }
|
|
validates :timing_direction, presence: true
|
|
validates :inbox_id, presence: true
|
|
|
|
scope :active, -> { where(active: true) }
|
|
scope :ordered, -> { order(:position, :id) }
|
|
scope :for_inbox, ->(inbox_id) { where(inbox_id: inbox_id) }
|
|
end
|