In the below method, I am retrieving a document from a Firebase collection.
I have managed to log the values I need to return when getUserByUserId() is called, but I need to return them as a User object:
getUserByUserId(userId: string) {
return of(firebase.firestore().collection("users").where("userId", "==", userId)
.get().then(querySnapshot => {
querySnapshot.forEach(doc => {
console.log("User ID", "=>", doc.data().userId);
console.log("Username", "=>", doc.data().userName);
console.log("Mechanic", "=>", doc.data().isMechanic);
console.log("Location", "=>", doc.data().location);
})
}).catch(err => {
console.log(err);
}));
}
Here is the User structure that the data will need to follow:
import { PlaceLocation } from './location.model';
export class User {
constructor(
public id: string,
public name: string,
public isMechanic: boolean,
public email: string,
public location: PlaceLocation
) { }
}
Can someone please tell me how I can create a User object with this data & return it as the response of getUserByUserId()?