diff --git a/src/structures/services/structures.service.ts b/src/structures/services/structures.service.ts index 69ad57271435a42fa40c2dbaa9f3c270df27b815..3826f7023899805f2048f8e4077eefcfcfefae88 100644 --- a/src/structures/services/structures.service.ts +++ b/src/structures/services/structures.service.ts @@ -2,7 +2,6 @@ import { HttpService } from '@nestjs/axios'; import { HttpException, HttpStatus, Inject, Injectable, Logger, forwardRef } from '@nestjs/common'; import { InjectModel } from '@nestjs/mongoose'; import { Cron, CronExpression } from '@nestjs/schedule'; -import { AxiosResponse } from 'axios'; import * as ejs from 'ejs'; import * as _ from 'lodash'; import { DateTime } from 'luxon'; @@ -27,6 +26,7 @@ import { Structure, StructureDocument } from '../schemas/structure.schema'; import { StructuresSearchService } from './structures-search.service'; import { PhotonPoints } from '../interfaces/photon-response.interface'; import { JobsService } from '../../users/services/jobs.service'; +import { AxiosResponse } from 'axios'; @Injectable() export class StructuresService { @@ -550,11 +550,11 @@ export class StructuresService { * Search structure address based on data search WS * @param {searchQuery} data - Query address */ - public async searchAddress(data: { searchQuery: string }): Promise<{ features: PhotonPoints[] }> { + public async searchAddress(data: { searchQuery: string }) { const reqBan = `https://download.data.grandlyon.com/geocoding/photon/api?q=${data.searchQuery}&lang=fr&limit=500&osm_tag=:!construction&osm_tag=:!bus_stop`; const reqBal = `https://download.data.grandlyon.com/geocoding/photon-bal/api?q=${data.searchQuery}&lang=fr&limit=500&osm_tag=:!construction&osm_tag=:!bus_stop`; - const requestGroup = async (url: string): Promise<AxiosResponse<{ features: PhotonPoints[] }>> => { + const requestGroup = async (url: string) => { const response$ = this.httpService.get<{ features: PhotonPoints[] }>(encodeURI(url), { headers: { 'Content-Type': 'application/json' }, }); @@ -650,8 +650,9 @@ export class StructuresService { ' ' + commune; this.logger.debug('Print getCoord ' + req); - - return await lastValueFrom(this.httpService.get(encodeURI(req))); + const obs = this.httpService.get<PhotonResponse>(encodeURI(req)); + const response = (await lastValueFrom(obs)) as unknown as Promise<AxiosResponse<PhotonResponse>>; + return response; } /** @@ -1046,9 +1047,9 @@ export class StructuresService { */ public getCNFSStructures(): Promise<Array<CNFSStructure>> { this.logger.debug(`get CNFS structures`); - const obs = this.httpService.get('https://api.conseiller-numerique.gouv.fr/permanences').pipe( - map((response: AxiosResponse<Array<CNFSStructure>>) => - response.data.filter((structure: CNFSStructure) => { + const obs = this.httpService.get<Array<CNFSStructure>>('https://api.conseiller-numerique.gouv.fr/permanences').pipe( + map((response) => + response.data.filter((structure) => { if (structure.code_postal.substring(0, 2) === '69' && (structure.courriel || structure.telephone)) return structure; })