Commit 97bde7ce4cb8f440a82828ea953f2e6f63c7e20e
Refactor out isInvalidChoice and isPositionAfterClose
Piet Geursen committed on 3/7/2018, 1:02:07 AMParent: b05294a4fda9b4144ba8446e80a727b175dfdcfe
Files changed
package-lock.json | changed |
position/sync/chooseOneResults.js | changed |
package-lock.json | ||
---|---|---|
@@ -306,13 +306,8 @@ | ||
306 | 306 | "version": "4.5.0", |
307 | 307 | "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", |
308 | 308 | "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=" |
309 | 309 | }, |
310 | - "lodash.merge": { | |
311 | - "version": "4.6.1", | |
312 | - "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.1.tgz", | |
313 | - "integrity": "sha512-AOYza4+Hf5z1/0Hztxpm2/xiPZgi/cjMqdnKTUWTBSKchJlxXXuUSxCCl8rJlf4g6yww/j6mA8nC8Hw/EZWxKQ==" | |
314 | - }, | |
315 | 310 | "minimatch": { |
316 | 311 | "version": "3.0.4", |
317 | 312 | "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", |
318 | 313 | "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", |
position/sync/chooseOneResults.js | ||
---|---|---|
@@ -14,9 +14,9 @@ | ||
14 | 14 | module.exports = function ({positions, poll}) { |
15 | 15 | return positions.reduce(function (results, position) { |
16 | 16 | var { positionDetails: {choice} } = Position(position) |
17 | 17 | |
18 | - if (choice >= poll.pollDetails.choices.length || position.value.timestamp > poll.closesAt) { | |
18 | + if (isInvalidChoice({position, poll}) || isPositionAfterClose({position, poll})) { | |
19 | 19 | results.errors.invalidPositions.push(position) |
20 | 20 | return results |
21 | 21 | } |
22 | 22 | |
@@ -27,4 +27,13 @@ | ||
27 | 27 | |
28 | 28 | return results |
29 | 29 | }, {errors: {invalidPositions: []}}) |
30 | 30 | } |
31 | + | |
32 | +function isInvalidChoice ({position, poll}) { | |
33 | + var { positionDetails: {choice} } = Position(position) | |
34 | + return choice >= poll.pollDetails.choices.length | |
35 | +} | |
36 | + | |
37 | +function isPositionAfterClose ({position, poll}) { | |
38 | + return position.value.timestamp > poll.closesAt | |
39 | +} |
Built with git-ssb-web