Skip to content

Commit

Permalink
fix: Typing in a taxonomy code properly does a taxonomy query
Browse files Browse the repository at this point in the history
  • Loading branch information
devcshort committed Oct 7, 2024
1 parent a96a1f2 commit 8736782
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/shared/services/search-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { API_URL } from '../lib/constants';
import qs from 'qs';
import _ from 'lodash';
import { Axios } from '../lib/axios';
import { TaxonomyService } from './taxonomy-service';

export class SearchService {
static endpoint = 'search';
Expand All @@ -14,10 +15,16 @@ export class SearchService {
) {
const hasLocation = searchStore['userCoordinates']?.length === 2;

const isTaxonomyCode = TaxonomyService.isTaxonomyCode(
searchStore['query']?.trim(),
);

const urlParams = {
query: searchStore['query']?.trim(),
query_label: searchStore['queryLabel']?.trim(),
query_type: searchStore['queryType']?.trim(),
query_type: isTaxonomyCode
? 'taxonomy'
: searchStore['queryType']?.trim(),
location: hasLocation ? searchStore['userLocation']?.trim() : null,
coords: hasLocation
? searchStore['userCoordinates']?.join(',')?.trim()
Expand Down
8 changes: 8 additions & 0 deletions src/shared/services/taxonomy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ import { Axios } from '../lib/axios';
export class TaxonomyService {
static endpoint = 'taxonomy';

static taxonomyCodeRegexp = new RegExp(
/^[a-zA-Z]{1,2}(-\d{1,4}(\.\d{1,4}){0,3})?$/i,
);

static isTaxonomyCode(code: string) {
return this.taxonomyCodeRegexp.test(code);
}

static async getTaxonomies(searchTerm: string, options: { locale: string }) {
const res = await Axios.get(`${API_URL}/${this.endpoint}`, {
params: {
Expand Down

0 comments on commit 8736782

Please sign in to comment.