This repository contains the implementation of a backend service for a wallet system. The system supports operations like setting up wallets, processing credit and debit transactions, fetching transactions, and retrieving wallet details.
The service uses two main tables: transactions
and Wallet
.
CREATE TABLE `transactions` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`wallet_id` bigint(20) NOT NULL,
`type` enum('CREDIT','DEBIT') DEFAULT NULL,
`pre_balance` DECIMAL(13, 4) NOT NULL,
`balance` DECIMAL(13, 4) NOT NULL,
`post_balance` DECIMAL(13, 4) NOT NULL,
`created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`wallet_id`) REFERENCES `Wallet`(`id`) ON DELETE CASCADE,
KEY `wallet_id` (`wallet_id`)
) ENGINE=InnoDB AUTO_INCREMENT=3840046 DEFAULT CHARSET=utf8mb4;
CREATE TABLE `Wallet` (
`id` BIGINT(20) AUTO_INCREMENT PRIMARY KEY,
`name` VARCHAR(255) NOT NULL,
`created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
- Initialize Wallet (/setup) Method: POST Body: { "balance": Decimal, "name": String } Response: { "id": String, "balance": Decimal, "name": String, "date": JS Date Object }
- Credit/Debit Amount (/transact/:walletId) Method: POST Params: walletId Body: { "amount": Decimal, "description": String } Response: { "balance": Decimal, "transactionId": String, "name": String, "date": JS Date Object }
- Fetch Transactions (/transactions?walletId={walletId}&skip={skip}&limit={limit}) Method: GET Query: walletId, skip, limit Response: Array of transaction objects
- Get Wallet (/wallet/:id) Method: GET Response: { "id": String, "balance": Decimal, "name": String, "date": JS Date Object }
-
Spin up the MySQL image using Docker Compose in detached mode:
docker-compose up -d
-
Install dependencies and start the server:
npm install
npm run start
-
Install dependencies:
yarn install
-
Build the project:
yarn run build
-
Start the development server:
yarn run dev
or start the production server:yarn run start
- get curls from : examplecurl.txt file.