code refactored - used switch case instead of if

master
Aayush Saxena 2019-07-25 00:47:19 +05:30 committed by Mark Moffat
parent 399343a09d
commit c42bd43de3
1 changed files with 25 additions and 20 deletions

15
app.js
View File

@ -31,26 +31,31 @@ if(baseConfig === false){
} }
// Validate the payment gateway config // Validate the payment gateway config
if(config.paymentGateway === 'paypal'){ switch(config.paymentGateway)
{
case 'paypal':
const paypalConfig = ajv.validate(require('./config/paypalSchema'), require('./config/paypal.json')); const paypalConfig = ajv.validate(require('./config/paypalSchema'), require('./config/paypal.json'));
if(paypalConfig === false){ if(paypalConfig === false){
console.log(colors.red(`PayPal config is incorrect: ${ajv.errorsText()}`)); console.log(colors.red(`PayPal config is incorrect: ${ajv.errorsText()}`));
process.exit(2); process.exit(2);
} }
} break;
if(config.paymentGateway === 'stripe'){
case 'stripe':
const stripeConfig = ajv.validate(require('./config/stripeSchema'), require('./config/stripe.json')); const stripeConfig = ajv.validate(require('./config/stripeSchema'), require('./config/stripe.json'));
if(stripeConfig === false){ if(stripeConfig === false){
console.log(colors.red(`Stripe config is incorrect: ${ajv.errorsText()}`)); console.log(colors.red(`Stripe config is incorrect: ${ajv.errorsText()}`));
process.exit(2); process.exit(2);
} }
} break;
if(config.paymentGateway === 'authorizenet'){
case 'authorizenet':
const authorizenetConfig = ajv.validate(require('./config/authorizenetSchema'), require('./config/authorizenet.json')); const authorizenetConfig = ajv.validate(require('./config/authorizenetSchema'), require('./config/authorizenet.json'));
if(authorizenetConfig === false){ if(authorizenetConfig === false){
console.log(colors.red(`Authorizenet config is incorrect: ${ajv.errorsText()}`)); console.log(colors.red(`Authorizenet config is incorrect: ${ajv.errorsText()}`));
process.exit(2); process.exit(2);
} }
break;
} }
// require the routes // require the routes