67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { ObjectType, Field, ArgsType, InputType, Args } from 'type-graphql';
|
|
|
|
import { GetManyArgs } from '@seed/graphql/Request';
|
|
|
|
|
|
import { Permission } from '@seed/interfaces/permission';
|
|
import { AccountTypeEnum } from '@src/accounts/account.components';
|
|
import BaseSEOModel, { EditBaseSEOInput, NewBaseSEOInput } from '@seed/graphql/baseModels/BaseSeoModel';
|
|
import { getDistanceBetween } from '../services/GeolocService';
|
|
import { GeolocDistComponent, GeolocSearchComponent, PlaceComponent } from '@seed/interfaces/components.geo';
|
|
|
|
const permissions: Permission = {
|
|
c: [AccountTypeEnum.admin],
|
|
r: [AccountTypeEnum.public],
|
|
w: [AccountTypeEnum.admin],
|
|
d: [AccountTypeEnum.admin],
|
|
};
|
|
|
|
@ObjectType()
|
|
export default class BaseGeoSEOModel extends BaseSEOModel {
|
|
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 BaseSEOArgs extends GetManyArgs {}
|
|
|
|
@InputType()
|
|
export class NewGeoBaseSEOInput extends NewBaseSEOInput implements Partial<BaseSEOModel> {
|
|
@Field(() => PlaceComponent)
|
|
place: PlaceComponent;
|
|
}
|
|
|
|
@InputType()
|
|
export class EditGeoBaseSEOInput extends EditBaseSEOInput implements Partial<BaseSEOModel> {
|
|
@Field(() => PlaceComponent, { nullable: true })
|
|
place?: PlaceComponent;
|
|
}
|