From 2dd9c23032f21fbb08bb28005ee0a823098846e1 Mon Sep 17 00:00:00 2001 From: Loi Phan Date: Mon, 2 Oct 2023 20:17:21 +0700 Subject: [PATCH] Fix bug and improve code --- typescript-practice/src/ts/app.ts | 10 +- .../src/ts/controllers/homeController.ts | 6 +- typescript-practice/src/ts/global/types.ts | 2 +- typescript-practice/src/ts/helpers/data.ts | 6 +- typescript-practice/src/ts/models/category.ts | 26 ++--- .../src/ts/models/transaction.ts | 6 +- typescript-practice/src/ts/models/user.ts | 45 ++------ typescript-practice/src/ts/models/wallet.ts | 6 +- .../src/ts/services/commonService.ts | 6 +- .../src/ts/services/firebaseService.ts | 28 ++--- .../src/ts/services/localStorageService.ts | 12 +-- .../src/ts/services/transactionService.ts | 8 +- .../src/ts/services/userService.ts | 12 +-- .../src/ts/services/walletService.ts | 9 +- .../src/ts/views/home/budgetView.ts | 4 +- .../src/ts/views/home/homeView.ts | 16 +-- .../src/ts/views/home/transactionTabView.ts | 6 +- .../src/ts/views/home/transactionView.ts | 14 +-- .../src/ts/views/home/walletView.ts | 101 +++++++++--------- .../src/ts/views/registerView.ts | 2 +- 20 files changed, 141 insertions(+), 184 deletions(-) diff --git a/typescript-practice/src/ts/app.ts b/typescript-practice/src/ts/app.ts index 4cb6089..aa120c1 100644 --- a/typescript-practice/src/ts/app.ts +++ b/typescript-practice/src/ts/app.ts @@ -3,15 +3,15 @@ import Service from './services/index'; import View from './views/index'; export default class App { - private _controller: Controller; + controller: Controller; constructor() { - this._controller = new Controller(new Service(), new View()); + this.controller = new Controller(new Service(), new View()); } start() { - this._controller.registerController.init(); - this._controller.loginController.init(); - this._controller.homeController.init(); + this.controller.registerController.init(); + this.controller.loginController.init(); + this.controller.homeController.init(); } } diff --git a/typescript-practice/src/ts/controllers/homeController.ts b/typescript-practice/src/ts/controllers/homeController.ts index ba2f180..8388e76 100644 --- a/typescript-practice/src/ts/controllers/homeController.ts +++ b/typescript-practice/src/ts/controllers/homeController.ts @@ -21,7 +21,7 @@ export default class HomeController { return this.service.userService.getInfoUserLogin(); } - handlerGetWalletByIdUser(idUser: number): Promise { + handlerGetWalletByIdUser(idUser: string): Promise { return this.service.walletService.getWalletByIdUser(idUser); } @@ -37,11 +37,11 @@ export default class HomeController { return this.service.categoryService.getAllCategory(); } - handlerGetAllTransactions(idUser: number): Promise { + handlerGetAllTransactions(idUser: string): Promise { return this.service.transactionService.getListTransactionByIdUser(idUser); } - handlerDeleteTransaction(idTransaction: number): Promise { + handlerDeleteTransaction(idTransaction: string): Promise { return this.service.transactionService.deleteTransaction(idTransaction); } diff --git a/typescript-practice/src/ts/global/types.ts b/typescript-practice/src/ts/global/types.ts index 53aba9c..98350cb 100644 --- a/typescript-practice/src/ts/global/types.ts +++ b/typescript-practice/src/ts/global/types.ts @@ -48,7 +48,7 @@ export interface Data { } export interface ItemTransaction { - id: number; + id: string; day: string; fullDateString: string; note: string; diff --git a/typescript-practice/src/ts/helpers/data.ts b/typescript-practice/src/ts/helpers/data.ts index 297e20e..ed9759f 100644 --- a/typescript-practice/src/ts/helpers/data.ts +++ b/typescript-practice/src/ts/helpers/data.ts @@ -5,8 +5,8 @@ import Transaction from 'models/transaction'; import TransactionDetail from 'models/transactionDetail'; import Category from 'models/category'; -export const generateId = (): number => { - return new Date().getTime(); +export const generateId = (): string => { + return new Date().getTime().toString(); }; export const convertDataObjectToModel = (dataObj: DataObject): T => { @@ -110,7 +110,7 @@ export const createTransactionDetailObject = ( return tempData; }); - results.sort((a, b) => b.id - a.id); + results.sort((a, b) => parseInt(b.id) - parseInt(a.id)); return results; }; diff --git a/typescript-practice/src/ts/models/category.ts b/typescript-practice/src/ts/models/category.ts index e82b366..71988bb 100644 --- a/typescript-practice/src/ts/models/category.ts +++ b/typescript-practice/src/ts/models/category.ts @@ -1,25 +1,13 @@ export default class Category { - private readonly _id: number; + readonly id: string; - private _url: string; + url: string; - private _name: string; + name: string; - constructor(id: number, url: string, name: string) { - this._id = id; - this._url = url; - this._name = name; - } - - get id() { - return this._id; - } - - get url() { - return this._url; - } - - get name() { - return this._name; + constructor(id: string, url: string, name: string) { + this.id = id; + this.url = url; + this.name = name; } } diff --git a/typescript-practice/src/ts/models/transaction.ts b/typescript-practice/src/ts/models/transaction.ts index 33f9a34..339b4b8 100644 --- a/typescript-practice/src/ts/models/transaction.ts +++ b/typescript-practice/src/ts/models/transaction.ts @@ -2,14 +2,14 @@ import { generateId } from 'helpers/data'; export default class Transaction { constructor( - public id: number, + public id: string, public categoryName: string, public date: string, public note: string, public amount: number, - public idUser: number, + public idUser: string, ) { - this.id = id !== 0 ? id : generateId(); + this.id = id ? id : generateId(); this.categoryName = categoryName; this.date = date; this.note = note; diff --git a/typescript-practice/src/ts/models/user.ts b/typescript-practice/src/ts/models/user.ts index 66b92bb..9b2fa4c 100644 --- a/typescript-practice/src/ts/models/user.ts +++ b/typescript-practice/src/ts/models/user.ts @@ -1,47 +1,18 @@ import { generateId } from '../helpers/data'; export default class User { - private readonly _id: number; + id: string; - private _email: string; + email: string; - private _password: string; + password: string; - private _accessToken: string; + accessToken: string; constructor(email: string, password: string, accessToken?: string) { - this._id = generateId(); - this._email = email; - this._password = password || ''; - this._accessToken = accessToken || ''; - } - - get password() { - return this._password; - } - - set accessToken(accessToken: string) { - this._accessToken = accessToken; - } - - get accessToken() { - return this._accessToken; - } - - get email() { - return this._email; - } - - get id() { - return this._id; - } - - get toObject() { - return { - id: this._id, - email: this._email, - password: this._password, - accessToken: this.accessToken, - } as User; + this.id = generateId(); + this.email = email; + this.password = password || ''; + this.accessToken = accessToken || ''; } } diff --git a/typescript-practice/src/ts/models/wallet.ts b/typescript-practice/src/ts/models/wallet.ts index 88002be..7e0e1a9 100644 --- a/typescript-practice/src/ts/models/wallet.ts +++ b/typescript-practice/src/ts/models/wallet.ts @@ -1,7 +1,7 @@ import { generateId } from '../helpers/data'; export default class Wallet { - id: number; + id: string; walletName: string; @@ -9,13 +9,13 @@ export default class Wallet { outflow: number; - idUser: number; + idUser: string; constructor( walletName: string, inflow: number, outflow: number, - idUser: number, + idUser: string, ) { this.id = generateId(); this.walletName = walletName; diff --git a/typescript-practice/src/ts/services/commonService.ts b/typescript-practice/src/ts/services/commonService.ts index 3c8dd9d..1c0a36c 100644 --- a/typescript-practice/src/ts/services/commonService.ts +++ b/typescript-practice/src/ts/services/commonService.ts @@ -68,7 +68,7 @@ export default class CommonService { ) { this.connectToDb(); const data = this.firebaseService.getDataFromProp(path, property, value); - const result = (await timeOutConnect(data)) as DataObject; + const result = >await timeOutConnect(data); if (result && typeof result === 'object') { return convertDataObjectToModel(result); @@ -98,7 +98,7 @@ export default class CommonService { async getListDataFromProp( property: string, - value: string, + value: string | number, path: string = this.defaultPath, ): Promise { this.connectToDb(); @@ -121,7 +121,7 @@ export default class CommonService { } async deleteData( - id: number, + id: string, path = this.defaultPath, ): Promise { this.connectToDb(); diff --git a/typescript-practice/src/ts/services/firebaseService.ts b/typescript-practice/src/ts/services/firebaseService.ts index f6034d4..32557a9 100644 --- a/typescript-practice/src/ts/services/firebaseService.ts +++ b/typescript-practice/src/ts/services/firebaseService.ts @@ -12,16 +12,16 @@ import { import { DATABASE_URL } from '../constants/config'; class FirebaseService { - private _app: FirebaseApp; + app: FirebaseApp; - private _db: Database; + db: Database; constructor() { const firebaseConfig = { databaseURL: DATABASE_URL, }; - this._app = initializeApp(firebaseConfig); - this._db = getDatabase(this._app); + this.app = initializeApp(firebaseConfig); + this.db = getDatabase(this.app); } /** @@ -31,25 +31,25 @@ class FirebaseService { * @returns {Promise} Return the resolves when write to database completed */ save(data: object, path: string): Promise { - return set(ref(this._db, path), data); + return set(ref(this.db, path), data); } - delete(id: number, path: string): Promise { - return remove(ref(this._db, path + id)); + delete(id: string, path: string): Promise { + return remove(ref(this.db, path + id)); } /** * Disconnect to database */ disconnect(): void { - goOffline(this._db); + goOffline(this.db); } /** * Reconnect to database */ reconnect(): void { - goOnline(this._db); + goOnline(this.db); } /** @@ -66,7 +66,7 @@ class FirebaseService { ): Promise { return new Promise((resolve) => { onValue( - ref(this._db, path), + ref(this.db, path), (snapshot) => { let id: string | null = null; let data: object | null = null; @@ -104,7 +104,7 @@ class FirebaseService { getDataFromId(id: string, path: string): Promise { return new Promise((resolve) => { onValue( - ref(this._db, path + id), + ref(this.db, path + id), (snapshot) => { resolve(snapshot.val()); }, @@ -118,7 +118,7 @@ class FirebaseService { getAllDataFromPath(path: string): Promise { return new Promise((resolve) => { onValue( - ref(this._db, path), + ref(this.db, path), (snapshot) => { const listData: object[] = []; @@ -145,11 +145,11 @@ class FirebaseService { getListDataFromProp( path: string, property: string, - value: string, + value: string | number, ): Promise { return new Promise((resolve) => { onValue( - ref(this._db, path), + ref(this.db, path), (snapshot) => { let id: string; let data: object; diff --git a/typescript-practice/src/ts/services/localStorageService.ts b/typescript-practice/src/ts/services/localStorageService.ts index 9ef2187..5786cd5 100644 --- a/typescript-practice/src/ts/services/localStorageService.ts +++ b/typescript-practice/src/ts/services/localStorageService.ts @@ -1,24 +1,24 @@ class LocalStorageService { - private _localStorage: Storage; + localStorage: Storage; constructor() { - this._localStorage = localStorage; + this.localStorage = localStorage; } add(key: string, value: string): void { - this._localStorage.setItem(key, value); + this.localStorage.setItem(key, value); } get(key: string): string | null { - return this._localStorage.getItem(key); + return this.localStorage.getItem(key); } remove(key: string): void { - this._localStorage.removeItem(key); + this.localStorage.removeItem(key); } clear(): void { - this._localStorage.clear(); + this.localStorage.clear(); } } diff --git a/typescript-practice/src/ts/services/transactionService.ts b/typescript-practice/src/ts/services/transactionService.ts index 7743e16..bb53cf9 100644 --- a/typescript-practice/src/ts/services/transactionService.ts +++ b/typescript-practice/src/ts/services/transactionService.ts @@ -17,18 +17,18 @@ export default class TransactionService extends CommonService { } async getListTransactionByIdUser( - idUser: number, + idUser: string, ): Promise { - const results = this.getListDataFromProp( + const results = await this.getListDataFromProp( 'idUser', - idUser.toString(), + idUser, this.defaultPath, ); return results || null; } - async deleteTransaction(idTransaction: number) { + async deleteTransaction(idTransaction: string) { await this.deleteData(idTransaction); } } diff --git a/typescript-practice/src/ts/services/userService.ts b/typescript-practice/src/ts/services/userService.ts index 3051f9d..42729ed 100644 --- a/typescript-practice/src/ts/services/userService.ts +++ b/typescript-practice/src/ts/services/userService.ts @@ -5,10 +5,10 @@ import CommonService from './commonService'; import LocalStorageService from './localStorageService'; export default class UserService { - private _commonService: CommonService; + private commonService: CommonService; constructor() { - this._commonService = new CommonService('users/'); + this.commonService = new CommonService('users/'); } /** @@ -16,7 +16,7 @@ export default class UserService { * @param {Object} user The user object need to be saved into database */ async saveUser(user: User): Promise { - await this._commonService.save(user); + await this.commonService.save(user); } /** @@ -36,7 +36,7 @@ export default class UserService { * @returns {Object || null} Return new User Object if find, otherwise return null. */ async getUserByEmail(email: string): Promise { - const result = await this._commonService.getDataFromProp('email', email); + const result = await this.commonService.getDataFromProp('email', email); return result || null; } @@ -73,7 +73,7 @@ export default class UserService { // Add token to user object newUserData.accessToken = createToken(); - this._commonService.save(newUserData); + this.commonService.save(newUserData); // Add access token to local storage LocalStorageService.add( @@ -102,7 +102,7 @@ export default class UserService { * @returns {Object || null} Return new User Object if find, otherwise return null. */ async getUserByToken(accessToken: string): Promise { - const result = await this._commonService.getDataFromProp( + const result = await this.commonService.getDataFromProp( 'accessToken', accessToken, ); diff --git a/typescript-practice/src/ts/services/walletService.ts b/typescript-practice/src/ts/services/walletService.ts index dbb2f50..c84a90b 100644 --- a/typescript-practice/src/ts/services/walletService.ts +++ b/typescript-practice/src/ts/services/walletService.ts @@ -21,7 +21,7 @@ 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 isValidWallet(idUser: number): Promise { + async isValidWallet(idUser: string): Promise { const wallet = await this.getWalletByIdUser(idUser); return !!wallet; @@ -32,11 +32,8 @@ export default class WalletService extends CommonService { * @param {string} email The id user to find user's wallet * @returns {Object || null} Return new Wallet Object if find, otherwise return null. */ - async getWalletByIdUser(idUser: number): Promise { - const result = (await this.getDataFromProp( - 'idUser', - idUser.toString(), - )) as Wallet; + async getWalletByIdUser(idUser: string): Promise { + const result = (await this.getDataFromProp('idUser', idUser)) as Wallet; return result || null; } diff --git a/typescript-practice/src/ts/views/home/budgetView.ts b/typescript-practice/src/ts/views/home/budgetView.ts index ab062e1..425fca8 100644 --- a/typescript-practice/src/ts/views/home/budgetView.ts +++ b/typescript-practice/src/ts/views/home/budgetView.ts @@ -125,12 +125,12 @@ export default class BudgetView { this.budgetDialog!.close(); // Close dialog const transaction = new Transaction( - 0, + '', DEFAULT_CATEGORY.INCOME, date, note, +amount, - +this.wallet!.idUser, + this.wallet!.idUser, ); await this.saveTransaction!(transaction); diff --git a/typescript-practice/src/ts/views/home/homeView.ts b/typescript-practice/src/ts/views/home/homeView.ts index 5a457fe..518a0fd 100644 --- a/typescript-practice/src/ts/views/home/homeView.ts +++ b/typescript-practice/src/ts/views/home/homeView.ts @@ -51,15 +51,15 @@ export default class HomeView extends CommonView { getInfoUserLogin: (() => Promise) | null = null; - getWalletByIdUser: ((idUser: number) => Promise) | null = null; + getWalletByIdUser: ((idUser: string) => Promise) | null = null; getAllCategory: (() => Promise) | null = null; getAllTransactions: - | ((idUser: number) => Promise) + | ((idUser: string) => Promise) | null = null; - deleteTransaction: ((idTransaction: number) => Promise) | null = null; + deleteTransaction: ((idTransaction: string) => Promise) | null = null; saveWallet: ((wallet: Wallet) => Promise) | null = null; @@ -91,12 +91,12 @@ export default class HomeView extends CommonView { initFunction( getInfoUserLogin: () => Promise, - getWalletByIdUser: (idUser: number) => Promise, + getWalletByIdUser: (idUser: string) => Promise, getAllCategory: () => Promise, - getAllTransactions: (idUser: number) => Promise, + getAllTransactions: (idUser: string) => Promise, saveWallet: (wallet: Wallet) => Promise, saveTransaction: (transaction: Transaction) => Promise, - deleteTransaction: (idTransaction: number) => Promise, + deleteTransaction: (idTransaction: string) => Promise, transform: Transform, ) { this.getInfoUserLogin = getInfoUserLogin; @@ -191,6 +191,8 @@ export default class HomeView extends CommonView { this.summaryTabView.load(); this.transactionTabView.loadTransactionTab(); + + await this.updateAmountWallet(); } async loadPage() { @@ -204,7 +206,7 @@ export default class HomeView extends CommonView { } else { // If user already login this.user = user; - this.wallet = await this.getWalletByIdUser!(user.id); + this.wallet = await this.getWalletByIdUser!(user.id); this.sendData(); // Check user's wallet if have or not diff --git a/typescript-practice/src/ts/views/home/transactionTabView.ts b/typescript-practice/src/ts/views/home/transactionTabView.ts index 594d1c4..b39e265 100644 --- a/typescript-practice/src/ts/views/home/transactionTabView.ts +++ b/typescript-practice/src/ts/views/home/transactionTabView.ts @@ -92,7 +92,9 @@ export default class TransactionTabView { }, ); - tempList.sort((a, b) => b.transactions[0].id - a.transactions[0].id); + tempList.sort( + (a, b) => parseInt(b.transactions[0].id) - parseInt(a.transactions[0].id), + ); return tempList; } @@ -176,7 +178,7 @@ export default class TransactionTabView { )!; if (transactionTime) { - const idTransaction = +(transactionTime).dataset.id!; + const idTransaction = (transactionTime).dataset.id!; // If it is income transaction, don't show dialog if ( diff --git a/typescript-practice/src/ts/views/home/transactionView.ts b/typescript-practice/src/ts/views/home/transactionView.ts index 80e97d1..81122b2 100644 --- a/typescript-practice/src/ts/views/home/transactionView.ts +++ b/typescript-practice/src/ts/views/home/transactionView.ts @@ -29,7 +29,7 @@ export default class TransactionView { toggleLoaderSpinner: (() => void) | null = null; - deleteTransaction: ((idTransaction: number) => Promise) | null = null; + deleteTransaction: ((idTransaction: string) => Promise) | null = null; loadTransactionData: (() => Promise) | null = null; @@ -61,7 +61,7 @@ export default class TransactionView { initFunction( toggleLoaderSpinner: () => void, - deleteTransaction: (idTransaction: number) => Promise, + deleteTransaction: (idTransaction: string) => Promise, loadTransactionData: () => Promise, updateAmountWallet: () => Promise, loadData: () => Promise, @@ -165,7 +165,7 @@ export default class TransactionView { this.transactionDialog!.close(); this.toggleLoaderSpinner!(); - await this.deleteTransaction!(+idEl.value); + await this.deleteTransaction!(idEl.value); // Reload data await this.loadTransactionData!(); @@ -199,7 +199,7 @@ export default class TransactionView { ); } - initValueTransactionDialog(idTransaction: number | null) { + initValueTransactionDialog(idTransaction: string | null) { let categoryName: string; if (idTransaction) { @@ -281,12 +281,12 @@ export default class TransactionView { this.transactionDialog!.close(); const transaction = new Transaction( - +idEl.value, + idEl.value, categoryNameEl.value, dateEl.value, noteEl.value, +amount, - +this.wallet!.idUser, + this.wallet!.idUser, ); await this.saveTransaction!(transaction); @@ -353,7 +353,7 @@ export default class TransactionView { this.transactionForm!.reset(); } - showTransactionDialog(idTransaction: number | null = null) { + showTransactionDialog(idTransaction: string | null = null) { this.clearInputTransactionForm(); // Init data transaction to dialog diff --git a/typescript-practice/src/ts/views/home/walletView.ts b/typescript-practice/src/ts/views/home/walletView.ts index 26c1795..f5dd34e 100644 --- a/typescript-practice/src/ts/views/home/walletView.ts +++ b/typescript-practice/src/ts/views/home/walletView.ts @@ -8,35 +8,32 @@ import { FIRST_ADD_WALLET_NOTE } from 'constants/defaultVariable'; import { ADD_WALLET_SUCCESS, DEFAULT_MESSAGE } from 'constants/messages/dialog'; export default class WalletView { - private _walletDialog: HTMLDialogElement | null = null; + walletDialog: HTMLDialogElement | null = null; - private _transform: Transform | null = null; + transform: Transform | null = null; - private _toggleLoaderSpinner: (() => void) | null = null; + toggleLoaderSpinner: (() => void) | null = null; - private _saveWallet: ((wallet: Wallet) => Promise) | null = null; + saveWallet: ((wallet: Wallet) => Promise) | null = null; - private _saveTransaction: - | ((transaction: Transaction) => Promise) - | null = null; + saveTransaction: ((transaction: Transaction) => Promise) | null = null; - private _loadTransactionData: (() => Promise) | null = null; + loadTransactionData: (() => Promise) | null = null; - private _loadData: (() => Promise) | null = null; + loadData: (() => Promise) | null = null; - private _loadEvent: (() => void) | null = null; + loadEvent: (() => void) | null = null; - private _showSuccessToast: ((title: string, message: string) => void) | null = - null; + showSuccessToast: ((title: string, message: string) => void) | null = null; - private _showErrorToast: ((error: string | TError) => void) | null = null; + showErrorToast: ((error: string | TError) => void) | null = null; - private _user: User | null = null; + user: User | null = null; - private _wallet: Wallet | null = null; + wallet: Wallet | null = null; constructor() { - this._walletDialog = document.getElementById( + this.walletDialog = document.getElementById( 'walletDialog', ) as HTMLDialogElement; @@ -54,49 +51,49 @@ export default class WalletView { showSuccessToast: (title: string, message: string) => void, showErrorToast: (error: string | TError) => void, ) { - this._transform = transform; - this._toggleLoaderSpinner = toggleLoaderSpinner; - this._saveWallet = saveWallet; - this._saveTransaction = saveTransaction; - this._loadTransactionData = loadTransactionData; - this._loadData = loadData; - this._loadEvent = loadEvent; - this._showSuccessToast = showSuccessToast; - this._showErrorToast = showErrorToast; + this.transform = transform; + this.toggleLoaderSpinner = toggleLoaderSpinner; + this.saveWallet = saveWallet; + this.saveTransaction = saveTransaction; + this.loadTransactionData = loadTransactionData; + this.loadData = loadData; + this.loadEvent = loadEvent; + this.showSuccessToast = showSuccessToast; + this.showErrorToast = showErrorToast; } subscribe() { - this._transform!.create('walletView', this.updateData.bind(this)); + this.transform!.create('walletView', this.updateData.bind(this)); } sendData() { const data = { - wallet: this._wallet!, - user: this._user!, + wallet: this.wallet!, + user: this.user!, }; - this._transform!.onSendSignal('walletView', data); + this.transform!.onSendSignal('walletView', data); } updateData(data: Data) { - if (data.wallet) this._wallet = data.wallet; + if (data.wallet) this.wallet = data.wallet; - if (data.user) this._user = data.user; + if (data.user) this.user = data.user; } showDialog() { - this._walletDialog!.showModal(); + this.walletDialog!.showModal(); } addHandlerEventWalletForm() { - this._walletDialog!.addEventListener('submit', (e) => { + this.walletDialog!.addEventListener('submit', (e) => { e.preventDefault(); this.clearErrorStyleWalletDialog(); this.submitWalletForm(); }); - this._walletDialog!.addEventListener('input', (e) => { + this.walletDialog!.addEventListener('input', (e) => { const bodyDialog = (e.target!).closest('.dialog__body'); this.changeBtnStyleWalletDialog(bodyDialog!); @@ -106,8 +103,8 @@ export default class WalletView { clearErrorStyleWalletDialog() { const inputFieldEls = - this._walletDialog!.querySelectorAll('.form__input-field'); - const errorTextEls = this._walletDialog!.querySelectorAll('.error-text'); + this.walletDialog!.querySelectorAll('.form__input-field'); + const errorTextEls = this.walletDialog!.querySelectorAll('.error-text'); inputFieldEls.forEach((item) => { if (item.classList.contains('error-input')) @@ -128,45 +125,45 @@ export default class WalletView { const amount = walletForm.get('amount') as string; if (this.validateWalletDialog(walletName, +amount)) { - this._walletDialog!.close(); - this._toggleLoaderSpinner!(); + this.walletDialog!.close(); + this.toggleLoaderSpinner!(); - const wallet = new Wallet(walletName, +amount, 0, this._user!.id); - this._wallet = wallet; + const wallet = new Wallet(walletName, +amount, 0, this.user!.id); + this.wallet = wallet; this.sendData(); - await this._saveWallet!(wallet); + await this.saveWallet!(wallet); // Transaction info const transaction = new Transaction( - 0, + '', 'Income', new Date().toISOString().slice(0, 10), FIRST_ADD_WALLET_NOTE, +amount, - this._user!.id, + this.user!.id, ); - await this._saveTransaction!(transaction); + await this.saveTransaction!(transaction); // Load data and event - await this._loadTransactionData!(); - await this._loadData!(); - this._loadEvent!(); + await this.loadTransactionData!(); + await this.loadData!(); + this.loadEvent!(); - this._showSuccessToast!(ADD_WALLET_SUCCESS, DEFAULT_MESSAGE); + this.showSuccessToast!(ADD_WALLET_SUCCESS, DEFAULT_MESSAGE); - this._toggleLoaderSpinner!(); + this.toggleLoaderSpinner!(); } } catch (error) { // Show toast error - this._showErrorToast!(error as string | TError); - this._toggleLoaderSpinner!(); + this.showErrorToast!(error as string | TError); + this.toggleLoaderSpinner!(); } } validateWalletDialog(walletName: string, amount: number) { const inputFieldEls = - this._walletDialog!.querySelectorAll('.form__input-field'); + this.walletDialog!.querySelectorAll('.form__input-field'); if (!walletName || !amount) { if (!walletName) { diff --git a/typescript-practice/src/ts/views/registerView.ts b/typescript-practice/src/ts/views/registerView.ts index 98c141f..f60d587 100644 --- a/typescript-practice/src/ts/views/registerView.ts +++ b/typescript-practice/src/ts/views/registerView.ts @@ -152,7 +152,7 @@ export default class RegisterView extends AuthenticationView { if (userExist) { throw Error(USER_EXIST_ERROR); } else { - await saveUser(user.toObject); + await saveUser(user); // Show toast success this.showRegisterSuccessToast();