Browse Source

refactor

pull/816/head
Kat 3 years ago
parent
commit
f305c06364
  1. 3
      app/models/application_record.rb
  2. 4
      app/models/location.rb
  3. 5
      app/models/organisation.rb
  4. 4
      app/models/scheme.rb
  5. 4
      app/models/user.rb

3
app/models/application_record.rb

@ -2,7 +2,6 @@ class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
def strip_whitespaces
self.service_name = service_name.strip unless !respond_to?("service_name") || service_name.nil?
self.name = name.strip unless !respond_to?("name") || name.nil?
fields_to_strip.each { |field| self[field] = self[field].strip if field.present? }
end
end

4
app/models/location.rb

@ -8,6 +8,10 @@ class Location < ApplicationRecord
before_save :lookup_postcode!, if: :postcode_changed?
before_validation :strip_whitespaces
def fields_to_strip
%w[name]
end
attr_accessor :add_another_location
scope :search_by_postcode, ->(postcode) { where("REPLACE(postcode, ' ', '') ILIKE ?", "%#{postcode.delete(' ')}%") }

5
app/models/organisation.rb

@ -13,6 +13,11 @@ class Organisation < ApplicationRecord
has_paper_trail
before_validation :strip_whitespaces
def fields_to_strip
%w[name]
end
PROVIDER_TYPE = {
LA: 1,
PRP: 2,

4
app/models/scheme.rb

@ -21,6 +21,10 @@ class Scheme < ApplicationRecord
before_validation :strip_whitespaces
def fields_to_strip
%w[service_name]
end
SENSITIVE = {
No: 0,
Yes: 1,

4
app/models/user.rb

@ -29,6 +29,10 @@ class User < ApplicationRecord
before_validation :strip_whitespaces
def fields_to_strip
%w[name]
end
ROLES = {
data_provider: 1,
data_coordinator: 2,

Loading…
Cancel
Save