Commit efadded25c7d985e173095d212e207a19a8c7b5a
1 parent
8b23754b2f
Exists in
master
APISERVER: /products/del support multiple products (comma separated)
Showing 1 changed file with 10 additions and 14 deletions Side-by-side Diff
api-server/router-products.js
... | ... | @@ -57,26 +57,22 @@ function pageDel(req, res, next) { |
57 | 57 | return; |
58 | 58 | } |
59 | 59 | |
60 | - const product = req.params.product.trim().toUpperCase(); | |
61 | 60 | config.products.map(function(x) { return x.toUpperCase(); }); |
62 | - const idx = config.products.indexOf(product); | |
63 | - if (idx < 0) { | |
64 | - res.json({ | |
65 | - method: '/products/del', | |
66 | - error: true, | |
67 | - error_msg: 'Product to delete does not exist on old product list' | |
68 | - }); | |
69 | - | |
70 | - return; | |
61 | + const products = req.params.product.split(','); | |
62 | + const productsCount = products.length; | |
63 | + for (let i=0; i<productsCount; i++) { | |
64 | + const product = products[i].trim().toUpperCase(); | |
65 | + const idx = config.products.indexOf(product); | |
66 | + if (idx >= 0) { | |
67 | + matrix.config_is_dirty = true; | |
68 | + config.products.splice(idx, 1) | |
69 | + } | |
71 | 70 | } |
72 | - config.products.splice(idx, 1) | |
73 | - | |
74 | - matrix.config_is_dirty = true; | |
75 | 71 | |
76 | 72 | res.json({ |
77 | 73 | method: '/products/del', |
78 | 74 | error: null, |
79 | - product_to_delete: product, | |
75 | + product_to_delete: products, | |
80 | 76 | products: config.products |
81 | 77 | }) |
82 | 78 | } |