From e5ef7af4ccf07bb433e89d9dbda9124aa8230955 Mon Sep 17 00:00:00 2001 From: Mark Moffat Date: Sun, 3 Nov 2019 09:48:34 +1030 Subject: [PATCH] Linting --- .eslintignore | 2 ++ app.js | 11 ++++------ config/settings.json | 3 ++- lib/common.js | 46 +++++++++++++++++++-------------------- routes/payments/paypal.js | 2 +- routes/product.js | 6 ++--- 6 files changed, 35 insertions(+), 35 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..80a17a7 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +**/*.min.js +pm2.config.js \ No newline at end of file diff --git a/app.js b/app.js index 4ddfdf0..29a4fd6 100644 --- a/app.js +++ b/app.js @@ -23,7 +23,7 @@ const Ajv = require('ajv'); const ajv = new Ajv({ useDefaults: true }); // get config -let config = common.getConfig(); +const config = common.getConfig(); const baseConfig = ajv.validate(require('./config/baseSchema'), config); if(baseConfig === false){ @@ -34,24 +34,21 @@ if(baseConfig === false){ // Validate the payment gateway config switch(config.paymentGateway){ case'paypal': - const paypalConfig = ajv.validate(require('./config/paypalSchema'), require('./config/paypal.json')); - if(paypalConfig === false){ + if(ajv.validate(require('./config/paypalSchema'), require('./config/paypal.json')) === false){ console.log(colors.red(`PayPal config is incorrect: ${ajv.errorsText()}`)); process.exit(2); } break; case'stripe': - const stripeConfig = ajv.validate(require('./config/stripeSchema'), require('./config/stripe.json')); - if(stripeConfig === false){ + if(ajv.validate(require('./config/stripeSchema'), require('./config/stripe.json')) === false){ console.log(colors.red(`Stripe config is incorrect: ${ajv.errorsText()}`)); process.exit(2); } break; case'authorizenet': - const authorizenetConfig = ajv.validate(require('./config/authorizenetSchema'), require('./config/authorizenet.json')); - if(authorizenetConfig === false){ + if(ajv.validate(require('./config/authorizenetSchema'), require('./config/authorizenet.json')) === false){ console.log(colors.red(`Authorizenet config is incorrect: ${ajv.errorsText()}`)); process.exit(2); } diff --git a/config/settings.json b/config/settings.json index 0ef732f..b0c47a4 100644 --- a/config/settings.json +++ b/config/settings.json @@ -23,5 +23,6 @@ "paymentGateway": "stripe", "databaseConnectionString": "mongodb://127.0.0.1:27017/expresscart", "theme": "Cloth", - "trackStock": false + "trackStock": false, + "orderHook": "" } diff --git a/lib/common.js b/lib/common.js index ad0615e..28d5a39 100755 --- a/lib/common.js +++ b/lib/common.js @@ -242,53 +242,53 @@ const updateConfig = (fields) => { _.forEach(fields, (value, key) => { settingsFile[key] = value; if(key === 'customCss_input'){ - settingsFile['customCss'] = escape.encode(uglifycss.processString(value)); + settingsFile.customCss = escape.encode(uglifycss.processString(value)); } if(key === 'footerHtml_input'){ const footerHtml = typeof value !== 'undefined' || value === '' ? escape.encode(value) : ''; - settingsFile['footerHtml'] = footerHtml; + settingsFile.footerHtml = footerHtml; } if(key === 'googleAnalytics_input'){ const googleAnalytics = typeof value !== 'undefined' ? escape.encode(value) : ''; - settingsFile['googleAnalytics'] = googleAnalytics; + settingsFile.googleAnalytics = googleAnalytics; } }); // delete settings - delete settingsFile['customCss_input']; - delete settingsFile['footerHtml_input']; - delete settingsFile['googleAnalytics_input']; + delete settingsFile.customCss_input; + delete settingsFile.footerHtml_input; + delete settingsFile.googleAnalytics_input; - if(fields['emailSecure'] === 'on'){ - settingsFile['emailSecure'] = true; + if(fields.emailSecure === 'on'){ + settingsFile.emailSecure = true; }else{ - settingsFile['emailSecure'] = false; + settingsFile.emailSecure = false; } - if(!fields['menuEnabled']){ - settingsFile['menuEnabled'] = false; + if(!fields.menuEnabled){ + settingsFile.menuEnabled = false; }else{ - settingsFile['menuEnabled'] = true; + settingsFile.menuEnabled = true; } - if(fields['emailPort']){ - settingsFile['emailPort'] = parseInt(fields['emailPort']); + if(fields.emailPort){ + settingsFile.emailPort = parseInt(fields.emailPort); } - if(fields['flatShipping']){ - settingsFile['flatShipping'] = parseInt(fields['flatShipping']); + if(fields.flatShipping){ + settingsFile.flatShipping = parseInt(fields.flatShipping); } - if(fields['freeShippingAmount']){ - settingsFile['freeShippingAmount'] = parseInt(fields['freeShippingAmount']); + if(fields.freeShippingAmount){ + settingsFile.freeShippingAmount = parseInt(fields.freeShippingAmount); } - if(fields['productsPerRow']){ - settingsFile['productsPerRow'] = parseInt(fields['productsPerRow']); + if(fields.productsPerRow){ + settingsFile.productsPerRow = parseInt(fields.productsPerRow); } - if(fields['productsPerPage']){ - settingsFile['productsPerPage'] = parseInt(fields['productsPerPage']); + if(fields.productsPerPage){ + settingsFile.productsPerPage = parseInt(fields.productsPerPage); } // If we have a local settings file (not git tracked) we loop its settings and save @@ -509,7 +509,7 @@ const getData = (req, page, query) => { query = {}; } - query['productPublished'] = { $ne: false }; + query.productPublished = { $ne: false }; // Run our queries return Promise.all([ diff --git a/routes/payments/paypal.js b/routes/payments/paypal.js index e57d36c..2fd854e 100644 --- a/routes/payments/paypal.js +++ b/routes/payments/paypal.js @@ -13,7 +13,7 @@ router.get('/checkout_return', (req, res, next) => { const db = req.app.db; const config = req.app.config; const paymentId = req.session.paymentId; - const payerId = req.query['PayerID']; + const payerId = req.query.PayerID; const details = { payer_id: payerId }; paypal.payment.execute(paymentId, details, (error, payment) => { diff --git a/routes/product.js b/routes/product.js index 1fb42c1..aa4e3f7 100644 --- a/routes/product.js +++ b/routes/product.js @@ -356,12 +356,12 @@ router.post('/admin/product/update', restrict, checkAccess, async (req, res) => // if no featured image if(!product.productImage){ if(images.length > 0){ - productDoc['productImage'] = images[0].path; + productDoc.productImage = images[0].path; }else{ - productDoc['productImage'] = '/uploads/placeholder.png'; + productDoc.productImage = '/uploads/placeholder.png'; } }else{ - productDoc['productImage'] = product.productImage; + productDoc.productImage = product.productImage; } try{