Compare View
Commits (3)
Changes
Showing 3 changed files Side-by-side Diff
api-server/router-products.js
| ... | ... | @@ -20,8 +20,9 @@ function pageIndex(req, res, next) { |
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | function pageAdd(req, res, next) { |
| 23 | - //if (!req.params.product || req.params.product !== 'string' || !req.params.product.trim()) { | |
| 24 | - if (!req.params.product || !req.params.product.trim()) { | |
| 23 | + let products = req.params.product || req.query.product | |
| 24 | + | |
| 25 | + if (!products) { | |
| 25 | 26 | res.json({ |
| 26 | 27 | method: '/products/add', |
| 27 | 28 | error: true, |
| ... | ... | @@ -31,8 +32,20 @@ function pageAdd(req, res, next) { |
| 31 | 32 | return; |
| 32 | 33 | } |
| 33 | 34 | |
| 34 | - const product = req.params.product.trim().toUpperCase(); | |
| 35 | - config.products.push(product); | |
| 35 | + if (typeof products === 'string') { | |
| 36 | + products = products.trim().split(/[\s,]+/); | |
| 37 | + } | |
| 38 | + | |
| 39 | + const productsCount = products.length; | |
| 40 | + for (let i=0; i<productsCount; i++) { | |
| 41 | + const product = products[i]; | |
| 42 | + if (!product.trim()) { | |
| 43 | + continue; | |
| 44 | + } | |
| 45 | + | |
| 46 | + config.products.push(product.trim().toUpperCase()); | |
| 47 | + } | |
| 48 | + | |
| 36 | 49 | config.products.map(function(x) { return x.toUpperCase(); }); |
| 37 | 50 | unique(config.products); |
| 38 | 51 | config.products.sort(naturalSort()); |
| ... | ... | @@ -41,7 +54,7 @@ function pageAdd(req, res, next) { |
| 41 | 54 | res.json({ |
| 42 | 55 | method: '/products/add', |
| 43 | 56 | error: null, |
| 44 | - new_product: product, | |
| 57 | + new_product: products, | |
| 45 | 58 | products: config.products |
| 46 | 59 | }) |
| 47 | 60 | } |
| ... | ... | @@ -81,9 +94,9 @@ function pageDel(req, res, next) { |
| 81 | 94 | }) |
| 82 | 95 | } |
| 83 | 96 | |
| 84 | - | |
| 85 | 97 | router.get('/', pageIndex); |
| 86 | 98 | router.get('/add/:product', pageAdd); |
| 99 | +router.get('/add', pageAdd); | |
| 87 | 100 | |
| 88 | 101 | router.get('/del/:product', pageDel); |
| 89 | 102 | router.get('/delete/:product', pageDel); |
package-lock.json