Untitled
// <!-- Design a in memory Bank Account Service catering to the following needs // * Create Bank Account // * Add Money // * Withdraw Money // * Send Money // * Block Money // * Release Money --> // ledger? // multiple account? -> send money // data = { // money, // acoountNumber, // id, // name, // age, // gender // address // status? // } class BankAccount { constructor() { // this.account = {} this.ledger = {} } createAccount(data) { if(!data.email) { // more error condition on mandotory keys console.log("Cannot be empty"); } const ac = 'AC000' + parseInt(Date.now()); this.account[ac] = { money: data.money || 0, email: data.email, accountNumber: ac, name: data.name, status: 'Active' } let transaction = { createdAt: Date.now(), type: 'Credit',// logic amount: data.money || 0 } this.account[ac].ledger = [transaction] return this.account[ac]; } withdrawAccount(amount, selfAccountNumber) { // basic validation null, empty\ if(this.account[selfAccountNumber].money < amount) { console.log('error canot be greather than'); // throw new console.error(''); } else { this.account[selfAccountNumber].money = this.account[selfAccountNumber].money - amount; let transaction = { createdAt: Date.now(), type: 'Debit',// logic amount: amount } this.account[selfAccountNumber].ledger.push(transaction) } return this.account[selfAccountNumber]; } transferMoney(amount, selfAccountNumber, payeeAccountNumber) { } } const data = { money: 1000, email: "some@MediaList.com", name: "Hulk" } const account = new BankAccount(); const selfAccount = account.createAccount(data); console.log('creating account, ', selfAccount); console.log('withdrawn, ', account.withdrawAccount(2000, selfAccount.accountNumber));
Leave a Comment