2020-08-06 16:35:45 +02:00
|
|
|
# == Schema Information
|
|
|
|
#
|
|
|
|
# Table name: services
|
|
|
|
#
|
|
|
|
# id :bigint not null, primary key
|
|
|
|
# adresse :text
|
|
|
|
# email :string
|
|
|
|
# horaires :text
|
|
|
|
# nom :string not null
|
|
|
|
# organisme :string
|
|
|
|
# telephone :string
|
|
|
|
# type_organisme :string not null
|
|
|
|
# created_at :datetime not null
|
|
|
|
# updated_at :datetime not null
|
|
|
|
# administrateur_id :bigint
|
|
|
|
#
|
2018-04-17 16:11:49 +02:00
|
|
|
class Service < ApplicationRecord
|
|
|
|
has_many :procedures
|
|
|
|
belongs_to :administrateur
|
|
|
|
|
2018-04-23 10:42:30 +02:00
|
|
|
scope :ordered, -> { order(nom: :asc) }
|
|
|
|
|
2018-04-17 16:11:49 +02:00
|
|
|
enum type_organisme: {
|
|
|
|
administration_centrale: 'administration_centrale',
|
|
|
|
association: 'association',
|
2019-02-18 16:18:09 +01:00
|
|
|
collectivite_territoriale: 'collectivite_territoriale',
|
2018-04-17 16:11:49 +02:00
|
|
|
etablissement_enseignement: 'etablissement_enseignement',
|
2019-02-18 16:18:09 +01:00
|
|
|
operateur_d_etat: "operateur_d_etat",
|
|
|
|
service_deconcentre_de_l_etat: 'service_deconcentre_de_l_etat',
|
2018-04-17 16:11:49 +02:00
|
|
|
autre: 'autre'
|
|
|
|
}
|
|
|
|
|
|
|
|
validates :nom, presence: { message: 'doit être renseigné' }, allow_nil: false
|
|
|
|
validates :nom, uniqueness: { scope: :administrateur, message: 'existe déjà' }
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2018-04-17 16:11:49 +02:00
|
|
|
validates :type_organisme, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :email, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2019-11-14 18:31:14 +01:00
|
|
|
validates :telephone, phone: { possible: true, allow_blank: true }
|
2018-05-10 11:38:11 +02:00
|
|
|
validates :horaires, presence: { message: 'doivent être renseignés' }, allow_nil: false
|
|
|
|
validates :adresse, presence: { message: 'doit être renseignée' }, allow_nil: false
|
2018-04-17 16:11:49 +02:00
|
|
|
validates :administrateur, presence: { message: 'doit être renseigné' }, allow_nil: false
|
2018-12-19 15:35:07 +01:00
|
|
|
|
|
|
|
def clone_and_assign_to_administrateur(administrateur)
|
|
|
|
service_cloned = self.dup
|
|
|
|
service_cloned.administrateur = administrateur
|
|
|
|
service_cloned
|
|
|
|
end
|
2019-11-20 17:22:01 +01:00
|
|
|
|
|
|
|
def telephone_url
|
|
|
|
if telephone.present?
|
|
|
|
"tel:#{telephone.gsub(/[[:blank:]]/, '')}"
|
|
|
|
end
|
|
|
|
end
|
2018-04-17 16:11:49 +02:00
|
|
|
end
|