GitHub - devmobin/manimani: Manage your budget and money with manimani API · GitHub
Skip to content

devmobin/manimani

Folders and files

Repository files navigation

ManiMani

Manage your budget


Installation

1 - clone or download project somewhere in your computer.

2 - create config files(dev.env and test.env) in the config folder and check that if mongodb url and other variables are true. (both for dev.env and test.env files)

in dev.env:

PORT=3000
JWT_SECRET='thisismysecret'
MONGO_URI='mongodb://localhost:27017/manimaniDB'

in test.env:

PORT=3001
JWT_SECRET='thisismysecret'
MONGO_URI='mongodb://localhost:27017/manimaniDB-test'

3 - run npm install to install the packages.

4 - run npm test to make sure updates didn't break anything.

5 - run npm run dev to start the server. and now you are able to send requests from your front-end project to the api.

Usage

project is ready to use and you can find api end points in here:


Signup User

users need to signup in the database to use the application

  • URL

    /user/signup

  • Method

    POST
  • Data Params

  {
    email: 'dev@gmail.com',
    password: 'mobin1234'
  }

these are required fields.

users can provide more information for their account like: name

  • Success Response:

    • Code: 201

      Content:

{
    user: {
        _id: "5d8b79e31381132868766c52",
        email: "dev@mobin.com",
        createdAt: "2019-09-25T14:29:55.926Z",
        updatedAt: "2019-09-25T14:29:56.230Z"
    }
}
  • Error Response:

    • Code: 400

      Content:

{
  error: 'please enter all the required fields [email, password]'
}

OR:

  • Code: 400

    Content:

{
  error: 'email is already exists'
}

Login User

now you have an account and you need a valid jwt token for any operation. you can take it from signup response or for other devices you can login again.

for use that token you just need to take that and put in a header for next request

.set('Authorization', `Bearer ${token}`)

now time to login:

  • URL

    /user/login

  • Method

    POST
  • Data Params

  {
    email: 'dev@gmail.com',
    password: 'mobin1234'
  }

these are required fields.

  • Success Response:

    • Code: 200

      Content:

{
  token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC'
}
  • Error Response:

    • Code: 400

      Content:

{
  error: 'please enter all the required fields [email, password]'
}

OR:

for cases with invalid password

  • Code: 400

    Content:

{
  error: 'Unable to login'
}

Read User Profile

this is for see your profile in database

  • URL

    /user/me

  • Method

    GET
  • only needs Bearer token in header

  • Success Response:

    • Code: 200

      Content:

{
    _id: "5d8a42640f717a0d2ac761b8",
    email: "devmobin@mobin.com",
    createdAt: "2019-09-24T16:20:52.172Z",
    updatedAt: "2019-09-25T15:03:30.017Z"
}
  • Error Response:

    • Code: 401

      Content:

{
  error: 'please signup or login'
}

this is what you see without token


Edit User Profile

this is for editing your profile in database

  • URL

    /user/me

  • Method

    PATCH
  • Data Params

  {
    email: 'devcom@mobin.com',
    password: 'mobin12345'
  }

you can edit 'name', 'email', 'password'.

just send anything you want to edit in request body

  • Success Response:

    • Code: 200

      Content:

{
    _id: "5d8a42640f717a0d2ac761b8",
    email: "devcom@mobin.com",
    createdAt: "2019-09-24T16:20:52.172Z",
    updatedAt: "2019-09-25T15:03:30.017Z"
}
  • Error Response:

    • Code: 401

      Content:

{
  error: 'please signup or login'
}

this is what you see without token

OR:

  • Code: 400

    Content:

{
  error: 'Invalid updates!'
}

when you are editing invalid field in user profile like: location

OR:

  • Code: 500

when you choose an email that used before :)


Logout User

this is for delete your token and logout

  • URL

    /user/logout

  • Method

    GET
  • only needs Bearer token in header

  • Success Response:

    • Code: 200

  • Error Response:

    • Code: 401

this is what you see without token


Logout User from all devices

this is for delete your tokens and logout from all devices

  • URL

    /user/logoutAll

  • Method

    GET
  • only needs Bearer token in header

  • Success Response:

    • Code: 200

  • Error Response:

    • Code: 401

this is what you see without token


Delete User Profile

this will completely delete user and tasks that related to this user

  • URL

    /user/me

  • Method

    DELETE
  • only needs Bearer token in header

  • Success Response:

    • Code: 200

      Content:

