To reproduce:
* In the root folder run cd
* Start MongoDB server
* Run `npm run dev`
* Navigate to http://localhost:5000/
API Docs
Routes
Public routes
POST /signup
Route for signing up a new user. You should pass userName, email and password as required fields and firstName, lastName, birthday, phoneNumber, location, autos as optional fields Example request
{
"userName": "vasya123",
"firstName": "vasya",
"lastName": "vasin",
"email": "[email protected]",
"password": "password",
"birthday": "1980-01-01T00:00:00.000Z",
"phoneNumber": "+380661234567"
"location": "Ukraine"
} Example response
{
"success": true,
"message": "user successfully registered"
}POST /login
Route for logging in. You should pass email and password in a request and receive token in a response. Example request
{
"email": "[email protected]",
"password": "password"
} Example response
{
"success": true,
"message": "token successfully created",
"token": "access token"
}GET /item/:id
Route for getting detailed info about 1 auto. You should pass auto id in URL. Example URL
/item/5739fa5ba16b5b4b48acfb58
Example response
{
"_id": "5739fa5ba16b5b4b48acfb58",
"stockID": "1111",
"vin": "4JGDF6EE8GA622370",
"maker": "MERCEDES-BENZ",
"model": "GL450W4",
"color": "",
"price": 1,
"year": 2016,
"mileage": 10,
"state": "N",
"transmission": "manual",
"entryDate": "2015-06-26T21:00:00.000Z",
"__v": 0,
"ratings": [],
"createdAt": "2016-05-24T09:19:17.160Z",
"options": []
}GET /items/:page
Route for pagination with sorting. You can pass "page", "perPage", "sortBy", "sortOrder" as query params in URL. Example URL
/items/page?page=3&perPage=1&sortBy=price&sortOrder=desc
Example response
[
{
"_id": "5739fa5ca16b5b4b48acfc55",
"stockID": "160021",
"vin": "WDDUX7GB6GA151321",
"maker": "MERCEDES-BENZ",
"model": "S600X",
"color": "DESIGNO MOCHA BLACK",
"price": 178,
"year": 2016,
"mileage": 10,
"state": "N",
"transmission": "manual",
"entryDate": "2015-04-16T21:00:00.000Z",
"__v": 0,
"ratings": [],
"createdAt": "2016-05-24T09:19:17.160Z",
"options": []
}
]POST /search
Route for search. You should pass search string in a request body. Search will be executed by fields "maker" and "model" Example request
{
"body": {
"search": "190"
}
} Example response
[
{
"_id": "5739fa5ba16b5b4b48acfb5f",
"stockID": "TEST",
"vin": "22222222222222222",
"maker": "MERCEDES-BENZ",
"model": "190",
"color": "",
"price": 1,
"year": 2002,
"mileage": 101961,
"state": "U",
"transmission": "manual",
"entryDate": "2012-07-29T21:00:00.000Z",
"__v": 0,
"ratings": [],
"createdAt": "2016-05-24T09:19:17.160Z",
"options": []
}
]Profile routes
GET /profile
Route for getting detailed info about logged in user. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
}
}Example response
{
"email": "[email protected]",
"userName": "petya3",
"orders": [],
"autos": []
}PUT /profile
Route for updating current user info. You cannot update "_id", "password" and "role" fields by this route. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"userName": "superman"
}
}Example response
{
"success": true,
"message": "User updated successfully"
}PUT /profile/password
Route for updating current user password. New password has to be from 6 to 20 characters long to pass the validation. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"password": "password2"
}
}Example response
{
"success": true,
"message": "Password updated successfully"
}Users routes
POST /user/order
Route for ordering a car by current user. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"autoId": "5739fa5ba16b5b4b48acfb75",
"duration": 3,
"sum": 84
}
}Example response
{
"success": true,
"message": "Order placed to a cart",
"cartId": "5744296ba226b8a2a778ebd4"
}GET /user/orders
Route for getting current user history Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
[
{
"_id": "5744296ba226b8a2a778ebd4",
"orderedBy": "573dbeec3334d7d23fd66930",
"sum": 84,
"duration": 3,
"__v": 0,
"status": "pending",
"createdAt": "2016-05-24T10:13:47.030Z",
"orders": [
"5739fa5ba16b5b4b48acfb75"
]
}
]GET /user/cart/:id
Route for getting last order of current user. You should pass cart id to URL. Example URL
/user/cart/5744296ba226b8a2a778ebd4
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
[
{
"_id": "5744296ba226b8a2a778ebd4",
"orderedBy": "573dbeec3334d7d23fd66930",
"sum": 84,
"duration": 3,
"__v": 0,
"status": "pending",
"createdAt": "2016-05-24T10:13:47.030Z",
"orders": [
"5739fa5ba16b5b4b48acfb75"
]
}
]DELETE /user/order
Route for deleting one order from users cart. You should pass auto id and new total order sum in request body. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"autoId": "5739fa5ba16b5b4b48acfb75",
"sum": 0
}
}Example response
{
"success": true,
"message": "Order deleted"
}POST /user/cart/confirm
Route for confirming an order. You cannot confirm an order if order cart is empty. Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"success": true,
"message": "Orders confirmed"
}POST /user/rate
Route for rating a car by user. You should pass "id" as car id and "rate" field to request. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"id": "5739fa5ba16b5b4b48acfb75",
"rate": 2
}
}Example response
{
"success": true,
"message": "rating submitted",
"avgRating": 3.5,
"ratedBy": 4
}Providers routes
POST /provider/auto
Route for creating new auto if user role is "provider". Required fields are: "stockID", "maker" and "price". Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"stockID": "abc123",
"maker": "vaz",
"model": "2107",
"price": 7,
"color": "white",
"year": 1985,
"mileage": 220000,
"state": "U",
"transmission": "manual",
"seats": 5,
"doors": 4,
"size": "small",
}
}Example response
{
"success": true,
"message": "auto successfully created"
}PUT /provider/auto
Route for updating a car that belongs to provider. You should pass required field "id" as a car id and optional other fields to update. You cannot pass "_id" or "owner" fields to request Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"id": "5744370a85f669c320e59f85",
"price": 8
}
}Example response
{
"success": true,
"message": "auto updated successfully"
}GET /provider/autos
Route for getting current provider car list. Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
[
{
"_id": "5744370a85f669c320e59f85",
"owner": "574307641574dda63febcfc0",
"stockID": "abc123",
"maker": "vaz",
"model": "2107",
"price": 8,
"color": "white",
"year": 1985,
"mileage": 220000,
"state": "U",
"transmission": "manual",
"seats": 5,
"doors": 4,
"size": "small",
"__v": 0,
"ratings": [],
"createdAt": "2016-05-24T11:12:07.973Z",
"options": []
}
]GET /provider/autos/:id
Route for getting detailed info about providers car by id. You should pass auto id to URL. Example URL
/provider/autos/5744370a85f669c320e59f85
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"_id": "5744370a85f669c320e59f85",
"owner": "574307641574dda63febcfc0",
"stockID": "abc123",
"maker": "vaz",
"model": "2107",
"price": 8,
"color": "white",
"year": 1985,
"mileage": 220000,
"state": "U",
"transmission": "manual",
"seats": 5,
"doors": 4,
"size": "small",
"__v": 0,
"ratings": [],
"createdAt": "2016-05-24T11:12:07.973Z",
"options": []
}POST /provider/auto/:id/image
Route for setting car image by provider. You should pass car id to URL and image string to request body Example URL
/provider/auto/5744370a85f669c320e59f85/image
Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"image": "some image"
}
}Example response
{
"success": true,
"message": "Auto image set successfully"
}DELETE /provider/auto/:id/image
Route for deleting car image by provider. You should pass car id to URL. Example URL
/provider/auto/5744370a85f669c320e59f85/image
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"success": true,
"message": "Auto image deleted successfully"
}DELETE /provider/auto
Route for deleting auto by provider. You should pass car id to request body. Example request
{
"headers" : {
"x-access-token": "access token"
},
"body" : {
"id": "5744370a85f669c320e59f85"
}
}Example response
{
"success": true,
"message": "Auto deleted"
}Admin routes
GET /admin/user/:id
Route for getting detailed info about user by admin. You should pass user id to URL. Example URL
/admin/user/573d9220ef4c905d25d9e114
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"email": "[email protected]",
"userName": "superman",
"orders": [],
"autos": []
}GET /admin/user/:id/orders
Route for getting orders of specified user by admin. You should pass user id to URL. Example URL
/admin/user/573d9220ef4c905d25d9e114/orders
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
[
{
"_id": "5744296ba226b8a2a778ebd4",
"orderedBy": "573d9220ef4c905d25d9e114",
"sum": 84,
"duration": 3,
"__v": 0,
"status": "pending",
"createdAt": "2016-05-24T10:13:47.030Z",
"orders": [
"5739fa5ba16b5b4b48acfb75"
]
}
]GET /admin/provider/:id/autos
Route for getting autos that belong to specified provider by admin. You should pass provider id to URL. Example URL
/admin/provider/574307641574dda63febcfc0/autos
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
[
{
"_id" : ObjectId("5744370a85f669c320e59f85"),
"owner" : ObjectId("574307641574dda63febcfc0"),
"stockID" : "abc123",
"maker" : "vaz",
"model" : "2107",
"price" : 7,
"color" : "white",
"year" : 1985,
"mileage" : 220000,
"state" : "U",
"transmission" : "manual",
"seats" : 5,
"doors" : 4,
"size" : "small",
"ratings" : [ ],
"createdAt" : ISODate("2016-05-24T11:12:07.973Z"),
"options" : [ ],
"__v" : 0
}
]GET /admin/statistics/autos/:params
Route for autos statistics with different criteria by admin. You can pass to URL next query params - "field", "fromValue", "toValue", "sortBy", "sortOrder". Example URL
/admin/statistics/autos/params?field=price&fromValue=20&toValue=50
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"count": 323,
"data": [
...
]
} GET /admin/statistics/providers/:params
Route for autos statistics with different criteria by admin. You can pass to URL next query params - "field", "fromValue", "toValue", "sortBy", "sortOrder". Example URL
/admin/statistics/providers/params?field=location&equals=Ukraine
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"count": 0,
"data": []
} GET /admin/statistics/orders/:params
Route for autos statistics with different criteria by admin. You can pass to URL next query params - "field", "fromValue", "toValue", "sortBy", "sortOrder". Example URL
/admin/statistics/orders/params?field=sum&fromValue=10&toValue=50
Example request
{
"headers" : {
"x-access-token": "access token"
}
}Example response
{
"count": 12,
"data": [
...
]
}