All files / src/services/translators CurrentLocationTranslator.js

100% Statements 15/15
100% Branches 8/8
100% Functions 0/0
100% Lines 15/15
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49    1x       1x 1x 1x         7x 2x     5x   5x 1x     4x 2x     2x   2x 1x                 1x                  
'use es6';
 
import {
  List,
} from 'immutable';
 
import Coordinate from '../../data/Coordinate';
import Location from '../../data/Location';
import Utilities from '../../Utilities';
 
export default class CurrentLocationTranslator {
  static translate(json) {
 
    if (!('latitude' in json)) {
      throw new ReferenceError('expected latitude field');
    }
 
    const latitude = json['latitude'];
 
    if (typeof(latitude) !== 'number') {
      throw new TypeError('expected latitude to be a number');
    }
 
    if (!('longitude' in json)) {
      throw new ReferenceError('expected longitude field');
    }
 
    const longitude = json['longitude'];
    
    if (typeof(longitude) !== 'number') {
      throw new TypeError('expected longitude to be a number');
    }
 
    // Uncomment below for showing current location address
    // return new Coordinate({
    //   latitude: latitude,
    //   longitude: longitude,
    // });
 
    return new Location({
      name: 'Current Location',
      coordinate: new Coordinate({
        latitude: latitude,
        longitude: longitude,
      }),
    });
  }
}