Created
February 17, 2022 09:47
-
-
Save GoodnessEzeokafor/b94b7b0ecfc95d1b6406cd6fe4455580 to your computer and use it in GitHub Desktop.
Firebase find query
This file contains 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
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