@sss2sssss/bank_cli
v1.0.1
Published
bank cli demo
Downloads
4
Readme
Simple Bank CLI developed by using commander, sqlite, and bcrypt (for password authentication) with Node.js.
It allow user to type bank command on command prompt without have any active windows need to run with.
Before Start
You will need to download and install Node.js first before running the code. The link to download is on below: https://nodejs.org/en/download/
After download the installer, double click and follow the instruction to complete.
Then download the project zip file, extract it and went to the root of project folder (where you can see index.js at there), open terminal/ command prompt and type following script command to initiate project: npm run first-initiate
Available Scripts
In the project directory, you can run:
npm run first-initiate
This script command helps you to install all the node modules that's required to run. And make the cli available to global environment.
Database
In this project, SQLite is used for any transaction and user logging. The database named bank.db will auto created if any command is fired up and there's no database exists.
Table(s)
Here are the list of table been used and column defined
user
- id (INTEGER, PRIMARY KEY, AUTO INCREMENTAL, index id)
- name (TEXT, NOT NULL, user name)
- passwordHashed (TEXT NOT NULL, password hashed by bcrypt)
- status (TEXT NOT NULL, user status ['Online', 'Offline'])
- totalAmountAvailable (TEXT NOT NULL, current available amount)
debtTransaction
- id (INTEGER, PRIMARY KEY, AUTO INCREMENTAL, index id)
- performUserId (INTEGER, NOT NULL, own from person id)
- toUserId (INTEGER NOT NULL, own to person id)
- debtAmount (TEXT NOT NULL, debt amount)
- lastUpdateTimestamp (TEXT NOT NULL, last update timestamp by ISO string with GMT timezone)
transactionLog
- id (INTEGER, PRIMARY KEY, AUTO INCREMENTAL, index id)
- performUserId (INTEGER, NOT NULL, person id to view the log)
- event (TEXT NOT NULL, event detail)
- transactionTimestamp (TEXT NOT NULL, transaction timestamp by ISO string with GMT timezone)
Available Commands
All the commands need to be start with 'bank', example: bank login Alice 1234567b bank pay Bob 20
bank -h, --help
To call up the help content for all the commands availble inside this cli
bank -V, --version
To give the current cli version
bank login <name> <password>
name - required, password - required To login to certain user if password is matched with password hash by bcrypt If there's no user matched with the name provided, it will auto register a new profile The password need to have at least 8 characters, one number and one character
Possible Output(s)
When the password provided is less than 8 character: "Password length should need to have at least 8 character." "Which consists at least one character and one number."
When the password provided doesn't contain at least one character and one number: "Password doesn't contain at least one character and one number."
When password provided doesn't matched with existed user profile password hash: "Incorrect Password.
If login perform successfully: "Hello, <'name'>!" (If have someone own you money) "Owing <'debt amount'> from <'own person'>." "Your balance is <'available value'>." (If have you own someone money) "Owing <'debt amount'> to <'debt person'>."
bank topup <amount>
amount - required To topup amount provided to active user login A active user session must exists, if doesn't have you will have need to login with any user to perform The topup will only applied to most recent user session The amount provided must need to be greater than 0, can accept numeric and / or decimal with two decimal places If the active user session have own any other user money, it will priority to transfer the money to that user first
Possible Output(s)
When amount provided is not numeric / there's other than decimal separator appear / more than two decimal typed: "Amount enter allowed only numeric and / or decimal with two decimal places."
When the amount provided is less or equal to 0.00 "Amount enter need to be greater than 0.00."
When there's no any active user login: "No user login at the moment." "Please login to perform this command."
If have active user login: (If you need to pay debt to own person) "Transferred <'amount need to pay'> to <'own person'>." "Your balance is <'final available value (previous available value + (topup amount - total amount need to pay))'>."
bank pay <user> <amount>
user - required, amount - required To transfer your available amount to certain user A active user session must exists, if doesn't have you will have need to login with any user to perform The targeted user must not be same user as requested user The targeted user must be valid user, if the targeted user is not exists it will not allowed to transfer If targeted user own this user money, it will priority reduce the own amount first If there's no any available amount to transfer (0.00), it will stop the operation and request user to topup first If the amount is not enough to make the full amount to transfer, it will first transfer all the available amount then create debt tranaction to own the targeted user remaining money
Possible Output(s)
When amount provided is not numeric / there's other than decimal separator appear / more than two decimal typed: "Amount enter allowed only numeric and / or decimal with two decimal places."
When the amount provided is less or equal to 0.00 "Amount enter need to be greater than 0.00."
When there's no any active user login: "No user login at the moment." "Please login to perform this command."
When same user is typed on pay command: "Pay function cannot be use on same user." "Please type another username to perform this command."
When targeted user is not exists: "Please first login to that user first to perform auto register."
When your remaining amount reach 0 and you don't have any debt from targeted user: "Your balance is reached 0.00." "And your had no remaining debt from <'targeted user'>." "Please topup before perform this command.";
When your remaining amount reach 0 and the debt amount is already been paid off: "Your balance is reached 0.00." "Your remaining pay balance <'pay balance'> cannot be pay now." "Please topup then perform the pay command again.";
If pay amount can proceed: (If there is debt from targeted person need to deduct) "Owning <'new debt amount'> from <'targeted user'>." (If there is have amount remaining need to transfer) "Transferred <'amount need transfer'> to <'targeted user'>." "Your balance is <'final available value (previous available vlue - (amount need transfer))'>." (If there is still have amount remaining cannot pay and need to perform debt) "Owing <'amount to own'> to <'targeted user'>."
bank history [limit]
limit - optional; if not specific default to 10 To view recent transaction history for active user login A active user session must exists, if doesn't have you will have need to login with any user to perform Limit is to specific maximun transaction shown, need to more than 0 if specific If there's no transaction history to show, it will show no history appear Else it will show table list wiith event detail and transaction time
Possible Output(s)
If limit supplied less than 0: "Limit need to set more than 0."
When there's no any active user login: "No user login at the moment." "Please login to perform this command."
When there is no record: "Hello, <'name'>!" "There's no record at the moment."
If there is have any transaction record: Example: Hello, Bob! Here's your last 7 transaction(s) performed. Event Log Timestamp =========================================================== Top up 90.00. 2020-04-08T12:00:37.644Z Transferred 10.00 to Alice. 2020-04-08T12:00:37.612Z Owing 10.00 to Alice. 2020-04-08T12:00:14.787Z Transferred 30.00 to Alice. 2020-04-08T11:59:49.831Z Owing 70.00 to Alice. 2020-04-08T11:59:36.038Z Transferred 30.00 to Alice. 2020-04-08T11:59:35.980Z Top up 80.00. 2020-04-08T11:59:25.385Z