Skip to content

Commit 9ae2a21

Browse files
committed
update util fn names
1 parent c62991d commit 9ae2a21

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

server/routes/api/checkout.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ const { createClient } = require('../../db')
33
const router = express.Router()
44
const db = createClient()
55
const stripe = require('stripe')(process.env.STRIPE_SECRET_KEY)
6-
const format = require('../../../util/format')
7-
const validate = require('../../../util/validate')
6+
const { formatDonationAmount } = require('../../../util/format')
7+
const { validateDonationAmount } = require('../../../util/validate')
88

99
router.post('/create-transaction', async (req, res) => {
1010
const { sessionId /*, email /*, campaignId, donationId */ } = req.body || {}
@@ -45,8 +45,8 @@ router.post('/create-checkout-session', async (req, res) => {
4545
const { donationAmount } = req.body || {}
4646
const origin = req.get('origin')
4747

48-
const input = format(donationAmount)
49-
const inputIsValid = validate(input)
48+
const input = formatDonationAmount(donationAmount)
49+
const inputIsValid = validateDonationAmount(input)
5050
const donationAmountForStripe = input * 100 // Stripe accepts values in cents
5151

5252
if (inputIsValid) {

src/components/DonateMoney.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@
7979

8080
<script lang="js">
8181
import axios from 'axios'
82-
import format from '../../util/format.js'
83-
import validate from '../../util/validate.js'
82+
import { formatDonationAmount } from '../../util/format.js'
83+
import { validateDonationAmount } from '../../util/validate.js'
8484
export default {
8585
name: 'DonateMoney',
8686
props: [],
@@ -90,7 +90,7 @@ export default {
9090
customAmountSelected: false,
9191
customDonationAmount: undefined,
9292
inputRule: [
93-
(val) => validate(format(val)) || 'Invalid amount: acceptable value ranges between $1.50 and $10,000.00'
93+
(val) => validateDonationAmount(formatDonationAmount(val)) || 'Invalid amount: acceptable value ranges between $1.50 and $10,000.00'
9494
]
9595
}
9696
},
@@ -108,14 +108,14 @@ export default {
108108
submit() {
109109
const value = this.customAmountSelected ?
110110
this.customDonationAmount : this.donationAmount;
111-
const input = format(value);
111+
const input = formatDonationAmount(value);
112112
113113
if (this.customAmountSelected) {
114114
// inputRule provides user feedback on input, but actual validation occurs on submit
115115
if (this.$refs.input.validate()) this.createCheckoutSession(input);
116116
}
117117
118-
if (validate(input)) this.createCheckoutSession(input);
118+
if (validateDonationAmount(input)) this.createCheckoutSession(input);
119119
120120
return;
121121
},

util/format.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// format input value
2-
function format(value) {
2+
function formatDonationAmount(value) {
33
// separating parameter assignment and parseFloat operation for consistent outcome
44
value = parseFloat(value) // outputs: number
55
value = value.toFixed(2) // outputs: string
66
value = parseFloat(value) // outputs: number
77
return value // number
88
}
99

10-
module.exports = format
10+
module.exports = { formatDonationAmount }

util/validate.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// validate input value, expects a number as parameter
2-
function validate(value) {
2+
function validateDonationAmount(value) {
33
let message = ''
44

55
if (value > 1.49 && value < 10000.01) return true
@@ -16,4 +16,4 @@ function validate(value) {
1616
return false
1717
}
1818

19-
module.exports = validate
19+
module.exports = { validateDonationAmount }

0 commit comments

Comments
 (0)