Skip to content

Instantly share code, notes, and snippets.

@trblackw
Created March 22, 2020 20:27
Show Gist options
  • Save trblackw/7f6bf09d5ec1e1c451ad5f511add6271 to your computer and use it in GitHub Desktop.
Save trblackw/7f6bf09d5ec1e1c451ad5f511add6271 to your computer and use it in GitHub Desktop.
import { FirebaseModel } from "../firebaseTypes"
import { User } from "./userTypes"
export default class UserModel extends FirebaseModel {
public async getCurrentUser(userId: string): Promise<User> {
const currentUser = await this.store
.collection(UserModel.userCollection)
.doc(userId)
.get()
return { ...currentUser.data(), id: currentUser.id } as User
}
public async getAllUsers(): Promise<User[]> {
const userCollection = await this.store.collection(UserModel.userCollection).get()
return userCollection.map(user => ({
...user.data(),
id: user.id,
})) as User[]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment