import HTTPClient from './HTTPClient' ; import { Province } from '../enums/Province' ; import { Municipality , MunicipalityRaw } from '../models/Municipality' ; import { SuburbRaw , Suburb } from '../models/Suburb' ; import { SearchSuburbRaw , SearchSuburb } from '../models/SearchSuburb' ; export class Search extends HTTPClient { public static async getMunicipalitiesRaw ( province ) { const resp = await this . get ( '/GetMunicipalities/?Id=' + province ) ; return resp . data ; } public static async getMunicipalities ( province ) { const municipalities = await this . getMunicipalitiesRaw ( province ) ; return municipalities . map ( ( municipality ) => Municipality . fromRaw ( municipality ) ) ; } public static async getMunicipalitySuburbsRaw ( municipalityId , searchTerm = '' , pageNum = 1 ) { const resp = await this . get ( `/GetSurburbData/?pageSize=100&pageNum=${ pageNum }&searchTerm=${ searchTerm }&id=${ municipalityId }` ) ; return resp . data . Results ; } public static async getMunicipalitySuburbs ( municipalityId , searchTerm = '' , pageNum = 1 ) { const suburbs = await this . getMunicipalitySuburbsRaw ( municipalityId , searchTerm , pageNum ) ; return suburbs . map ( ( suburb ) => Suburb . fromRaw ( suburb ) ) ; } public static async searchSuburbsRaw ( searchTerm , maxResults = 300 ) { const resp = await this . get ( `/FindSuburbs?searchText=${ searchTerm }&maxResults=${ maxResults }` ) ; return resp . data ; } public static async searchSuburbs ( searchTerm , maxResults = 300 ) { const searchResults = await this . searchSuburbsRaw ( searchTerm , maxResults ) ; return searchResults . map ( ( result ) => SearchSuburb . fromRaw ( result ) ) ; } }