In the Salesforce::Database class, the wiring of our business logic is implemented:
search supporter,
if it doesn't exist, create it,
then create a donation associated to the supporter.
return the errors of these operations
However, there is also this:
def add_donation
return [:missing_email] unless email_present?
# ...
end
# ...
def email_present?
data &&
data.respond_to?(:request_data) &&
data.request_data.respond_to?(:email) &&
data.request_data.email
end
The reason for this is that the email is explicitly used in the supporter search in that class.
The input data for supporters and donations is the same, so I think this would be totally unnecessary if we merged the supporter and donation validators into one validator to use there:
def add_donation
return validation.errors unless validation.okay?
# ...
end
# ...
def validation
@validation ||= Validator.execute(data)
end
We would need to split the validation part from the field generation part and merge only the code that does the validations. Then, the two supporter and donation validators would rather be two fields-generators and be used to produce fields for each.
See our contributing guides.
In the
Salesforce::Database
class, the wiring of our business logic is implemented:However, there is also this:
The reason for this is that the email is explicitly used in the supporter search in that class.
The input data for supporters and donations is the same, so I think this would be totally unnecessary if we merged the supporter and donation validators into one validator to use there:
We would need to split the validation part from the field generation part and merge only the code that does the validations. Then, the two supporter and donation validators would rather be two fields-generators and be used to produce fields for each.