From ed00a64310a866d41d97f9141bde6992db4dfed6 Mon Sep 17 00:00:00 2001 From: devcorpio Date: Sun, 31 Mar 2019 20:12:54 +0200 Subject: [PATCH] chapter 05: authentication is not depending in connection anymore, now depends in an abstraction --- .../{userProvider.js => MySQLUserProvider.js} | 7 +++++-- .../refactor/authentication.js | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) rename chapter-05-the-dependency-inversion-principle/refactor/{userProvider.js => MySQLUserProvider.js} (61%) diff --git a/chapter-05-the-dependency-inversion-principle/refactor/userProvider.js b/chapter-05-the-dependency-inversion-principle/refactor/MySQLUserProvider.js similarity index 61% rename from chapter-05-the-dependency-inversion-principle/refactor/userProvider.js rename to chapter-05-the-dependency-inversion-principle/refactor/MySQLUserProvider.js index 256b284..0f04003 100644 --- a/chapter-05-the-dependency-inversion-principle/refactor/userProvider.js +++ b/chapter-05-the-dependency-inversion-principle/refactor/MySQLUserProvider.js @@ -1,4 +1,7 @@ -function userProvider(connection) { +/** + * @implements {UserProviderInterface} + */ +function mysqlUserProvider(connection) { function findUser(username) { return connection.fetchAssoc('SELECT * FROM users WHERE username = ?', [ username, @@ -10,4 +13,4 @@ function userProvider(connection) { }; } -module.exports = userProvider; +module.exports = mysqlUserProvider; diff --git a/chapter-05-the-dependency-inversion-principle/refactor/authentication.js b/chapter-05-the-dependency-inversion-principle/refactor/authentication.js index c1104cf..0b4a8ed 100644 --- a/chapter-05-the-dependency-inversion-principle/refactor/authentication.js +++ b/chapter-05-the-dependency-inversion-principle/refactor/authentication.js @@ -1,3 +1,16 @@ +/** + * In order to improve the understanding of this code, this file it is supposing to implement the following interface: + * + * interface UserProviderInterface { + * function findUser(username); + * } + * + * Quack Quack Quack 🦆 typing :D + */ + +/** + * @param {UserProviderInterface} userProvider + */ function authentication(userProvider) { function checkCredentials(username, password) { const user = userProvider.findUser(username);