git ssb

0+

Piet / ssb-loomio



Commit 97bde7ce4cb8f440a82828ea953f2e6f63c7e20e

Refactor out isInvalidChoice and isPositionAfterClose

Piet Geursen committed on 3/7/2018, 1:02:07 AM
Parent: b05294a4fda9b4144ba8446e80a727b175dfdcfe

Files changed

package-lock.jsonchanged
position/sync/chooseOneResults.jschanged
package-lock.jsonView
@@ -306,13 +306,8 @@
306306 "version": "4.5.0",
307307 "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz",
308308 "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8="
309309 },
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- },
315310 "minimatch": {
316311 "version": "3.0.4",
317312 "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz",
318313 "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==",
position/sync/chooseOneResults.jsView
@@ -14,9 +14,9 @@
1414 module.exports = function ({positions, poll}) {
1515 return positions.reduce(function (results, position) {
1616 var { positionDetails: {choice} } = Position(position)
1717
18- if (choice >= poll.pollDetails.choices.length || position.value.timestamp > poll.closesAt) {
18+ if (isInvalidChoice({position, poll}) || isPositionAfterClose({position, poll})) {
1919 results.errors.invalidPositions.push(position)
2020 return results
2121 }
2222
@@ -27,4 +27,13 @@
2727
2828 return results
2929 }, {errors: {invalidPositions: []}})
3030 }
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