Merge branch 'foodcourt' of gitlab.com:code2lab/SXRestaurant into foodcourt

This commit is contained in:
Myat Zin Wai Maw
2020-01-29 16:27:58 +06:30

View File

@@ -12,7 +12,11 @@ class Employee < ApplicationRecord
validates :emp_id, uniqueness: true, numericality: true, length: {in: 1..4}, allow_blank: true
validates :password, numericality: true, length: {in: 3..9}, allow_blank: true
before_save :generate_app_id, :generate_app_token , if: Proc.new { self.role == "application" }
before_create :generate_app_id, :generate_app_token,
if: Proc.new { self.role == "application" }
before_update :generate_app_id, :generate_app_token,
if: Proc.new { self.role == "application" && self.role_was != "application" }
# Employee Image Uploader
mount_uploader :image_path, EmployeeImageUploader
@@ -90,14 +94,13 @@ class Employee < ApplicationRecord
end
def generate_app_id
return if self.app_id.present?
self.app_id = SecureRandom.hex(8)
rescue ActiveRecord::RecordNotUnique
retry
end
def generate_app_token
self.app_token = SecureRandom.hex(8)
self.app_token = SecureRandom.hex(10)
rescue ActiveRecord::RecordNotUnique
retry
end