Commit 2678580012966bf821ab52b4c3bb3c63f03cfbed
1 parent
e80763573c
Exists in
master
Change remote product separator to ";" and ","
Showing 1 changed file with 16 additions and 14 deletions Side-by-side Diff
api-server/router-remote-products.js
1 | -"use strict"; | |
2 | - | |
3 | 1 | const express = require('express'); |
4 | 2 | // const sortObj = require('sort-object'); |
5 | 3 | const naturalCompare = require('string-natural-compare'); |
... | ... | @@ -10,11 +8,13 @@ const matrix = require('../matrix'); |
10 | 8 | const router = express.Router(); |
11 | 9 | module.exports = router; |
12 | 10 | |
11 | +const splitProductSeparator = / *[;,]+ */; | |
12 | + | |
13 | 13 | function pageIndex(req, res) { |
14 | 14 | res.json({ |
15 | 15 | method: '/products', |
16 | 16 | error: null, |
17 | - result: config.remote_products | |
17 | + result: config.remote_products, | |
18 | 18 | }); |
19 | 19 | } |
20 | 20 | |
... | ... | @@ -23,12 +23,12 @@ function pageSet(req, res) { |
23 | 23 | res.json({ |
24 | 24 | method: '/remote-products/set', |
25 | 25 | error: true, |
26 | - error_msg: 'Usage: /remote-products/set/<LOCAL_PRODUCT>/<REMOTE_PRODUCT>' | |
26 | + error_msg: 'Usage: /remote-products/set/<LOCAL_PRODUCT>/<REMOTE_PRODUCT>', | |
27 | 27 | }); |
28 | 28 | } |
29 | 29 | |
30 | 30 | if (!req.params.localProduct && !req.query.local) { |
31 | - responseWithUsageHelp() | |
31 | + responseWithUsageHelp(); | |
32 | 32 | return; |
33 | 33 | } |
34 | 34 | |
... | ... | @@ -37,7 +37,6 @@ function pageSet(req, res) { |
37 | 37 | return; |
38 | 38 | } |
39 | 39 | |
40 | - | |
41 | 40 | const localProduct = (req.params.localProduct || req.query.local).trim().toUpperCase(); |
42 | 41 | const remoteProduct = (req.params.remoteProduct || req.query.remote).trim(); |
43 | 42 | |
... | ... | @@ -50,7 +49,10 @@ function pageSet(req, res) { |
50 | 49 | */ |
51 | 50 | |
52 | 51 | const sortedRemoteProducts = {}; |
53 | - const remoteProductsKeys = Object.keys(config.remote_products).sort(naturalCompare.caseInsensitive); | |
52 | + const remoteProductsKeys = Object.keys( | |
53 | + config.remote_products, | |
54 | + ).sort(naturalCompare.caseInsensitive); | |
55 | + | |
54 | 56 | remoteProductsKeys.forEach((item) => { |
55 | 57 | sortedRemoteProducts[item] = config.remote_products[item]; |
56 | 58 | }); |
... | ... | @@ -63,8 +65,8 @@ function pageSet(req, res) { |
63 | 65 | error: null, |
64 | 66 | local_product: localProduct, |
65 | 67 | remote_product: remoteProduct, |
66 | - remote_products: config.remote_products | |
67 | - }) | |
68 | + remote_products: config.remote_products, | |
69 | + }); | |
68 | 70 | } |
69 | 71 | |
70 | 72 | function pageDel(req, res) { |
... | ... | @@ -72,7 +74,7 @@ function pageDel(req, res) { |
72 | 74 | res.json({ |
73 | 75 | method: '/remote-products/del', |
74 | 76 | error: true, |
75 | - error_msg: 'Usage: /remote-products/del/<LOCAL_PRODUCT>' | |
77 | + error_msg: 'Usage: /remote-products/del/<LOCAL_PRODUCT>', | |
76 | 78 | }); |
77 | 79 | } |
78 | 80 | |
... | ... | @@ -83,11 +85,11 @@ function pageDel(req, res) { |
83 | 85 | } |
84 | 86 | |
85 | 87 | if (typeof localProducts === 'string') { |
86 | - localProducts = localProducts.split(/[\s,]+/); | |
88 | + localProducts = localProducts.split(splitProductSeparator); | |
87 | 89 | } |
88 | 90 | |
89 | 91 | const localProductsCount = localProducts.length; |
90 | - for (let i=0; i<localProductsCount; i++) { | |
92 | + for (let i = 0; i < localProductsCount; i += 1) { | |
91 | 93 | const localProduct = localProducts[i]; |
92 | 94 | |
93 | 95 | if (localProduct) { |
... | ... | @@ -100,8 +102,8 @@ function pageDel(req, res) { |
100 | 102 | method: '/remote-products/del', |
101 | 103 | error: null, |
102 | 104 | deleted_product: localProducts, |
103 | - remote_products: config.remote_products | |
104 | - }) | |
105 | + remote_products: config.remote_products, | |
106 | + }); | |
105 | 107 | } |
106 | 108 | |
107 | 109 | router.get('/', pageIndex); |