import {Profile} from '../models/Profile'; import {ProfilesAPI} from '../ProfilesAPI'; import {FirestoreAPI} from './FirestoreAPI'; import {App, Firestore} from './FirestoreTypes'; export class FirebaseProfilesAPI extends FirestoreAPI implements ProfilesAPI { constructor(app: App) { super(app); } get = async (uid: string): Promise => { const doc = await this.profileRef(uid).get(); return doc.exists ? (doc.data() as Profile) : undefined; }; set = async (profile: Profile): Promise => { await this.profileRef(profile.uid).set(profile); }; delete = async (uid: string): Promise => { await this.profileRef(uid).delete(); }; // TODO: Create index on email in profiles uidWihEmail = async (email: string): Promise => { const profiles = await this.profilesRef().where('email', '==', email).get(); return profiles.docs.pop()?.id; }; }