2020-02-29 15:11:09 +00:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: notification_settings
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# email_flags :integer default(0), not null
|
2020-05-01 09:23:43 +00:00
|
|
|
# push_flags :integer default(0), not null
|
2020-02-29 15:11:09 +00:00
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# account_id :integer
|
|
|
|
# user_id :integer
|
|
|
|
#
|
|
|
|
# Indexes
|
|
|
|
#
|
|
|
|
# by_account_user (account_id,user_id) UNIQUE
|
|
|
|
#
|
|
|
|
|
|
|
|
class NotificationSetting < ApplicationRecord
|
|
|
|
# used for single column multi flags
|
|
|
|
include FlagShihTzu
|
|
|
|
|
|
|
|
belongs_to :account
|
|
|
|
belongs_to :user
|
|
|
|
|
|
|
|
DEFAULT_QUERY_SETTING = {
|
|
|
|
flag_query_mode: :bit_operator
|
|
|
|
}.freeze
|
|
|
|
|
2020-05-01 09:23:43 +00:00
|
|
|
EMAIL_NOTIFICATION_FLAGS = ::Notification::NOTIFICATION_TYPES.transform_keys { |key| "email_#{key}".to_sym }.invert.freeze
|
|
|
|
PUSH_NOTIFICATION_FLAGS = ::Notification::NOTIFICATION_TYPES.transform_keys { |key| "push_#{key}".to_sym }.invert.freeze
|
2020-02-29 15:11:09 +00:00
|
|
|
|
2020-04-19 18:10:28 +00:00
|
|
|
has_flags EMAIL_NOTIFICATION_FLAGS.merge(column: 'email_flags').merge(DEFAULT_QUERY_SETTING)
|
2020-05-01 09:23:43 +00:00
|
|
|
has_flags PUSH_NOTIFICATION_FLAGS.merge(column: 'push_flags').merge(DEFAULT_QUERY_SETTING)
|
2020-02-29 15:11:09 +00:00
|
|
|
end
|