Within this method, I am accessing a document from a Firebase collection.
I have successfully identified the necessary values to be returned when getUserByUserId()
is invoked, but now I require these values to be structured within 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);
}));
}
The following outlines the structure required for the User
data:
import { PlaceLocation } from './location.model';
export class User {
constructor(
public id: string,
public name: string,
public isMechanic: boolean,
public email: string,
public location: PlaceLocation
) { }
}
Could someone guide me on creating a User
object with this data and returning it as the response of getUserByUserId()
?