backend/lib/seed/services/geolocation/models/BaseGeoSimpleModel.ts
2025-05-14 21:45:16 +02:00

84 lines
2.9 KiB
TypeScript

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<BaseSEOSimpleModel> {
@Field(() => PlaceComponent)
place: PlaceComponent;
}
@InputType()
export class EditGeoBaseSEOSimpleInput extends EditBaseSEOSimpleInput implements Partial<BaseSEOSimpleModel> {
@Field(() => PlaceComponent, { nullable: true })
place?: PlaceComponent;
}
@InputType()
export class NewGeoWithAddressBaseSEOSimpleInput extends NewBaseSEOSimpleInput implements Partial<BaseSEOSimpleModel> {
@Field(() => PlaceComponentOptionnalWithAddress)
place: PlaceComponentOptionnalWithAddress;
}
@InputType()
export class EditGeoWithAddressBaseSEOSimpleInput extends EditBaseSEOSimpleInput implements Partial<BaseSEOSimpleModel> {
@Field(() => PlaceComponentOptionnalWithAddress, { nullable: true })
place?: PlaceComponentOptionnalWithAddress;
}