I have been working on retrieving a User
object from Firestore within my Angular application.
The User
model looks like this:
import { PlaceLocation } from './location.model';
export class User {
constructor(
public userId: string,
public userName: string,
public isMechanic: boolean,
public location: PlaceLocation
) { }
}
In the component, I have the following code snippet:
user: User;
this.usersService
.getUserByUserId(paramMap.get('id'))
.subscribe(user => {
this.user = user;
});
This is the method in the Users Service used to retrieve the user:
getUserByUserId(userId: string) {
return of(
firebase.firestore().collection("users").where("userId", "==", userId)
.get()
.then((querySnapshot) => {
console.log("Query Snapshot:", querySnapshot);
}).catch((err) => {
console.log("Query Error:", err);
})
);
}
However, when I try to assign this.user = user
, I encounter the following compilation error:
Type 'Promise' is missing the following properties from type 'User': userId, userName, isMechanic, location
I would appreciate some guidance on what changes need to be made to address this issue. Thank you!