2021-05-05 00:10:41 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Users
|
|
|
|
class CreditCardValidation < ApplicationRecord
|
2021-05-12 00:10:27 +00:00
|
|
|
RELEASE_DAY = Date.new(2021, 5, 17)
|
|
|
|
|
2021-05-05 00:10:41 +00:00
|
|
|
self.table_name = 'user_credit_card_validations'
|
|
|
|
|
|
|
|
belongs_to :user
|
2021-10-05 12:12:58 +00:00
|
|
|
|
2022-03-17 18:08:54 +00:00
|
|
|
validates :holder_name, length: { maximum: 50 }
|
2021-10-25 18:12:16 +00:00
|
|
|
validates :network, length: { maximum: 32 }
|
2021-10-05 12:12:58 +00:00
|
|
|
validates :last_digits, allow_nil: true, numericality: {
|
|
|
|
greater_than_or_equal_to: 0, less_than_or_equal_to: 9999
|
|
|
|
}
|
2021-10-08 06:11:46 +00:00
|
|
|
|
|
|
|
def similar_records
|
|
|
|
self.class.where(
|
|
|
|
expiration_date: expiration_date,
|
|
|
|
last_digits: last_digits,
|
2021-10-26 06:12:23 +00:00
|
|
|
network: network
|
2021-10-08 06:11:46 +00:00
|
|
|
).order(credit_card_validated_at: :desc).includes(:user)
|
|
|
|
end
|
2022-09-01 12:11:56 +00:00
|
|
|
|
|
|
|
def similar_holder_names_count
|
2022-09-08 06:13:33 +00:00
|
|
|
return 0 unless holder_name
|
|
|
|
|
|
|
|
self.class.where('lower(holder_name) = lower(:value)', value: holder_name).count
|
2022-09-01 12:11:56 +00:00
|
|
|
end
|
2021-05-05 00:10:41 +00:00
|
|
|
end
|
|
|
|
end
|