本文整理汇总了TypeScript中@google-cloud/firestore.CollectionReference.where方法的典型用法代码示例。如果您正苦于以下问题:TypeScript CollectionReference.where方法的具体用法?TypeScript CollectionReference.where怎么用?TypeScript CollectionReference.where使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@google-cloud/firestore.CollectionReference
的用法示例。
在下文中一共展示了CollectionReference.where方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: queryCurrentSubscriptions
/*
* Query subscriptions registered to a particular user, that are either active or in account hold.
* Note: Other subscriptions which don't meet the above criteria still exists in Firestore purchase records, but not accessible from outside of the library.
*/
async queryCurrentSubscriptions(userId: string, sku?: string, packageName?: string): Promise<Array<SubscriptionPurchase>> {
const purchaseList = new Array<SubscriptionPurchase>();
try {
// Create query to fetch possibly active subscriptions from Firestore
let query = this.purchasesDbRef
.where('formOfPayment', '==', GOOGLE_PLAY_FORM_OF_PAYMENT)
.where('skuType', '==', SkuType.SUBS)
.where('userId', '==', userId)
.where('isMutable', '==', true)
if (sku) {
query = query.where('sku', '==', sku);
}
if (packageName) {
query = query.where('packageName', '==', packageName);
}
// Do fetch possibly active subscription from Firestore
const queryResult = await query.get();
// Loop through these subscriptions and filter those that are indeed active
for (const purchaseRecordSnapshot of queryResult.docs) {
let purchase: SubscriptionPurchase = SubscriptionPurchaseImpl.fromFirestoreObject(purchaseRecordSnapshot.data())
if (!purchase.isEntitlementActive() && !purchase.isAccountHold()) {
// If a subscription purchase record in Firestore indicates says that it has expired,
// and we haven't confirmed that it's in Account Hold,
// and we know that its status could have been changed since we last fetch its details,
// then we should query Play Developer API to get its latest status
console.log('Updating cached purchase record for token = ', purchase.purchaseToken);
purchase = await this.purchaseManager.querySubscriptionPurchase(purchase.packageName, purchase.sku, purchase.purchaseToken);
}
// Add the updated purchase to list to returned to clients
if (purchase.isEntitlementActive() || purchase.isAccountHold()) {
purchaseList.push(purchase);
}
}
return purchaseList;
} catch (err) {
console.error('Error querying purchase records from Firestore. \n', err.message);
const libraryError = new Error(err.message);
libraryError.name = PurchaseQueryError.OTHER_ERROR;
throw libraryError;
}
}