Review suggestions

This commit is contained in:
Matthias Rupp 2023-05-07 21:24:55 -11:00
parent ab7102bf50
commit 3e47ca3815
3 changed files with 2 additions and 23 deletions

View file

@ -1,5 +1,5 @@
import { AssetEntity } from '@app/infra/entities';
import { roundToDecimals } from '../../../utils/coordinate.util';
import { round } from 'lodash';
export type MapMarkerResponseDto = [
// latitude
@ -14,7 +14,7 @@ export function mapAssetMapMarker(asset: AssetEntity, preload: boolean): MapMark
const lat = asset.exifInfo?.latitude || 0;
const lon = asset.exifInfo?.longitude || 0;
const response = [roundToDecimals(lat, 5), roundToDecimals(lon, 5)] as MapMarkerResponseDto;
const response: MapMarkerResponseDto = [round(lat, 5), round(lon, 5)];
if (!preload) {
response.push(asset.id);

View file

@ -1,17 +0,0 @@
import { roundToDecimals } from './coordinate.util';
describe('Coordinate utils roundToDecimals test', () => {
it('should round latitude and longitude to 5 digits', () => {
const lat = 49.533547;
const lon = 10.703075;
const latRounded = roundToDecimals(lat, 5);
const lonRounded = roundToDecimals(lon, 5);
expect(latRounded).toBeCloseTo(lat, 4);
expect(lonRounded).toBeCloseTo(lon, 4);
expect(`${latRounded}`.split('.')[1]).toHaveLength(5);
expect(`${lonRounded}`.split('.')[1]).toHaveLength(5);
});
});

View file

@ -1,4 +0,0 @@
export function roundToDecimals(num: number, digits: number): number {
const factor = 10 ** digits;
return Math.round(num * factor + Number.EPSILON) / factor;
}