I want to fetch and join multiple collections based on user's location with geofirex:
Here's my code when I get users docs based on location : PS (This code returns only user's docs based on location)
getAround() {
const center = geo.point(this.lat, this.lng);
const field = 'location';
this.points = this.radius.pipe(
switchMap(r => {
return this.geo.query(locations).within(center, r, field, { log: true });
})
);
}
How I inner join collections with Rxjs :
getAll() {
const allPosts = this.afStore.collection<Service>('services')
.valueChanges()
.pipe(
switchMap(services => {
const res = services.map((service: Service) => {
return this.afStore.doc<UserModel>(`users/${service.userId}`)
.valueChanges()
.pipe(
map(user => Object.assign(service, { user }))
);
});
return combineLatest([...res]); })
)
.pipe(
switchMap(servuser => {
const ress = servuser.map((service: Service) => {
return this.afStore.doc<Category>(`categorys/${service.iconId}`)
.valueChanges()
.pipe(
map(category => Object.assign(service, { category }))
);
});
return combineLatest([... ress]);
})
);
return allPosts;
}
The problem is I can't mix these codes together so I can get my data joined and based on user's location,
I get this error:
(alias) interface Service
import Service
Argument of type '(service: Service) => Observable<Service & { user: UserModel; }>' is not assignable to parameter of type '(value: GeoQueryDocument, index: number, array: GeoQueryOocument[]) => Observable<Service & { user: UserModel; }>'. Types of parameters 'service' and 'value' are incompatible.
Type 'GeoQuerpocument' is missing the following properties from type 'Service': id, cost, dateCreated, discount, and 6 more.