Project Requirements:

TypeScript ATM Project is a console-based complex Node.js application. When the system starts the user is prompted with a user id and user pin. After entering the details successfully, the ATM functionalities are unlocked. All the user data is generated randomly.

Analysis:

  • The TypeScript ATM Project is a complex Node.js application that runs in the console.
  • When the system starts, it prompts the user for a user ID and password.
  • If the user enters the correct details, the ATM functionalities are unlocked.
  • All the user data is randomly generated.

The TypeScript ATM Project is a well-designed and secure application that uses random generation of user data to ensure the safety of the user’s personal information. It is easy to use and accessible to anyone with a computer.

Part-1

Part-2

Part-3

Shebang code:

The line #!/usr/bin/env node in TypeScript code is called a shebang. It tells the operating system to use the Node.js interpreter to run the script. This is a common convention in Node.js scripts.

The #!/usr/bin/env part tells the operating system where to find the Node.js interpreter. The node part is the name of the Node.js interpreter.

This line is typically placed at the beginning of a Node.js script. It is important to note that this line is only a convention and is not required.

Import modules:

The `inquirer` module is imported from the `inquirer` package.

You need to install the inquirer module first using the npm install inquirer command.

You can use the inquirer module to create interactive prompts for users. These prompts can be used to collect input from users, such as their name, email address, or password. They can also be used to display messages to users, such as instructions or error messages.

Interface ansType:

Defines an interface called ansType. The ansType interface defines 5 properties:

  • The userID property is a string that represents the user ID.
  • The userPin property is a number that represents the user PIN.
  • The accountType property is a string that represents the account type.
  • The transType property is a string that represents the transaction type.
  • The amount property is a number that represents the amount of money involved in the transaction.

The ansType interface defines the properties that an object must have in order to represent an ATM transaction. For example, an object that represents an ATM withdrawal must have the userID, userPin, accountType, and amount properties.

The ansType interface is a useful tool for defining and validating ATM transactions. It can be used to ensure that all transactions are valid and that the data in the transactions is consistent.

Type User:

Defines a type called User. The User type has two properties:

  • The userID property is a string that represents the user ID.
  • The userPin property is a number that represents the user PIN.

The User type is used to define objects that represent users.

Declaring variables:

Defines four variables:

  • The users variable is an array of objects of type User. The array contains three users:
    • A user with the user ID “ahmer” and the user PIN 1234.
    • A user with the user ID “rafi” and the user PIN 5678.
    • A user with the user ID “nadeem” and the user PIN 9876.
  • The balance variable is a number that represents the balance of an account. The value of the balance variable is randomly generated.
  • The answers1 variable is an object of type ansType. The answers1 variable is not assigned any value.
  • The answers2 variable is an object of type ansType. The answers2 variable is not assigned any value.

The code first defines an array of users. The array contains three users, each with a user ID and a user PIN. The code then randomly generates a value for the balance variable. The answers1 and answers2 variables are not assigned any values.

Function startLoop:

The startLoop() function prompts the user for their user ID and PIN, and then enters a loop. In each iteration of the loop, the function prompts the user for their transaction type and amount, checks if the user has enough balance to complete the transaction, updates the balance and logs the new balance if the user does have enough balance, and logs an error message if the user does not have enough balance. The function then prompts the user if they want to continue. If the user answers yes, the loop is repeated. If the user answers no, the loop is terminated.

  • The do keyword is used to start a loop. The while keyword is used to check if the loop should be terminated.
  • The var keyword is used to declare a variable. The again variable is declared to store the user’s response to the prompt about whether they want to continue.
  • The prompt() function is used to prompt the user for input. The prompt() function can be used to prompt the user for text, numbers, and objects.

Function getUserID:

The getUserID() function prompts the user for their user ID, PIN, and account type using the inquirer module. The function then returns an object of type ansType that contains the user’s input.

The inquirer module is a popular module for creating interactive prompts in TypeScript. The inquirer module provides a variety of functions for creating different types of prompts, such as input prompts, number prompts, and list prompts.

In this case, the inquirer module is used to create three prompts:

  • An input prompt for the user ID.
  • A number prompt for the PIN.
  • A list prompt for the account type.

The getUserID() function then uses the responses to these prompts to create an object of type ansType. This object is then returned by the function.

Function getTransaction:

The getTransaction() function prompts the user for their transaction type and amount using the inquirer module. The function then checks if the user has enough balance to complete the transaction. If the user does have enough balance, the function updates the balance and logs the new balance. If the user does not have enough balance, the function logs an error message.

The inquirer module is used to create two prompts:

  • A list prompt for the transaction type.
  • A number prompt for the amount.

Ahmer Arman

JII Store

Best Laptop

GitHub Link