I know what you mean. All of this code to run one query:
import { initializeApp, getFirestore, getAuth, signInWithEmailAndPassword, collection, getDocs, DocumentData, QueryDocumentSnapshot, query, Query, where } from 'firebase/firestore';
// init
const firebaseApp = initializeApp(config.firebase.prod.app);
const firestore = getFirestore(firebaseApp);
const firestoreAuth = getAuth(firebaseApp);
signInWithEmailAndPassword(firestoreAuth, config.firebase.prod.user.email, config.firebase.prod.user.password);
const stripeAccountColl = collection(firestore, "StripeAccount");
// Function
private async getStripeAccount(): Promise<FirebaseStripeAccountIntf> {
try {
const q1: Query<DocumentData> = query(this.stripeAccountColl, where("JobNumber", "==", "ABC123"));
const querySnapshot: QuerySnapshot<DocumentData> = await getDocs(q1);
return new Promise((resolve, reject) => {
if (querySnapshot.size) {
querySnapshot.forEach((doc: QueryDocumentSnapshot<DocumentData>) => {
const data: any = doc.data();
if (this.debug) {
console.debug(`getStripeAccount >> data = ${JSON.stringify(data)}`);
}
resolve(data);
});
} else {
console.error(`getStripeAccount >> query returned no results`);
reject("query returned no results");
}
});
} catch (error: any) {
console.error(`getStripeAccount >> error = ${error}`);
throw new Error(error);
}
}