From ef17792dfce4bd99667103efe333b91737fb0375 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Wed, 13 Sep 2023 10:09:15 +0700 Subject: [PATCH 1/2] Fix naming, typo and bug --- javascript-practice/src/js/controllers/homeController.js | 6 +++--- .../src/js/controllers/registerController.js | 6 +++--- javascript-practice/src/js/helpers/helpers.js | 2 +- javascript-practice/src/js/services/commonService.js | 8 ++------ javascript-practice/src/js/services/firebaseService.js | 2 +- javascript-practice/src/js/services/userService.js | 2 +- javascript-practice/src/js/services/walletService.js | 6 +++--- .../src/js/views/commonLoginRegisterView.js | 6 +++--- javascript-practice/src/js/views/commonView.js | 8 ++++---- javascript-practice/src/js/views/homeView.js | 6 +++--- javascript-practice/src/js/views/registerView.js | 2 +- 11 files changed, 25 insertions(+), 29 deletions(-) diff --git a/javascript-practice/src/js/controllers/homeController.js b/javascript-practice/src/js/controllers/homeController.js index 7397d8c..fea87ec 100644 --- a/javascript-practice/src/js/controllers/homeController.js +++ b/javascript-practice/src/js/controllers/homeController.js @@ -8,8 +8,8 @@ export default class HomeController { return this.service.userService.getInfoUserLogin(); } - handlerCheckWalletExist(idUser) { - return this.service.walletService.checkWalletExist(idUser); + handlerCheckWalletValid(idUser) { + return this.service.walletService.isValidWallet(idUser); } handlerSaveWallet(wallet) { @@ -24,7 +24,7 @@ export default class HomeController { ); this.homeView.loadPage( this.handlerGetInfoUserLogin.bind(this), - this.handlerCheckWalletExist.bind(this), + this.handlerCheckWalletValid.bind(this), ); } } diff --git a/javascript-practice/src/js/controllers/registerController.js b/javascript-practice/src/js/controllers/registerController.js index 0722299..367688f 100644 --- a/javascript-practice/src/js/controllers/registerController.js +++ b/javascript-practice/src/js/controllers/registerController.js @@ -4,8 +4,8 @@ export default class RegisterController { this.service = service; } - handlerCheckUserExist(email) { - return this.service.userService.checkUserExist(email); + handlerCheckUserValid(email) { + return this.service.userService.isValidUser(email); } handlerSaveUser(user) { @@ -15,7 +15,7 @@ export default class RegisterController { init() { if (this.registerView) { this.registerView.addHandlerForm( - this.handlerCheckUserExist.bind(this), + this.handlerCheckUserValid.bind(this), this.handlerSaveUser.bind(this), ); this.registerView.addHandlerInputFormChange(); diff --git a/javascript-practice/src/js/helpers/helpers.js b/javascript-practice/src/js/helpers/helpers.js index 97b5146..a339bc9 100644 --- a/javascript-practice/src/js/helpers/helpers.js +++ b/javascript-practice/src/js/helpers/helpers.js @@ -7,7 +7,7 @@ import FirebaseService from '../services/firebaseService'; * @param {string} password Password input * @returns {boolean} Return true if validate password success, otherwise return false */ -export const validatePassword = (password) => { +export const isValidatePassword = (password) => { return REGEX.PASSWORD.test(password); }; diff --git a/javascript-practice/src/js/services/commonService.js b/javascript-practice/src/js/services/commonService.js index cce9cb5..ce4a698 100644 --- a/javascript-practice/src/js/services/commonService.js +++ b/javascript-practice/src/js/services/commonService.js @@ -20,12 +20,8 @@ export default class CommonService { async getDataFromProp(property, value, path = this.defaultPath) { this.connectToDb(); - const dataExists = this.firebaseService.getDataFromProp( - path, - property, - value, - ); - const result = await timeOutConnect(dataExists); + const data = this.firebaseService.getDataFromProp(path, property, value); + const result = await timeOutConnect(data); if (result.id && result.data) { return convertDataObjectToModel(result); diff --git a/javascript-practice/src/js/services/firebaseService.js b/javascript-practice/src/js/services/firebaseService.js index 80d2036..3f31092 100644 --- a/javascript-practice/src/js/services/firebaseService.js +++ b/javascript-practice/src/js/services/firebaseService.js @@ -22,7 +22,7 @@ class FirebaseService { * Save data in database * @param {Object} data The object need to save into database * @param {string} path The path of database need to be save - * @returns {Promise} Return the relsoves when write to database completed + * @returns {Promise} Return the resolves when write to database completed */ save(data, path) { return set(ref(this.db, path), data); diff --git a/javascript-practice/src/js/services/userService.js b/javascript-practice/src/js/services/userService.js index 6f53cda..5ea89e5 100644 --- a/javascript-practice/src/js/services/userService.js +++ b/javascript-practice/src/js/services/userService.js @@ -23,7 +23,7 @@ export default class UserService extends CommonService { * @param {string} email Email to find user * @returns {boolean} Return true if find, otherwise return false */ - async checkUserExist(email) { + async isValidUser(email) { const userExist = await this.getUserByEmail(email); if (userExist) { diff --git a/javascript-practice/src/js/services/walletService.js b/javascript-practice/src/js/services/walletService.js index 5331bcb..6a75545 100644 --- a/javascript-practice/src/js/services/walletService.js +++ b/javascript-practice/src/js/services/walletService.js @@ -20,10 +20,10 @@ export default class WalletService extends CommonService { * @param {string} idUser The id user to find user's wallet * @returns {boolean} Return true if find, otherwise return false */ - async checkWalletExist(idUser) { - const walletExist = await this.getWalletByIdUser(idUser); + async isValidWallet(idUser) { + const wallet = await this.getWalletByIdUser(idUser); - if (walletExist) { + if (wallet) { return true; } diff --git a/javascript-practice/src/js/views/commonLoginRegisterView.js b/javascript-practice/src/js/views/commonLoginRegisterView.js index 5003978..26cd045 100644 --- a/javascript-practice/src/js/views/commonLoginRegisterView.js +++ b/javascript-practice/src/js/views/commonLoginRegisterView.js @@ -1,6 +1,6 @@ import CommonView from './commonView'; import * as MESSAGE from '../constants/message'; -import { validatePassword } from '../helpers/helpers'; +import { isValidatePassword } from '../helpers/helpers'; export default class CommonLoginRegisterView extends CommonView { constructor() { @@ -19,9 +19,9 @@ export default class CommonLoginRegisterView extends CommonView { * @param {Object} account The account object with email, password, passwordConfirm field * @returns {boolean} Return true if validate success and return false if validate not success */ - validateForm(account) { + isValidateForm(account) { if (account.password === account.passwordConfirm) { - if (validatePassword(account.passwordConfirm)) { + if (isValidatePassword(account.passwordConfirm)) { return true; } this.showError(MESSAGE.PASSWORD_NOT_STRONG); diff --git a/javascript-practice/src/js/views/commonView.js b/javascript-practice/src/js/views/commonView.js index f329ae3..02bd595 100644 --- a/javascript-practice/src/js/views/commonView.js +++ b/javascript-practice/src/js/views/commonView.js @@ -56,13 +56,13 @@ export default class CommonView { */ initToastContent(typeToast, title, content, btnContent) { // Remove old typeToast class if haved - Object.keys(TYPE_TOAST).forEach((value) => { - CommonView.removeClassElement(value, this.toast); + Object.keys(TYPE_TOAST).forEach((key) => { + CommonView.removeClassElement(TYPE_TOAST[key], this.toast); }); // Remove old icon toast if haved - Object.keys(MARK_ICON).forEach((value) => { - CommonView.removeClassElement(value, this.toastIcon); + Object.keys(MARK_ICON).forEach((key) => { + CommonView.removeClassElement(MARK_ICON[key], this.toastIcon); }); // Init content toast diff --git a/javascript-practice/src/js/views/homeView.js b/javascript-practice/src/js/views/homeView.js index e55b283..62a8818 100644 --- a/javascript-practice/src/js/views/homeView.js +++ b/javascript-practice/src/js/views/homeView.js @@ -22,7 +22,7 @@ export default class HomeView extends CommonView { this.walletDialog = document.getElementById('walletDialog'); } - async loadPage(getInfoUserLogin, checkWalletExist) { + async loadPage(getInfoUserLogin, isValidWallet) { this.toggleLoaderSpinner(); const user = await getInfoUserLogin(); @@ -30,10 +30,10 @@ export default class HomeView extends CommonView { window.location.replace('/login'); } else { this.user = user; - const walletExist = await checkWalletExist(user.id); + const wallet = await isValidWallet(user.id); // Check user's wallet if have or not - if (!walletExist) { + if (!wallet) { // Show add wallet dialog this.walletDialog.showModal(); } else { diff --git a/javascript-practice/src/js/views/registerView.js b/javascript-practice/src/js/views/registerView.js index 327433d..1a0c0be 100644 --- a/javascript-practice/src/js/views/registerView.js +++ b/javascript-practice/src/js/views/registerView.js @@ -23,7 +23,7 @@ export default class RegisterView extends CommonLoginRegisterView { const account = { email, password, passwordConfirm }; - if (this.validateForm(account)) { + if (this.isValidateForm(account)) { const user = new User(account); return user; From a4a48f237aaa28067d78dd2023db43ceeec65985 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Wed, 13 Sep 2023 11:15:25 +0700 Subject: [PATCH 2/2] Fix naming variable and function --- .../src/js/views/commonLoginRegisterView.js | 2 +- javascript-practice/src/js/views/homeView.js | 8 ++++---- javascript-practice/src/js/views/registerView.js | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/javascript-practice/src/js/views/commonLoginRegisterView.js b/javascript-practice/src/js/views/commonLoginRegisterView.js index 26cd045..5a598a6 100644 --- a/javascript-practice/src/js/views/commonLoginRegisterView.js +++ b/javascript-practice/src/js/views/commonLoginRegisterView.js @@ -19,7 +19,7 @@ export default class CommonLoginRegisterView extends CommonView { * @param {Object} account The account object with email, password, passwordConfirm field * @returns {boolean} Return true if validate success and return false if validate not success */ - isValidateForm(account) { + isValidateAccount(account) { if (account.password === account.passwordConfirm) { if (isValidatePassword(account.passwordConfirm)) { return true; diff --git a/javascript-practice/src/js/views/homeView.js b/javascript-practice/src/js/views/homeView.js index 62a8818..fefc304 100644 --- a/javascript-practice/src/js/views/homeView.js +++ b/javascript-practice/src/js/views/homeView.js @@ -11,7 +11,7 @@ export default class HomeView extends CommonView { this.allContent = document.querySelectorAll('.app__content-item'); this.addTransactionBtn = document.getElementById('addTransaction'); this.addBudgetBtn = document.getElementById('addBudget'); - this.saveBtn = document.querySelectorAll('.form__save-btn'); + this.saveBtns = document.querySelectorAll('.form__save-btn'); this.dialogs = document.querySelectorAll('.dialog'); this.categoryField = document.getElementById('selectCategory'); this.closeIcon = document.querySelector('.close-icon'); @@ -84,12 +84,12 @@ export default class HomeView extends CommonView { validateWalletForm(bodyDialog) { this.walletName = bodyDialog.querySelector('.form__input-text').value; this.amount = bodyDialog.querySelector('.form__input-balance').value; - const saveBtn = bodyDialog.querySelector('.form__save-btn'); + const saveBtns = bodyDialog.querySelector('.form__save-btn'); if (this.walletName.length >= 3 && this.amount.length >= 1) { - saveBtn.classList.add('active'); + saveBtns.classList.add('active'); } else { - saveBtn.classList.remove('active'); + saveBtns.classList.remove('active'); } } diff --git a/javascript-practice/src/js/views/registerView.js b/javascript-practice/src/js/views/registerView.js index 1a0c0be..9d920f6 100644 --- a/javascript-practice/src/js/views/registerView.js +++ b/javascript-practice/src/js/views/registerView.js @@ -23,7 +23,7 @@ export default class RegisterView extends CommonLoginRegisterView { const account = { email, password, passwordConfirm }; - if (this.isValidateForm(account)) { + if (this.isValidateAccount(account)) { const user = new User(account); return user;