Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
fixes #243 - validates that donation is NaN on server (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
logangingerich authored and jspaine committed Nov 19, 2017
1 parent cc94f4c commit 6bfe734
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server/controllers/donation.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@ import {ADMIN_ROLE} from '../../common/constants'
import Donation from '../models/donation'
import Donor from '../models/donor'
import {UnauthorizedError} from '../lib/errors'
import {BadRequestError} from '../lib/errors'
import mailer from '../lib/mail/mail-helpers'

export default {
async create(req, res) {

let newDonation = {
...req.body,
total: req.body.items.reduce((acc, item) => acc + Number(item.value), 0)
total: req.body.items.reduce((acc, item) => {
if (isNaN(Number(item.value))) {
throw new BadRequestError
} else {
return acc + Number(item.value)
}
},0 )
}

if (!req.user.roles.find(r => r === ADMIN_ROLE) &&
Expand Down

0 comments on commit 6bfe734

Please sign in to comment.