feat: Business hours

Data models and APIs for business hours

ref: #234
This commit is contained in:
Adam Zysko
2020-10-31 19:44:33 +01:00
committed by GitHub
parent 3d64ba49fc
commit 65ed4c78a4
23 changed files with 329 additions and 7 deletions

View File

@@ -0,0 +1,40 @@
class CreateWorkingHours < ActiveRecord::Migration[6.0]
def change
create_table :working_hours do |t|
t.belongs_to :inbox
t.belongs_to :account
t.integer :day_of_week, null: false
t.boolean :closed_all_day, default: false
t.integer :open_hour
t.integer :open_minutes
t.integer :close_hour
t.integer :close_minutes
t.timestamps
end
add_column :accounts, :timezone, :string, default: 'UTC'
change_table :inboxes, bulk: true do |t|
t.boolean :working_hours_enabled, default: false
t.string :out_of_office_message
end
Inbox.where.not(id: WorkingHour.select(:inbox_id)).each do |inbox|
create_working_hours_for_inbox(inbox)
end
end
private
def create_working_hours_for_inbox(inbox)
inbox.working_hours.create!(day_of_week: 1, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 2, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 3, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 4, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 5, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 6, closed_all_day: true)
inbox.working_hours.create!(day_of_week: 7, closed_all_day: true)
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: 2020_10_19_173944) do
ActiveRecord::Schema.define(version: 2020_10_27_135006) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@@ -49,6 +49,7 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
t.string "support_email", limit: 100
t.integer "settings_flags", default: 0, null: false
t.integer "feature_flags", default: 0, null: false
t.string "timezone", default: "UTC"
end
create_table "action_mailbox_inbound_emails", force: :cascade do |t|
@@ -280,6 +281,8 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
t.boolean "greeting_enabled", default: false
t.string "greeting_message"
t.string "email_address"
t.boolean "working_hours_enabled", default: false
t.string "out_of_office_message"
t.index ["account_id"], name: "index_inboxes_on_account_id"
end
@@ -513,6 +516,21 @@ ActiveRecord::Schema.define(version: 2020_10_19_173944) do
t.index ["account_id", "url"], name: "index_webhooks_on_account_id_and_url", unique: true
end
create_table "working_hours", force: :cascade do |t|
t.bigint "inbox_id"
t.bigint "account_id"
t.integer "day_of_week", null: false
t.boolean "closed_all_day", default: false
t.integer "open_hour"
t.integer "open_minutes"
t.integer "close_hour"
t.integer "close_minutes"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["account_id"], name: "index_working_hours_on_account_id"
t.index ["inbox_id"], name: "index_working_hours_on_inbox_id"
end
add_foreign_key "account_users", "accounts"
add_foreign_key "account_users", "users"
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"