60 lines
2.4 KiB
TypeScript
60 lines
2.4 KiB
TypeScript
import { Resolver, Query, Arg, Mutation, Ctx, Args, Authorized, Field, ArgsType } from 'type-graphql';
|
|
|
|
import { ApolloContext } from '@seed/interfaces/context';
|
|
|
|
import { GraphQLJSONObject } from 'graphql-type-json';
|
|
import { MinLength } from 'class-validator';
|
|
import { AvailableTranslation } from '@src/__components/components';
|
|
import { CountryCodesComponentEnum } from '../components/countries';
|
|
import { autocompleteService, getGeoLocFromAddress, getPlaceDetail } from '../services/GooglePlaceService';
|
|
|
|
@ArgsType()
|
|
export class AutocompleteArgs {
|
|
@Field()
|
|
session: string;
|
|
|
|
@Field()
|
|
@MinLength(5)
|
|
input: string;
|
|
|
|
@Field(() => AvailableTranslation, { nullable: true })
|
|
language?: AvailableTranslation;
|
|
@Field(() => [CountryCodesComponentEnum], { nullable: true })
|
|
country?: CountryCodesComponentEnum[];
|
|
}
|
|
|
|
@ArgsType()
|
|
export class GeolocFromLocationIdInput {
|
|
@Field()
|
|
session: string;
|
|
@Field()
|
|
placeId: string;
|
|
}
|
|
|
|
@Resolver()
|
|
export default class GooglePlaceResolver {
|
|
/*
|
|
██████╗ ██╗ ██╗███████╗██████╗ ██╗ ██╗
|
|
██╔═══██╗██║ ██║██╔════╝██╔══██╗╚██╗ ██╔╝
|
|
██║ ██║██║ ██║█████╗ ██████╔╝ ╚████╔╝
|
|
██║▄▄ ██║██║ ██║██╔══╝ ██╔══██╗ ╚██╔╝
|
|
╚██████╔╝╚██████╔╝███████╗██║ ██║ ██║
|
|
╚══▀▀═╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═╝
|
|
*/
|
|
|
|
@Query(() => [GraphQLJSONObject])
|
|
async placesAutocomplete(@Args() args: AutocompleteArgs, @Ctx() ctx: ApolloContext): Promise<any[]> {
|
|
return await autocompleteService(args.session, args.input, args.language, args.country);
|
|
}
|
|
|
|
@Query(() => GraphQLJSONObject)
|
|
async placesGeocode(@Args() args: GeolocFromLocationIdInput, @Ctx() ctx: ApolloContext): Promise<any> {
|
|
return await getPlaceDetail(args.session, args.placeId);
|
|
}
|
|
|
|
@Query(() => GraphQLJSONObject)
|
|
async placesGeocodeFromAddress(@Arg('address') address: string, @Ctx() ctx: ApolloContext): Promise<any> {
|
|
return await getGeoLocFromAddress(address);
|
|
}
|
|
}
|