gradido/backend/src/graphql/resolver/util/Location2Point.ts
einhornimmond 987582c3ef Revert "use root biome config for backend, add useImportType rule"
This reverts commit bb8132791557fb9dcbf117ff7c3622a83e2e3730.
2025-04-30 09:29:09 +02:00

28 lines
803 B
TypeScript

import { Point } from 'typeorm'
import { Location } from '@model/Location'
export function Location2Point(location: Location): Point {
let pointStr: string
if (location.longitude && location.latitude) {
pointStr = '{ "type": "Point", "coordinates": ['
.concat(location.longitude?.toString())
.concat(', ')
.concat(location.latitude?.toString())
.concat('] }')
} else {
pointStr = '{ "type": "Point", "coordinates": [] }'
}
const point = JSON.parse(pointStr) as Point
return point
}
export function Point2Location(point: Point): Location {
const location = new Location()
if (point?.type === 'Point' && point?.coordinates.length === 2) {
location.longitude = point.coordinates[0]
location.latitude = point.coordinates[1]
}
return location
}