This commit is contained in:
einhornimmond 2024-06-24 12:38:33 +02:00
parent 1b4550b658
commit 5f1bd0faae
5 changed files with 12 additions and 8 deletions

View File

@ -11,11 +11,11 @@ export class EditCommunityInput {
@IsUUID('4')
uuid: string
@Field(() => String, {nullable: true})
@Field(() => String, { nullable: true })
@IsString()
gmsApiKey: string | null
gmsApiKey?: string | null
@Field(() => Point, {nullable: true})
@Field(() => Point, { nullable: true })
@isValidPoint()
location: Point | null
location?: Point | null
}

View File

@ -5,6 +5,7 @@ export class Point implements geojsonPoint {
this.coordinates = []
this.type = 'Point'
}
type: 'Point'
coordinates: Position
}

View File

@ -89,8 +89,8 @@ export class CommunityResolver {
throw new LogError('Error: Only the HomeCommunity could be modified!')
}
if (homeCom.gmsApiKey !== gmsApiKey || homeCom.location !== location) {
homeCom.gmsApiKey = gmsApiKey
homeCom.location = location
homeCom.gmsApiKey = gmsApiKey ?? null
homeCom.location = location ?? null
await DbCommunity.save(homeCom)
}
return new Community(homeCom)

View File

@ -1,5 +1,6 @@
/* eslint-disable @typescript-eslint/no-unsafe-argument */
import { GraphQLScalarType, Kind } from 'graphql'
import { Point } from '@/graphql/model/Point'
export const PointScalar = new GraphQLScalarType({
@ -10,14 +11,15 @@ export const PointScalar = new GraphQLScalarType({
serialize(value: Point) {
// Check type of value
if (value.type !== 'Point') {
throw new Error(`PointScalar can only serialize Geometry type 'Point' values`, )
throw new Error(`PointScalar can only serialize Geometry type 'Point' values`)
}
return value
},
parseValue(value): Point {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
if (value.type !== 'Point') {
throw new Error(`PointScalar can only deserialize Geometry type 'Point' values`, )
throw new Error(`PointScalar can only deserialize Geometry type 'Point' values`)
}
return value as Point
},

View File

@ -1,4 +1,5 @@
import { registerDecorator, ValidationOptions, ValidationArguments } from 'class-validator'
import { Point } from '@/graphql/model/Point'
export function isValidPoint(validationOptions?: ValidationOptions) {