UNPKG

soda-angular

Version:
40 lines (39 loc) 1.47 kB
import { WithinBox } from '../../soql-query/clauses/where/functions/within-box'; import { WithinCircle } from '../../soql-query/clauses/where/functions/within-circle'; import { WhereValue } from '../../soql-query/clauses/where/where-value'; export class LocationFilter { constructor(query, column, ...prependOperators) { this.query = query; this.column = column; if (!query) { throw new Error("query must be provided"); } if (!column) { throw new Error("column must be provided"); } this.prependOperators = prependOperators; } withinCircle(location, radius) { if (!location) { throw new Error("Location must be provided"); } if (!radius) { throw new Error("Radius must be provided"); } const filter = new WithinCircle(this.column, new WhereValue(location), radius); return this.addFilter(filter); } withinBox(start, end) { if (!start) { throw new Error("Start location must be provided"); } if (!end) { throw new Error("End location must be provided"); } const filter = new WithinBox(this.column, new WhereValue(start), new WhereValue(end)); return this.addFilter(filter); } addFilter(filter) { return this.query.addFilter(...this.prependOperators, filter); } }