I am currently working on a NestJS interceptor to geolocate an address that is being sent through a REST API. Here is the code snippet:
export class PointsInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
var myAddress = context.switchToHttp().getRequest().body;
const geoCodingObservable = from(geocoder.geocode(myAddress));
geoCodingObservable.subscribe(value => console.log(JSON.stringify(value)));
return next.handle().pipe(map(value => console.log(value)))
}
}
The output of this code includes:
- a JSON object from the HTTP response:
{
address: '123, Avenue des Champs Elysées, 75008 PARIS',
_id: new ObjectId("64bd089088f925780705bbbd"),
__v: 0
}
- An object obtained from the geoCoder
[{"latitude":48.872438,"longitude":2.29811,"state":"75, Paris, Île-de-France","city":"Paris","zipcode":...}]
My goal is to combine all this information into a single JSON object that can be "pushed to the database". I have tried using merge and mergeWith, but without success.
Any assistance on this matter would be highly appreciated.
Thank you.