backend: route save / restore

This commit is contained in:
muerwre 2018-11-30 13:49:03 +07:00
parent 032821329b
commit d932fcb287
17 changed files with 163 additions and 43 deletions

24
backend/utils/parse.js Normal file
View file

@ -0,0 +1,24 @@
module.exports.parseRoute = route => route.filter(el => (
Object.keys(el).length === 2
&& el.lat
&& parseInt(el.lat, 10) > 0
&& parseInt(el.lat, 10) < 1000
&& el.lng
&& parseInt(el.lng, 10) > 0
&& parseInt(el.lng, 10) < 1000
));
module.exports.parseStickers = stickers => stickers.filter(el => (
Object.keys(el).length === 3
&& el.latlng
&& Object.keys(el.latlng).length === 2
&& el.latlng.lat
&& parseInt(el.latlng.lat, 10) > 0
&& parseInt(el.latlng.lat, 10) < 1000
&& el.latlng.lng
&& parseInt(el.latlng.lng, 10) > 0
&& parseInt(el.latlng.lng, 10) < 1000
));
module.exports.parseString = (value, size) => (value && String(value).substr(0, size)) || '';
module.exports.parseNumber = (value, min, max) => (value && Number(value) && Math.min(max, Math.max(min, value))) || 0;