Commit d5dfe4ff42710b10cab6e93308a36e028a3fa455
1 parent
1de2955e1c
Exists in
master
Fix eslint on api-server/router-locations
Showing 1 changed file with 23 additions and 21 deletions Side-by-side Diff
api-server/router-locations.js
1 | -"use strict"; | |
2 | - | |
3 | 1 | const express = require('express'); |
4 | 2 | const naturalSort = require('node-natural-sort'); |
5 | 3 | const unique = require('array-unique'); |
... | ... | @@ -14,39 +12,42 @@ function pageIndex(req, res) { |
14 | 12 | res.json({ |
15 | 13 | method: '/locations', |
16 | 14 | error: null, |
17 | - result: config.locations | |
15 | + result: config.locations, | |
18 | 16 | }); |
19 | 17 | } |
20 | 18 | |
21 | 19 | function pageAdd(req, res) { |
22 | - let locations = req.params.locations || req.query.locations | |
20 | + let locations = req.params.locations || req.query.locations; | |
23 | 21 | |
24 | 22 | if (!locations) { |
25 | 23 | res.json({ |
26 | 24 | method: '/locations/add', |
27 | 25 | error: true, |
28 | - error_msg: 'Usage: /locations/add/<NEW_LOCATION>' | |
26 | + error_msg: 'Usage: /locations/add/<NEW_LOCATION>', | |
29 | 27 | }); |
30 | 28 | |
31 | 29 | return; |
32 | 30 | } |
33 | 31 | |
34 | 32 | if (typeof locations === 'string') { |
35 | - locations = locations.trim().split(/[\s,]+/).filter((el) => { return el.toUpperCase() !== 'ALL'; }); | |
33 | + locations = locations | |
34 | + .trim() | |
35 | + .split(/[\s,]+/) | |
36 | + .filter((loc) => typeof loc === 'string') | |
37 | + .map((loc) => loc.trim().toUpperCase()) | |
38 | + .filter((loc) => loc && (loc !== 'ALL')); | |
36 | 39 | } |
37 | 40 | |
38 | 41 | const locationsCount = locations.length; |
39 | - for (let i=0; i<locationsCount; i++) { | |
42 | + for (let i = 0; i < locationsCount; i += 1) { | |
40 | 43 | const location = locations[i]; |
41 | - if (!location.trim()) { | |
42 | - continue; | |
43 | - } | |
44 | 44 | |
45 | 45 | if (!config.locations) config.locations = []; |
46 | - config.locations.push(location.trim().toUpperCase()); | |
46 | + config.locations.push(location); | |
47 | 47 | } |
48 | 48 | |
49 | - config.locations.map(function(x) { return x.toUpperCase(); }); | |
49 | + // config.locations.map((x) => x.toUpperCase()); | |
50 | + | |
50 | 51 | unique(config.locations); |
51 | 52 | config.locations.sort(naturalSort()); |
52 | 53 | matrix.config_is_dirty = true; |
... | ... | @@ -55,17 +56,17 @@ function pageAdd(req, res) { |
55 | 56 | method: '/locations/add', |
56 | 57 | error: null, |
57 | 58 | new_location: locations, |
58 | - locations: config.locations | |
59 | - }) | |
59 | + locations: config.locations, | |
60 | + }); | |
60 | 61 | } |
61 | 62 | |
62 | 63 | function pageDel(req, res) { |
63 | - let locations = req.params.locations || req.query.locations | |
64 | + let locations = req.params.locations || req.query.locations; | |
64 | 65 | if (!locations) { |
65 | 66 | res.json({ |
66 | 67 | method: '/locations/del', |
67 | 68 | error: true, |
68 | - error_msg: 'Usage: /locations/del/<LOCATION_TO_DELETE> or /locations/del?locations=<LOCATION_TO_DELETE>' | |
69 | + error_msg: 'Usage: /locations/del/<LOCATION_TO_DELETE> or /locations/del?locations=<LOCATION_TO_DELETE>', | |
69 | 70 | }); |
70 | 71 | |
71 | 72 | return; |
... | ... | @@ -75,14 +76,15 @@ function pageDel(req, res) { |
75 | 76 | locations = locations.trim().split(/[\s,]+/); |
76 | 77 | } |
77 | 78 | |
78 | - config.locations.map(function(x) { return x.toUpperCase(); }); | |
79 | + // config.locations.map((x) => x.toUpperCase()); | |
79 | 80 | const locationsCount = locations.length; |
80 | - for (let i=0; i<locationsCount; i++) { | |
81 | + | |
82 | + for (let i = 0; i < locationsCount; i += 1) { | |
81 | 83 | const location = locations[i].toUpperCase(); |
82 | 84 | const idx = config.locations.indexOf(location); |
83 | 85 | if (idx >= 0) { |
84 | 86 | matrix.config_is_dirty = true; |
85 | - config.locations.splice(idx, 1) | |
87 | + config.locations.splice(idx, 1); | |
86 | 88 | } |
87 | 89 | } |
88 | 90 | |
... | ... | @@ -90,8 +92,8 @@ function pageDel(req, res) { |
90 | 92 | method: '/locations/del', |
91 | 93 | error: null, |
92 | 94 | locations_to_delete: locations, |
93 | - locations: config.locations | |
94 | - }) | |
95 | + locations: config.locations, | |
96 | + }); | |
95 | 97 | } |
96 | 98 | |
97 | 99 | router.get('/', pageIndex); |