Standardise variable names between page and database

This is, again, so the validation function can be used for both
datasets rather than having to process each one differently.
This commit is contained in:
Hippo 2022-01-05 19:37:21 +05:30
parent 5a4d97b1bd
commit bf58eab258
2 changed files with 16 additions and 16 deletions

View file

@ -123,8 +123,8 @@ function validatePledge(body, PledgeModel = Pledge) {
// errors get saved here
let errors = []
let robo = body.robo
if(robo != 'no') {
let was_robot = body.was_robot
if(was_robot != 'no') {
errors.push('Only humans are allowed to donate money. Robots are too digital 🙁')
}
@ -155,29 +155,29 @@ function validatePledge(body, PledgeModel = Pledge) {
let phone = body.phone
let retryTimes
let retry_times
try {
retryTimes = body['reminder-count']
retry_times = body.retry_times
} catch (err) {
errors.push('Invalid retry count. Please choose a positive number!')
}
let newsletter = body.newsletter == 'yes' ? true : false
let get_newsletter = body.get_newsletter == 'yes' ? true : false
let overseas = body.overseas == 'yes' ? true : false
let messages = body.messages
let other_message = body.other_message
// enter the info
let pledge = new PledgeModel() // may be Pledge or UnverifiedPledge
pledge.set('was_robot', robo)
pledge.set('was_robot', was_robot)
pledge.set('amount', amount)
pledge.set('overseas', overseas)
pledge.set('name', name)
pledge.set('anonymous', anonymous)
pledge.set('email', email)
pledge.set('phone', phone)
pledge.set('retry_times', retryTimes)
pledge.set('get_newsletter', newsletter)
pledge.set('other_message', messages)
pledge.set('retry_times', retry_times)
pledge.set('get_newsletter', get_newsletter)
pledge.set('other_message', other_message)
// return it all!
return {

View file

@ -252,36 +252,36 @@
<div class="my-8">
<label for="input-reminder-count" class="block text-xl">How many times should we try to contact you before giving up?</label>
<input name="reminder-count" id="input-reminder-count" type="number" value="10" size="3" class="block font-sans text-2xl mb-2 bg-gray-100 p-2 rounded-md" required/>
<input name="retry_times" id="input-reminder-count" type="number" value="10" size="3" class="block font-sans text-2xl mb-2 bg-gray-100 p-2 rounded-md" required/>
<label for="input-reminder-count" class="block">If we don't manage to collect your payment, we may have to call off the crowdfunding, so please err on the higher side!</label>
</div>
<div class="my-8">
<p class="block text-xl">Would you like to receive our weekly newsletter?</p>
<div class="inline-block mr-2">
<input name="newsletter" value="yes" id="input-newsletter-yes" type="radio" class="text-xl font-sans"/>
<input name="get_newsletter" value="yes" id="input-newsletter-yes" type="radio" class="text-xl font-sans"/>
<label for="input-newsletter-yes" class="text-xl font-sans mr-3">Yes please</label>
</div>
<div class="inline-block">
<input name="newsletter" value="no" id="input-newsletter-no" type="radio" class="text-xl font-sans" checked/>
<input name="get_newsletter" value="no" id="input-newsletter-no" type="radio" class="text-xl font-sans" checked/>
<label for="input-newsletter-no" class="text-xl font-sans">No thanks</label>
</div>
</div>
<div class="my-8">
<label for="input-message" class="block text-xl">Any other message for us?</label>
<textarea name="messages" id="input-message" placeholder="Hi there..." class="block font-sans text-xl mb-2 w-full bg-gray-100 p-2 rounded-md"></textarea>
<textarea name="other_message" id="input-message" placeholder="Hi there..." class="block font-sans text-xl mb-2 w-full bg-gray-100 p-2 rounded-md"></textarea>
<label for="input-contact" class="block">You can also email us later at <a href="mailto:editors@snipettemag.com">editors@snipettemag.com</a></label>
</div>
<div class="my-5">
<p class="block text-xl">Are you a robot?</p>
<div class="inline-block mr-2">
<input name="robo" value="yes" id="input-robo-yes" type="radio" class="text-xl font-sans" checked/>
<input name="was_robot" value="yes" id="input-robo-yes" type="radio" class="text-xl font-sans" checked/>
<label for="input-robo-yes" class="text-xl font-sans">Yup, how did you know?</label>
</div>
<div class="inline-block">
<input name="robo" value="no" id="input-robo-no" type="radio" class="text-xl font-sans"/>
<input name="was_robot" value="no" id="input-robo-no" type="radio" class="text-xl font-sans"/>
<label for="input-robo-no" class="text-xl font-sans">No, of course not</label>
</div>
</div>