This script processes financial transactions, calculates commissions, and maintains weekly quotas for users.
The script reads transaction data from a JSON file, processes each transaction, calculates the commission based on transaction type and user type, and logs the commissions. It also manages weekly quotas to track users' free transaction limits.
- Entry point of the script.
- Reads transaction data from the input file, processes transactions, and logs commissions.
- Processes a single transaction.
- Determines the transaction type and user type.
- Calculates the commission based on the transaction details and updates weekly quotas.
- Deletes the
quotas.json
file if it exists. - Used to reset quotas when running the script.
- Loads weekly quotas data from the
quotas.json
file. - Initializes new quotas if the file doesn't exist or data for the current week is not available.
- Ensures quota values are initialized for all users.
- Saves weekly quotas data to the
quotas.json
file. - Called after updating quotas to persist changes.
- Checks if the transaction date falls within the current week.
- Updates the weekly start date and resets weekly quotas if necessary.
The quotas.json
file is used to store weekly quotas for users. It keeps track of the total amount spent and the free amount used by each user. This file is managed by the script to maintain accurate quota data between script executions.
To run the script, provide the input file path as a command-line argument:
node app.js input.json
To run the unit tests, use the following command:
npm test