-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcustomerOptions.ts
77 lines (67 loc) · 3.19 KB
/
customerOptions.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { Customer } from "./customer.js";
import chalk from 'chalk';
import inquirer from "inquirer";
import { createSpinner } from "nanospinner";
const sleep = () => new Promise((r) => setTimeout(r, 2000))
export function DisplayInfo(customer: Customer) {
console.log(chalk.whiteBright(`--------------------------------------`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Name : `)} ${customer.name}`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Age : `)} ${customer.age}`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Contact Number : `)} ${customer.contactNumber}`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`UserID : `)} ${customer.userId}`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Account Balance : `)} RS: ${customer.bankAccount.accountBalance}`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Account Number : `)} ${customer.bankAccount.accountNumber}`))
console.log(chalk.whiteBright(`--------------------------------------`))
}
export function ShowAccountBalance(customer: Customer) {
console.log(chalk.whiteBright(`--------------------------------------`))
console.log(chalk.whiteBright(`${chalk.bgRgb(1, 59, 52)(`Account Balance : `)} RS: ${customer.bankAccount.accountBalance}`))
console.log(chalk.whiteBright(`--------------------------------------`))
}
export async function Credit(customer: Customer) {
while (true) {
const { amount } = await inquirer.prompt([{
name: 'amount',
message: 'Enter Amount : ',
type: 'number'
}])
let spinner = createSpinner('Processing').start()
await sleep()
if (!amount) {
spinner.error({ text: chalk.whiteBright.bgRedBright(` Enter Correct Amount`) })
continue
}
customer.bankAccount.Credit(amount)
spinner.success({ text: chalk.whiteBright.bgRgb(0, 125, 17)(`${amount > 100 ? 'Transaction Sccessful' : 'Transaction Sccessful And RS:1 Minus'} `) })
return
}
}
export async function Debit(customer: Customer) {
while (true) {
const { amount } = await inquirer.prompt([{
name: 'amount',
message: 'Enter Amount : ',
type: 'number'
}])
let spinner = createSpinner('Processing').start()
await sleep()
if (!amount) {
spinner.error({ text: chalk.whiteBright.bgRedBright(` Enter Correct Amount`) })
continue
}
if (amount > customer.bankAccount.accountBalance) {
spinner.error({ text: chalk.whiteBright.bgRedBright(` Amount is Greater than Your Balance`) })
return
}
customer.bankAccount.Debit(amount)
spinner.success({ text: chalk.whiteBright.bgRgb(0, 125, 17)(`Transaction Sccessful`) })
return
}
}
export function TransactionHistory(customer: Customer) {
if (!customer.bankAccount.transactionHistory.length) {
console.log(` No Transaction Available`)
return
}
console.table(customer.bankAccount.transactionHistory.map((val) => { return { ...val, fee: `RS: ${val.fee}`,amount:`RS: ${val.amount}` } }))
}