This is a simple invoice system that requires configuration files for the application (app-config.js
) and the database (db-config.js
). Follow the instructions below to set up the system.
-
Clone the repository:
git clone https://github.com/shadanxd/invoice-system.git cd invoice-system
-
Create configuration files inside the
app/config
directory:-
app-config.js
for application configuration.Example
app/config/app-config.js
:module.exports ={ session_key : "123456789123456789", port: 3000 };
-
db-config.js
for database configuration.Example
app/config/db-config.js
:module.exports = { // format HOST: "localhost", USER: "postgres", PASSWORD: "123456", DB: "invoice_service", PORT: 5432 };
-
-
Install dependencies using npm:
npm install
-
Run the node server:
node index.js
user_id
: SERIAL PRIMARY KEY - Unique identifier for each user.name
: VARCHAR(255) NOT NULL - Name of the user.address
: VARCHAR(255) NOT NULL - Address of the user.role
: VARCHAR(10) NOT NULL CHECK (role IN ('admin', 'payer', 'receiver')) - Role of the user. Can be 'admin', 'payer', or 'receiver'.username
: VARCHAR(255) NOT NULL - username of the userpassword
: VARCHAR(255) NOT NULL - password of the user
- The
user_id
is the primary key, ensuring each user has a unique identifier. name
,address
,username
,password
,address
,role
cannot be NULL.role
must be one of 'admin', 'payer', or 'receiver'.
invoice_id
: SERIAL PRIMARY KEY - Unique identifier for each invoice.payer_id
: INTEGER NOT NULL - Foreign key referencing the user_id of the payer.receiver_id
: INTEGER NOT NULL - Foreign key referencing the user_id of the receiver.initiation_date
: DATE NOT NULL - Date when the invoice was initiated.due_date
: DATE NOT NULL - Due date for the invoice.amount
: DECIMAL(10, 2) NOT NULL - Amount of the invoice.status
: VARCHAR(20) NOT NULL CHECK (status IN ('PENDING', 'COMPLETED', 'REJECTED')) DEFAULT 'PENDING' - Status of the invoice.description
: TEXT - Additional description for the invoice.
- The
invoice_id
is the primary key, ensuring each invoice has a unique identifier. payer_id
andreceiver_id
are foreign keys referencing theuser_id
in theusers
table.status
must be one of 'PENDING', 'COMPLETED', or 'REJECTED'.- The default status is 'PENDING'.
- The payer and receiver roles are enforced through CHECK constraints.
payment_id
: SERIAL PRIMARY KEY - Unique identifier for each payment.invoice_id
: INTEGER NOT NULL - Foreign key referencing the invoice_id.payer_id
: INTEGER NOT NULL - Foreign key referencing the user_id of the payer.mode
: VARCHAR(10) NOT NULL CHECK (mode IN ('offline', 'online')) - Payment mode, can be 'offline' or 'online'.date
: DATE - Date when the payment was made.amount
: DECIMAL(10, 2) NOT NULL - Amount of the payment.
- The
payment_id
is the primary key, ensuring each payment has a unique identifier. invoice_id
is a foreign key referencing theinvoice_id
in theinvoices
table.
The Invoice Service API provides endpoints to manage users, invoices, and payments within an invoicing system. This documentation outlines the available endpoints, their functionalities, and the expected request and response formats.
Base URL: http://localhost:3000/invoice-system
To access protected endpoints, provide the following headers in your requests:
- username: username of admin/payer/receiver
- password: corresponding password
/payment/add
only by payer and admin/payment/fetch
only by admin/payment/delete
only by admin
/invoice/add
only by receiver and admin/invoice/fetch
only by receiver and admin/invoice/delete
only by admin/invoice/updateStatus
only by admin
- Endpoint:
/user/add
- Method: POST
- Request Body:
{ "name": "user11", "address": "lol", "role": "receiver", "username": "user11", "password": "12345" }
- Method: POST
- URL:
http://localhost:3000/invoice-system/invoice/add
- Body:
- Mode: Raw
- Content-Type: application/json
- Raw Data:
{ "user_id": 1, "payer_id": 2, "receiver_id": 3, "initiation_date": "08/12/2023", "due_date": "10/12/2023", "amount": 352 }
- Method: POST
- URL:
http://localhost:3000/invoice-system/payment/add
- Body:
- Mode: Raw
- Content-Type: application/json
- Raw Data:
{ "invoice_id": 5, "payer_id": 2, "mode": "online", "amount": 352 }
- Method: GET
- URL:
http://localhost:3000/invoice-system/user/fetch
- Allowed any of Query Parameters:
name
: "user2"userIdToCheck
: 2address
: "lol"username
: "user2"role
: "admin"
- Method: GET
- URL:
http://localhost:3000/invoice-system/invoice/fetch
- Allowed any of Query Parameters:
status
: "PENDING" or "COMPLETED" or "REJECTED"amount
: 2000invoice_id
: 1payer_id
: 2receiver_id
: 3due_date
: "DD/MM/YYYY"initiation_date
: "DD/MM/YYYY"
- Method: GET
- URL:
http://localhost:3000/invoice-system/payment/fetch
- Allowed Query Parameters:
mode
: "online"payment_id
: 2invoice_id
: 10payer_id
: 9date
: "DD/MM/YYYY"amount
: 3000
- Method: PUT
- URL:
http://localhost:3000/invoice-system/user/update
- Body:
- Mode: Raw
- Content-Type: application/json
- Raw Data:
{ //user_id required all other paramters optional "user_id": 11, "username": "user2", "password": "1234", "name": "newuser", "role": "payer", "address": "check" }
- Method: PUT
- URL:
http://localhost:3000/invoice-system/invoice/updateStatus
- Query Parameters:
invoice_id
: 11status
: "PENDING" or "COMPLETED" or "REJECTED"
- Method: DELETE
- URL:
http://localhost:3000/invoice-system/user/delete
- Query Parameters:
user_id
: 13
- Method: DELETE
- URL:
http://localhost:3000/invoice-system/payment/delete
- Query Parameters:
payment_id
: 5
- Method: DELETE
- URL:
http://localhost:3000/invoice-system/invoice/delete
- Query Parameters:
invoice_id
: 1