{
    _id: "5d8a42640f717a0d2ac761b8",
    email: "devcom@mobin.com",
    createdAt: "2019-09-24T16:20:52.172Z",
    updatedAt: "2019-09-25T15:03:30.017Z",
}
  • Error Response:

    • Code: 401

this is what you see without token


what about Transactions?

Create New Transaction

users signed up for create transactions and here is the way:

  • URL

    /transaction/new

  • Method

    POST
  • Data Params

{
  type: 'income',
  title: 'project'
  amount: 2500
}
  • needs token header

you can also send 'date'. but these 3 is required

date -> Date()

type -> string => 'income' or 'expense'

  • Success Response:

    • Code: 200

      Content:

{
    amount: 2500,
    type: 'income',
    date: "2019-09-25T16:06:00.570Z",
    _id: "5d8b90681381132868766c57",
    title: "project",
    owner: "5d8b79e31381132868766c52",
    createdAt: "2019-09-25T16:06:00.570Z",
    updatedAt: "2019-09-25T16:06:00.570Z",
    __v: 0
}
  • Error Response:

    • Code: 401

this is what you see without token

OR:

  • Code: 400

    Content:

{
  error: 'please enter valid type'
}

Get All User Transactions

return all transactions for this user

  • URL

    /transaction/me

  • Method

    GET
  • only needs Bearer token in header

  • Success Response:

    • Code: 200

      Content:

;[
  {
    amount: 2500,
    type: 'income',
    date: '2019-09-25T16:06:00.570Z',
    _id: '5d8b90681381132868766c57',
    title: 'project',
    owner: '5d8b79e31381132868766c52',
    createdAt: '2019-09-25T16:06:00.570Z',
    updatedAt: '2019-09-25T16:06:00.570Z',
    __v: 0
  },
  {
    amount: 25000,
    type: 'expense',
    date: '2019-09-25T16:06:00.570Z',
    _id: '5d8b90681381132868766c57',
    title: 'buy car',
    owner: '5d8b79e31381132868766c52',
    createdAt: '2019-09-25T16:06:00.570Z',
    updatedAt: '2019-09-25T16:06:00.570Z',
    __v: 0
  }
]
  • Error Response:

    • Code: 401

this is what you see without token


Get Transactions by id

return transaction by id

  • URL

    /transaction/5d8b90681381132868766c57

  • Method

    GET
  • needs Bearer token in header

  • Success Response:

    • Code: 200

      Content:

{
    amount: 2500,
    type: 'income',
    date: '2019-09-25T16:06:00.570Z',
    _id: '5d8b90681381132868766c57',
    title: 'project',
    owner: '5d8b79e31381132868766c52',
    createdAt: '2019-09-25T16:06:00.570Z',
    updatedAt: '2019-09-25T16:06:00.570Z',
    __v: 0
}
  • Error Response:

    • Code: 401

this is what you see without token

OR:

  • Code: 404

when transaction doesn't exist


Edit Transaction

this is for editing transaction by id

  • URL

    /transaction/5d8b90681381132868766c57

  • Method

    PATCH
  • Data Params

  {
    title: 'update project',
    amount: 3000
  }

you can edit 'title', 'amount', 'date', 'type'.

just send anything you want to edit in request body

  • Success Response:

    • Code: 200

      Content:

{
    amount: 3000,
    type: 'income',
    date: '2019-09-25T16:06:00.570Z',
    _id: '5d8b90681381132868766c57',
    title: 'update project',
    owner: '5d8b79e31381132868766c52',
    createdAt: '2019-09-25T16:06:00.570Z',
    updatedAt: '2019-09-25T16:06:00.570Z',
    __v: 0
}
  • Error Response:

    • Code: 401

this is what you see without token

OR:

  • Code: 400

    Content:

{
  error: 'Invalid updates!'
}

when you are editing invalid field in transaction like: time


Delete Transaction

this will completely delete the transaction

  • URL

    /transaction/5d8b90681381132868766c57

  • Method

    DELETE
  • needs Bearer token in header

  • Success Response:

    • Code: 200

      Content:

{
    amount: 3000,
    type: 'income',
    date: '2019-09-25T16:06:00.570Z',
    _id: '5d8b90681381132868766c57',
    title: 'update project',
    owner: '5d8b79e31381132868766c52',
    createdAt: '2019-09-25T16:06:00.570Z',
    updatedAt: '2019-09-25T16:06:00.570Z',
    __v: 0
}
  • Error Response:

    • Code: 401

this is what you see without token

OR

  • Code: 404

About

Manage your budget and money with manimani API

Resources

Stars

Watchers

Forks

Packages

Contributors