View on GitHub

Nexus-Account

It is the backend repository of Mobile App enabling MSMEs to track finances and manage accounts and inventory📱

Nexus Accounts HitCount

license

Nexus Account is an API which can be used to perform different accounting tasks such as creating Journal, Ledger, Trial Balance, Profit & Loss Account and Balance Sheet. It is also useful to create Flexible Budget or an Inventory.

Prerequisites

To work with the api you must have to install the following:

Installation

Before doing anything you have to clone or download(and unzip) the project folder, open terminal and navigate to the project folder and run:

npm install

This will install all the dependencies required by the project.

Getting Started

To start using this API, start your local database server, open terminal and navigate to the project folder and run:

npm run start

If an error occur, check your database server or check if you have installed the prerequisites correctly.

If there was no error, open Postman and create and send a new get request to:

http://localhost:3000/

Expected Output:

{
	message: "Welcome!"
}

Firstly, you have to create a new user for working with the API.

Send a post request to:

http://localhost:3000/user/register

Along with ‘id’ and ‘password’ field in the ‘x-www-form-urlencoded’ option for the body of the request in postman:

id demouserid
password demo

Expected Output:

{
    "success": "User registered and Logged In!"
}

Once you get this message, you are ready to work with the api.

Routes

Url for all these routes is http://localhost:3000 and parameters for POST request are sent through ‘x-www-form-urlencoded’ method.

User Routes

</tr> </tr> </tr> </table> ### Accounting Route
URL Parameters Method Description
/user/register</th>
  • id
  • password
POST Register a user
/user/login</th>
  • id
  • password
POST Login a user
/user/logout</th>
    None
      </td>
POST Logout a user
</tr> </tr> </tr> </tr> </tr> </tr> </tr> </tr> </table> ### Flexible Budget Route
URL Parameters Method Description
/journal/add</th>
  • from
  • to
  • date (MM/DD/YYYY)
  • debit
  • credit
  • narration
POST Add new entry into journal
/journal</th>
    None
GET Get all journal entry
/journal/update</th>
  • from
  • to
  • entryDate (MM/DD/YYYY)
  • updateDate (MM/DD/YYYY)
  • amount
  • narration
  • action ('increase' or 'decrease')
    • </td>
POST Update a journal entry
/ledger/update</th>
    None
      </td>
GET Update the ledger
/ledger</th>
    None
      </td>
GET Get ledger
/trial</th>
    None
      </td>
Get Get trial balance
/final/pnl</th>
    None
      </td>
GET Get Profit and Loss Account
/final/balance</th>
    None
      </td>
GET Get Balance Sheet
</tr> </tr> </table> ### Inventory Route
URL Parameters Method Description
/flexBudget/add</th>
  • name
  • type ("fixed" or "variable")
  • cost (only if 'type' is "fixed")
  • costPerUnit (only if 'type' is "variable")
POST Add an entry to budget
/flexBudget</th>
  • units (Number)
POST Get the flexible budget
</tr> </tr> </tr> </table> ### Repos for Seperate Access to the API's ### Authentication I used express-session to manage sessions to authenticate. We have isUserLoggedIn, isUserLoggedOut middleware function which checks if the user is authenticated or not. The session token is stored in the database using connect-mongo package and is deleted when the user logout
``` async function isUserLoggedIn (req, res, next) { try { if (!(req.session && req.session.user)) { return res.status(401).send({ error: "Unauthorized Access!" }); }else { const user = await User.findOne({ _id : req.session.user._id }) if(user) { next(); } else { req.session.user = null; return res.status(401).send({ error: "Unauthorized Access!" }); } } } catch(e) { res.status(400).send({ error: e }) } } // Function to check whether the user is logged out function isUserLoggedOut (req, res, next) { if (req.session && req.session.user) { return res.status(200).send({ message: "User already Logged In!" }); } next(); } module.exports = { isUserLoggedIn, isUserLoggedOut } ``` Note: some of the APIs which are mentionted above are not authenticate so please remember to add it. So it will help to proctect the private routes. ## Deployment This api can be hosted on platform like heroku, aws, and others. MongoDB Atlas or Matlab can be used for remote database.
For instance, the application can be deployed on [Heroku](https://signup.heroku.com/login) by creating and registering an account. Following, create a new app and choose a deployment method (terminal or github) and follow the instruction there. Remote database can be created using Mongodb Atlas or Matlab.
For [Mongodb Atlas](https://cloud.mongodb.com/user?_ga=2.185306281.1809166196.1559570784-2125252051.1557828824#/atlas/register/accountProfile), you need to just to create your account and make a new cluster and link the cluster to your application through a URL. Following the given steps, you would have a remote application up and running. ## Contributing [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/dwyl/esta/issues) If you are the helping and contributing one, your efforts and suggestion are always welcomed.
URL Parameters Method Description
/inventory/add</th>
  • name
  • category
  • quantity
  • thresholdQuantity
  • expiry (format '05 September 2019')
  • cost
POST Add an item to inventory
/inventory/update</th>
  • name
  • category
  • usedQuantity
POST Update an item in inventory
/inventory</th>
    None
GET Get the inventory