Skip to content

Instantly share code, notes, and snippets.

@GoodnessEzeokafor
Created February 17, 2022 09:47
Show Gist options
  • Save GoodnessEzeokafor/b94b7b0ecfc95d1b6406cd6fe4455580 to your computer and use it in GitHub Desktop.
Save GoodnessEzeokafor/b94b7b0ecfc95d1b6406cd6fe4455580 to your computer and use it in GitHub Desktop.
Firebase find query
type FilterQuery<T> = {
[K in keyof T]?: T[K]
};
static async findOne(field: FilterQuery<ITranslation>): Promise<any> {
try {
const results = await this.builder().where(Object.keys(field)[0], "==", Object.values(field)[0]).get();
if (results.length) {
return results[0];
}
return null;
} catch (e) {
return null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment