add models for Project, Task, Note, Category
This commit is contained in:
7
app/models/contact.rb
Normal file
7
app/models/contact.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
class Contact < ApplicationRecord
|
||||
has_many :phone_numbers
|
||||
belongs_to :user
|
||||
|
||||
validates :name, presence: true
|
||||
validates :email, format: { with: URI::MailTo::EMAIL_REGEXP }, allow_blank: true
|
||||
end
|
||||
3
app/models/note.rb
Normal file
3
app/models/note.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Note < ApplicationRecord
|
||||
belongs_to :project
|
||||
end
|
||||
@@ -6,6 +6,8 @@ class Organization < ApplicationRecord
|
||||
|
||||
after_create :create_schema
|
||||
before_destroy :drop_schema
|
||||
has_many :users, dependent: :destroy
|
||||
has_many :projects, through: :users
|
||||
|
||||
def schema_name
|
||||
"org_#{id.to_s.gsub('-', '_')}"
|
||||
|
||||
11
app/models/phone_number.rb
Normal file
11
app/models/phone_number.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
class PhoneNumber < ApplicationRecord
|
||||
belongs_to :contact
|
||||
enum :type, {
|
||||
mobile: 0,
|
||||
home: 1,
|
||||
work: 2,
|
||||
fax: 3,
|
||||
other: 4
|
||||
}, _prefix: true
|
||||
validates :number, presence: true, format: { with: /\A\+?[0-9\s\-()]+\z/, message: "must be a valid phone number" }
|
||||
end
|
||||
8
app/models/project.rb
Normal file
8
app/models/project.rb
Normal file
@@ -0,0 +1,8 @@
|
||||
class Project < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :project_category
|
||||
has_many :contacts, through: :user
|
||||
has_many :tasks
|
||||
has_many :notes
|
||||
enum business_type: { type1: 0, type2: 1 }
|
||||
end
|
||||
3
app/models/project_category.rb
Normal file
3
app/models/project_category.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class ProjectCategory < ApplicationRecord
|
||||
has_many :projects
|
||||
end
|
||||
9
app/models/task.rb
Normal file
9
app/models/task.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
class Task < ApplicationRecord
|
||||
belongs_to :creator, class_name: 'User'
|
||||
belongs_to :reporter, class_name: 'User', optional: true
|
||||
belongs_to :reportee, class_name: 'User', optional: true
|
||||
belongs_to :project
|
||||
enum priority: { low: 0, medium: 1, high: 2 }
|
||||
enum status: { open: 0, in_progress: 1, closed: 2 }
|
||||
enum type: { bug: 0, feature: 1, chore: 2 }
|
||||
end
|
||||
@@ -1,6 +1,9 @@
|
||||
class User < ApplicationRecord
|
||||
has_secure_password
|
||||
has_many :sessions, dependent: :destroy
|
||||
belongs_to :organization, optional: false
|
||||
has_many :projects
|
||||
has_many :contacts
|
||||
|
||||
normalizes :email_address, with: ->(e) { e.strip.downcase }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user