import { ObjectType, Field, ArgsType, InputType, Args } from 'type-graphql'; import { GeolocAddressSearchComponent, GeolocDistComponent, GeolocSearchComponent, PlaceComponent, PlaceComponentOptionnalWithAddress } from '@seed/interfaces/components.geo'; import { GetManyArgs } from '@seed/graphql/Request'; import { Permission } from '@seed/interfaces/permission'; import { AccountTypeEnum } from '@src/accounts/account.components'; import BaseSEOSimpleModel, { EditBaseSEOSimpleInput, NewBaseSEOSimpleInput } from '@seed/graphql/baseModels/BaseSeoSimpleModel'; import { getDistanceBetween } from '../services/GeolocService'; const permissions: Permission = { c: [AccountTypeEnum.admin], r: [AccountTypeEnum.public], w: [AccountTypeEnum.admin], d: [AccountTypeEnum.admin], }; @ObjectType() export default class BaseGeoSimpleSEOModel extends BaseSEOSimpleModel { public constructor(collectionName?: string, perm?: Permission) { const cName = collectionName ? collectionName : 'articles'; const permission = perm ? perm : permissions; super(cName, permission); } @Field(() => PlaceComponent) place: PlaceComponent; @Field(() => GeolocDistComponent, { nullable: true }) dist?: GeolocDistComponent; // eslint-disable-next-line @typescript-eslint/explicit-function-return-type @Field(() => Number, { nullable: true }) async getDistFromLocation(@Args() location: GeolocSearchComponent) { return getDistanceBetween( { latitude: this.place.loc.coordinates[1], longitude: this.place.loc.coordinates[0], }, location, ); } searchOptions(): string[] { return []; } filterOptions(): string[] { return []; } } @ArgsType() export class BaseGeoArgs extends GetManyArgs { @Field(() => GeolocSearchComponent, { nullable: true }) geoSearch?: GeolocSearchComponent; @Field(() => GeolocAddressSearchComponent, { nullable: true }) geoSearchWithAddress?: GeolocAddressSearchComponent; } @InputType() export class NewGeoBaseSEOSimpleInput extends NewBaseSEOSimpleInput implements Partial { @Field(() => PlaceComponent) place: PlaceComponent; } @InputType() export class EditGeoBaseSEOSimpleInput extends EditBaseSEOSimpleInput implements Partial { @Field(() => PlaceComponent, { nullable: true }) place?: PlaceComponent; } @InputType() export class NewGeoWithAddressBaseSEOSimpleInput extends NewBaseSEOSimpleInput implements Partial { @Field(() => PlaceComponentOptionnalWithAddress) place: PlaceComponentOptionnalWithAddress; } @InputType() export class EditGeoWithAddressBaseSEOSimpleInput extends EditBaseSEOSimpleInput implements Partial { @Field(() => PlaceComponentOptionnalWithAddress, { nullable: true }) place?: PlaceComponentOptionnalWithAddress; }