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.
users need to signup in the database to use the application
-
/user/signup
{
email: 'dev@gmail.com',
password: 'mobin1234'
}these are required fields.
users can provide more information for their account like: name
{
user: {
_id: "5d8b79e31381132868766c52",
email: "dev@mobin.com",
createdAt: "2019-09-25T14:29:55.926Z",
updatedAt: "2019-09-25T14:29:56.230Z"
}
}{
error: 'please enter all the required fields [email, password]'
}OR:
{
error: 'email is already exists'
}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:
-
/user/login
{
email: 'dev@gmail.com',
password: 'mobin1234'
}these are required fields.
{
token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVC'
}{
error: 'please enter all the required fields [email, password]'
}OR:
for cases with invalid password
{
error: 'Unable to login'
}this is for see your profile in database
-
/user/me
-
only needs Bearer token in header
-
{
_id: "5d8a42640f717a0d2ac761b8",
email: "devmobin@mobin.com",
createdAt: "2019-09-24T16:20:52.172Z",
updatedAt: "2019-09-25T15:03:30.017Z"
}{
error: 'please signup or login'
}this is what you see without token
this is for editing your profile in database
-
/user/me
{
email: 'devcom@mobin.com',
password: 'mobin12345'
}you can edit 'name', 'email', 'password'.
just send anything you want to edit in request body
{
_id: "5d8a42640f717a0d2ac761b8",
email: "devcom@mobin.com",
createdAt: "2019-09-24T16:20:52.172Z",
updatedAt: "2019-09-25T15:03:30.017Z"
}{
error: 'please signup or login'
}this is what you see without token
OR:
{
error: 'Invalid updates!'
}when you are editing invalid field in user profile like: location
OR:
when you choose an email that used before :)
this is for delete your token and logout
-
/user/logout
-
only needs Bearer token in header
-
-
this is what you see without token
this is for delete your tokens and logout from all devices
-
/user/logoutAll
-
only needs Bearer token in header
-
-
this is what you see without token
this will completely delete user and tasks that related to this user
-
/user/me
-
only needs Bearer token in header
-
{
_id: "5d8a42640f717a0d2ac761b8",
email: "devcom@mobin.com",
createdAt: "2019-09-24T16:20:52.172Z",
updatedAt: "2019-09-25T15:03:30.017Z",
}this is what you see without token
users signed up for create transactions and here is the way:
-
/transaction/new
{
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'
{
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
}this is what you see without token
OR:
{
error: 'please enter valid type'
}return all transactions for this user
-
/transaction/me
-
only needs Bearer token in header
-
;[
{
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
}
]this is what you see without token
return transaction by id
-
/transaction/5d8b90681381132868766c57
-
needs Bearer token in header
-
{
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
}this is what you see without token
OR:
when transaction doesn't exist
this is for editing transaction by id
-
/transaction/5d8b90681381132868766c57
{
title: 'update project',
amount: 3000
}you can edit 'title', 'amount', 'date', 'type'.
just send anything you want to edit in request body
{
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
}this is what you see without token
OR:
{
error: 'Invalid updates!'
}when you are editing invalid field in transaction like: time
this will completely delete the transaction
-
/transaction/5d8b90681381132868766c57
-
needs Bearer token in header
-
{
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
}this is what you see without token
OR
