Created
July 9, 2022 16:14
-
-
Save santanaG/3794f8dd2f7c34b3d2a7da93264547d7 to your computer and use it in GitHub Desktop.
Another version of getUserByEmail as seen here: https://gajus.medium.com/how-would-you-reduce-nesting-in-this-example-http-gajus-com-blog-8-using-mysql-in-node-js-4c8c71c3a59d
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
const userQ = 'SELECT `id` FROM `user` WHERE `email` = ?' | |
const permissionsQ = 'SELECT `id`, `name` FROM `permission` WHERE `user_id` = ?' | |
const getUserbyEmail = (connection, email) => connection | |
.queryAsync(userQ, [email]) | |
.spread(user => user === undefined | |
? [{}, {}] | |
: Promise.all([user, connection.queryAsync(permissionsQ, [user.id])])) | |
.then(([user, permissions]) => ({ ...user, permissions })) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment