import type { AxiosResponse } from 'axios' ; import { InvalidCredentialsException } from '../../../../exception' ; import { AccuracyEnum } from '../../../../model' ; import { HereLocationTransformer } from '../../transformer' ; import { filterByAccuracy } from '../../util' ; import type { AbstractCommand } from '../../../../command' ; import type { Query } from '../../../../model' ; import type { Constructor } from '../../../../types' ; import type { HereOneResultType , HereResponseType } from '../../interface' ; export function HereCommonCommandMixin < TBase extends Constructor < AbstractCommand > > ( Base ) { abstract class HereCommonCommand extends Base { protected readonly appId : string ; protected readonly appCode : string ; protected constructor ( ... args ) { super ( args [ 0 ] ) ; this . appId = args [ 1 ] ; this . appCode = args [ 2 ] ; if ( ! this . appId || ! this . appCode ) { throw new InvalidCredentialsException ( 'Invalid or missing api key.' ) ; } } static getMaxAccuracy ( ) { return AccuracyEnum . HOUSE_NUMBER ; } protected async validateResponse ( _response ) { } protected async parseResponse ( response , query ) { if ( ! response . data . Response || ! Array . isArray ( response . data . Response . View ) || ! response . data . Response . View [ 0 ] ) { return [ ] ; } let results = response . data . Response . View [ 0 ] . Result ; results = results . filter ( ( raw ) => filterByAccuracy ( raw , query . accuracy ) ) ; if ( ! results . length ) { return [ ] ; } return Promise . all < HereLocationTransformer > ( results . map ( async ( raw ) : Promise < HereLocationTransformer > => new HereLocationTransformer ( raw ) ) ) ; } } return HereCommonCommand ; }