项目作者: HrithikMittal

项目描述 :
It is the backend repository of Mobile App enabling MSMEs to track finances and manage accounts and inventory📱
高级语言: JavaScript
项目地址: git://github.com/HrithikMittal/Nexus-Account.git
创建时间: 2019-05-28T07:59:58Z
项目社区:https://github.com/HrithikMittal/Nexus-Account

开源协议:MIT License

下载


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:

  • NodeJS - Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.
  • MongoDB Server - NoSql Database and server
  • Postman - API development environment

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:

  1. 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:

  1. 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:

  1. http://localhost:3000/

Expected Output:

  1. {
  2. message: "Welcome!"
  3. }

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

Send a post request to:

  1. 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:

  1. {
  2. "success": "User registered and Logged In!"
  3. }

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























URL Parameters Method Description
/user/register


  • id

  • password



POST

Register a user
/user/login


  • id

  • password



POST

Login a user
/user/logout


    None


POST

Logout a user

Accounting Route
















































URL Parameters Method Description
/journal/add


  • from

  • to

  • date (MM/DD/YYYY)

  • debit

  • credit

  • narration



POST

Add new entry into journal
/journal


    None


GET

Get all journal entry
/journal/update


  • from

  • to

  • entryDate (MM/DD/YYYY)

  • updateDate (MM/DD/YYYY)

  • amount

  • narration

  • action (‘increase’ or ‘decrease’)



POST

Update a journal entry
/ledger/update


    None


GET

Update the ledger
/ledger


    None


GET

Get ledger
/trial


    None


Get

Get trial balance
/final/pnl


    None


GET

Get Profit and Loss Account
/final/balance


    None


GET

Get Balance Sheet

Flexible Budget Route


















URL Parameters Method Description
/flexBudget/add


  • name

  • type (“fixed” or “variable”)

  • cost (only if ‘type’ is “fixed”)

  • costPerUnit (only if ‘type’ is “variable”)



POST

Add an entry to budget
/flexBudget


  • units (Number)



POST

Get the flexible budget

Inventory Route























URL Parameters Method Description
/inventory/add


  • name

  • category

  • quantity

  • thresholdQuantity

  • expiry (format ‘05 September 2019’)

  • cost



POST

Add an item to inventory
/inventory/update


  • name

  • category

  • usedQuantity



POST

Update an item in inventory
/inventory


    None


GET

Get the inventory

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

  1. async function isUserLoggedIn (req, res, next) {
  2. try {
  3. if (!(req.session && req.session.user)) {
  4. return res.status(401).send({
  5. error: "Unauthorized Access!"
  6. });
  7. }else {
  8. const user = await User.findOne({ _id : req.session.user._id })
  9. if(user) {
  10. next();
  11. } else {
  12. req.session.user = null;
  13. return res.status(401).send({
  14. error: "Unauthorized Access!"
  15. });
  16. }
  17. }
  18. } catch(e) {
  19. res.status(400).send({
  20. error: e
  21. })
  22. }
  23. }
  24. // Function to check whether the user is logged out
  25. function isUserLoggedOut (req, res, next) {
  26. if (req.session && req.session.user) {
  27. return res.status(200).send({
  28. message: "User already Logged In!"
  29. });
  30. }
  31. next();
  32. }
  33. module.exports = {
  34. isUserLoggedIn,
  35. isUserLoggedOut
  36. }

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 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, 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

If you are the helping and contributing one, your efforts and suggestion are always welcomed.