|
1 | 1 | class JobApplication < ApplicationRecord |
| 2 | + attribute :status, :string |
| 3 | + |
2 | 4 | validates :date_applied, :company_name, :method_of_contact, :position_type, :position_title, presence: true |
3 | 5 | validates :email_address, presence: true, if: -> { method_of_contact == "email" } |
4 | 6 | validates :point_of_contact, presence: true, if: -> { ["email", "phone", "recruiter", "other"].include?(method_of_contact) } |
5 | | - validates :website_link, presence: true, if: -> { method_of_contact == "internet job application" } |
| 7 | + validates :website_link, presence: true, if: -> { method_of_contact == "internet_job_application" } |
6 | 8 | validates :website_link, url: { |
7 | 9 | allow_blank: true, |
8 | 10 | schemes: ["http", "https"], |
9 | 11 | no_local: true, |
10 | 12 | public_suffix: true |
11 | 13 | } |
12 | | - enum method_of_contact: {email: "email", phone: "phone", internet_job_application: "internet job application", recruiter: "recruiter", other: "other"} |
13 | | - enum position_type: {full_time: "full-time", part_time: "part-time", internship: "internship"} |
| 14 | + validates :claimed_for_unemployment, inclusion: {in: [true, false]} |
| 15 | + validates :status, inclusion: {in: %w[hired interviewing job_offer no_response not_hired]} |
| 16 | + |
| 17 | + enum method_of_contact: { |
| 18 | + email: "email", |
| 19 | + internet_job_application: "internet job application", |
| 20 | + other: "other", |
| 21 | + phone: "phone", |
| 22 | + recruiter: "recruiter" |
| 23 | + } |
| 24 | + enum position_type: { |
| 25 | + full_time: "full_time", |
| 26 | + internship: "internship", |
| 27 | + part_time: "part_time" |
| 28 | + } |
| 29 | + enum status: { |
| 30 | + hired: "hired", |
| 31 | + interviewing: "interviewing", |
| 32 | + job_offer: "job offer", |
| 33 | + no_response: "no response", |
| 34 | + not_hired: "not hired" |
| 35 | + } |
14 | 36 |
|
15 | | - scope :search, ->(query) { where("company_name ILIKE ? OR position_title ILIKE ?", "%#{query}%", "%#{query}%") } |
16 | 37 | scope :by_method_of_contact, ->(method) { where(method_of_contact: method) } |
17 | 38 | scope :by_position_type, ->(type) { where(position_type: type) } |
| 39 | + scope :by_status, ->(status) { where(status: status) } |
| 40 | + scope :claimed_for_unemployment, -> { where(claimed_for_unemployment: true) } |
| 41 | + scope :not_claimed_for_unemployment, -> { where(claimed_for_unemployment: false) } |
| 42 | + scope :search, ->(query) { |
| 43 | + where("company_name ILIKE :query OR |
| 44 | + position_title ILIKE :query OR |
| 45 | + email_address ILIKE :query OR |
| 46 | + point_of_contact ILIKE :query OR |
| 47 | + website_link ILIKE :query OR |
| 48 | + status ILIKE :query", query: "%#{query}%") |
| 49 | + } |
18 | 50 | end |
0 commit comments