Last active
November 22, 2019 14:08
-
-
Save nwaughachukwuma/28e1cb7760ce7c971a26574e71b43aa1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Firestore now supports a where-in query on the admin SDK | |
*/ | |
import admin from "../admin" // pre-initialised | |
// Instead of this | |
async function hasUserTraveledTo(listOfStates, userId) { | |
for (const state in listOfStates) { | |
const userHasTraveledTo = await admin.firestore().collection(`users/${userId}/travelDestinations`) | |
.where('state', '==', state) | |
.get() | |
if (!userHasTraveledTo.empty) { | |
return true | |
} | |
} | |
return false; | |
} | |
// Use this | |
async function hasUserTraveledTo(listOfStates, userId) { | |
const userHasTraveledTo = await admin.firestore().collection(`users/${userId}/travelDestinations`) | |
.where('state', 'in', listOfStates) | |
.get() | |
if (!userHasTraveledTo.empty) { | |
return true | |
} | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment