mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
test for updateUserInfo with geolocation but with db-driver error
This commit is contained in:
parent
f875214eff
commit
b2d2501f89
32
backend/src/graphql/resolver/util/Location2Point.ts
Normal file
32
backend/src/graphql/resolver/util/Location2Point.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import { Point } from '@dbTools/typeorm'
|
||||
|
||||
import { Location } from '@model/Location'
|
||||
|
||||
export function Location2Point(location: Location): Point {
|
||||
console.log('in Location2Point:', location)
|
||||
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": [] }'
|
||||
}
|
||||
console.log('pointStr:', pointStr)
|
||||
const point = JSON.parse(pointStr) as Point
|
||||
console.log('point:', point)
|
||||
return point
|
||||
}
|
||||
|
||||
export function Point2Location(point: Point): Location {
|
||||
console.log('in Point2Location:', point)
|
||||
const location = new Location()
|
||||
if (point.type === 'Point' && point.coordinates.length === 2) {
|
||||
location.longitude = point.coordinates[0]
|
||||
location.latitude = point.coordinates[1]
|
||||
}
|
||||
console.log('location:', location)
|
||||
return location
|
||||
}
|
||||
@ -1,33 +0,0 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { Geometry as DbGeometry } from '@dbTools/typeorm'
|
||||
import { GraphQLScalarType, Kind } from 'graphql'
|
||||
|
||||
import { Location } from '@model/Location'
|
||||
|
||||
export const GeometryScalar = new GraphQLScalarType({
|
||||
name: 'Geometry',
|
||||
description:
|
||||
'The `Geometry` scalar type to represent longitude and latitude values of a geo location',
|
||||
|
||||
serialize(value: DbGeometry): Location {
|
||||
// Check type of value
|
||||
if (value.type !== 'Point') {
|
||||
throw new Error(`GeometryScalar can only serialize Geometry type 'Point' values`)
|
||||
}
|
||||
|
||||
return new Location(value.coordinates[0], value.coordinates[1])
|
||||
},
|
||||
|
||||
parseValue(value): DbGeometry {
|
||||
const geometry: DbGeometry = JSON.parse(value) as DbGeometry
|
||||
return geometry
|
||||
},
|
||||
|
||||
parseLiteral(ast) {
|
||||
if (ast.kind !== Kind.STRING) {
|
||||
throw new TypeError(`${String(ast)} is not a valid Geometry value.`)
|
||||
}
|
||||
|
||||
return JSON.parse(ast.value) as DbGeometry
|
||||
},
|
||||
})
|
||||
46
backend/src/graphql/scalar/Location.ts
Normal file
46
backend/src/graphql/scalar/Location.ts
Normal file
@ -0,0 +1,46 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { GraphQLScalarType, Kind } from 'graphql'
|
||||
|
||||
import { Location } from '@model/Location'
|
||||
|
||||
export const LocationScalar = new GraphQLScalarType({
|
||||
name: 'Location',
|
||||
description:
|
||||
'The `Location` scalar type to represent longitude and latitude values of a geo location',
|
||||
|
||||
serialize(value: Location) {
|
||||
console.log('serialize LocationScalar:', value)
|
||||
return value
|
||||
},
|
||||
|
||||
parseValue(value): Location {
|
||||
console.log('parseValue LocationScalar:', value)
|
||||
try {
|
||||
const loc = new Location()
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
||||
loc.longitude = value.longitude
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
||||
loc.latitude = value.latitude
|
||||
console.log('parsed:', loc)
|
||||
return loc
|
||||
} catch (err) {
|
||||
console.log('Error:', err)
|
||||
}
|
||||
return new Location()
|
||||
},
|
||||
|
||||
parseLiteral(ast): Location {
|
||||
console.log('parseLiteral LocationScalar:', ast)
|
||||
if (ast.kind !== Kind.STRING) {
|
||||
throw new TypeError(`${String(ast)} is not a valid Location value.`)
|
||||
}
|
||||
let loc = new Location()
|
||||
try {
|
||||
loc = JSON.parse(ast.value) as Location
|
||||
console.log('parsed:', loc)
|
||||
} catch (err) {
|
||||
console.log('Error:', err)
|
||||
}
|
||||
return loc
|
||||
},
|
||||
})
|
||||
31
backend/src/graphql/scalar/Point.ts
Normal file
31
backend/src/graphql/scalar/Point.ts
Normal file
@ -0,0 +1,31 @@
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-argument */
|
||||
import { Point as DbPoint } from '@dbTools/typeorm'
|
||||
import { GraphQLScalarType, Kind } from 'graphql'
|
||||
|
||||
export const PointScalar = new GraphQLScalarType({
|
||||
name: 'Point',
|
||||
description:
|
||||
'The `Point` scalar type to represent longitude and latitude values of a geo location',
|
||||
|
||||
serialize(value: DbPoint) {
|
||||
// Check type of value
|
||||
if (value.type !== 'Point') {
|
||||
throw new Error(`PointScalar can only serialize Geometry type 'Point' values`)
|
||||
}
|
||||
return value
|
||||
},
|
||||
|
||||
parseValue(value): DbPoint {
|
||||
const point = JSON.parse(value) as DbPoint
|
||||
return point
|
||||
},
|
||||
|
||||
parseLiteral(ast) {
|
||||
if (ast.kind !== Kind.STRING) {
|
||||
throw new TypeError(`${String(ast)} is not a valid Geometry value.`)
|
||||
}
|
||||
|
||||
const point = JSON.parse(ast.value) as DbPoint
|
||||
return point
|
||||
},
|
||||
})
|
||||
@ -4,21 +4,27 @@ import { Decimal } from 'decimal.js-light'
|
||||
import { GraphQLSchema } from 'graphql'
|
||||
import { buildSchema } from 'type-graphql'
|
||||
|
||||
import { Location } from '@model/Location'
|
||||
|
||||
import { isAuthorized } from './directive/isAuthorized'
|
||||
import { DecimalScalar } from './scalar/Decimal'
|
||||
import { LocationScalar } from './scalar/Location'
|
||||
|
||||
export const schema = async (): Promise<GraphQLSchema> => {
|
||||
return buildSchema({
|
||||
resolvers: [path.join(__dirname, 'resolver', `!(*.test).{js,ts}`)],
|
||||
authChecker: isAuthorized,
|
||||
scalarsMap: [{ type: Decimal, scalar: DecimalScalar }],
|
||||
scalarsMap: [
|
||||
{ type: Decimal, scalar: DecimalScalar },
|
||||
{ type: Location, scalar: LocationScalar },
|
||||
],
|
||||
validate: {
|
||||
validationError: { target: false },
|
||||
skipMissingProperties: true,
|
||||
skipNullProperties: true,
|
||||
skipUndefinedProperties: false,
|
||||
forbidUnknownValues: true,
|
||||
stopAtFirstError: true,
|
||||
skipUndefinedProperties: true,
|
||||
forbidUnknownValues: false,
|
||||
stopAtFirstError: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user