This project is made for creating, manipulating and access the items (hotels) for the user (hotelier) by which they can update the items on the Trivago website.
- Node js (Server/ backend)
- Swagger (OpenApi)
- Mocha and Chai for unit test cases
- Clone the repository using :
git clone https://github.com/sk0693/trivago_hotelier.git
- Change the repository directory :
cd trivago_hotelier
- Install the needed node packges/modules :
npm install
- Start the development server :
npm start
I have made some test cases using Mocha and chai. To run the test cases...
npm test
All API expect /auth
and /bookings
requests require the use of a generated Authorization Token (JWT)
. You have to register and then login the application using register
and login
routes respectively. These APIs are not required the jwt token.
To authenticate an API request, you must provide your API key in the Authorization
header.
Alternatively, you may use cookies in the browser for the requests to authorize yourself to the API. But note that this is likely to leave traces in things like your history, if accessing the API through a browser.
jwt : Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiI1ZWI4NGQ2YzNmOGIwMDc1ZGRmYzhmYTAiLCJpYXQiOjE1ODkxMzY3NjJ9.
/api-docs
To get the swagger editor
which I have made for open api specifications.
POST /v1/auth/register
Parameter | Type | Description |
---|---|---|
name |
string |
Required. The Name |
contactNumber |
string |
Required. The Name |
email |
string |
Required. The valid email address |
password |
string |
Required. min 8 and max 16 digit password |
{
"success": true,
"user" : {
"_id": String,
"email": String,
"name": String,
"contactNumber": String,
"createdAt": Date,
"updatedAt": Date,
}
}
POST /v1/auth/login
Parameter | Type | Description |
---|---|---|
email |
String |
Required. The valid email address |
password |
String |
Required. 8 digit password |
{
"success": true,
"user": {
"id": String,
"email": String,
"name": String,
"createdAt": Date,
"updatedAt": Date,
},
"token": String
}
To get the user details
GET /v1/user
{
"success": true,
"user": {
"_id": "5f4d2496804c5379496475a6",
"name": "sourabh",
"email": "[email protected]",
"contactNumber": "111234",
"createdAt": "2020-08-31T16:25:58.126Z",
"updatedAt": "2020-08-31T16:46:21.830Z",
"__v": 0
}
}
POST /v1/items/createItem
Parameter | Type | Description |
---|---|---|
name |
String |
Required. The name of the hotel, min 10 characters |
ratings |
Number |
Required. between 0 and 5 |
location |
object |
Required. the valid location object |
category |
String |
Required. it is one, from predefined categories |
image |
String |
Required. the valid image url |
reputation |
Number |
Required. the valid number |
price |
Number |
Required. the price of the booking |
availability |
Number |
Required. curently availability |
*While creating item, the location will be stored in different collection.
{
"success": true,
"item": {
"category": "hotel",
"reputationBadge": "green",
"_id": "5f4de72b5596ee2234b3c11d",
"name": "The Taz hotel 234",
"ratings": 0,
"location": "5f4de72b5596ee2234b3c11c",
"image": "www.image.com",
"reputation": 900,
"price": 1000,
"availability": 2,
"user_id": "5f4d2496804c5379496475a6",
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:16:11.429Z",
"__v": 0
}
}
To get the item with the item_id
GET /v1/items/5f4de72b5596ee2234b3c11d
Parameter | Type | Description |
---|---|---|
item_id |
string |
Required. The valid item id |
{
"success": true,
"item": {
"_id": "5f4de72b5596ee2234b3c11d",
"name": "The Taz hotel",
"category": "hotel",
"reputationBadge": "green",
"ratings": 0,
"location": {
"_id": "5f4de72b5596ee2234b3c11c",
"city": "Mumbai",
"state": "Maharashtra",
"country": "India",
"zip_code": 40997,
"address": "Apollo Bandar, Colaba",
"createdAt": "2020-09-01T06:16:11.425Z",
"updatedAt": "2020-09-01T06:16:11.425Z",
"__v": 0,
"id": "5f4de72b5596ee2234b3c11c"
},
"image": "www.image.com",
"reputation": 900,
"price": 1000,
"availability": 2,
"user_id": "5f4d2496804c5379496475a6",
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:16:11.429Z",
"__v": 0
}
}
To get all items
GET /v1/items
{
"success": true,
"item": [{
"_id": "5f4de72b5596ee2234b3c11d",
"name": "The Taz hotel",
"category": "hotel",
"reputationBadge": "green",
"ratings": 0,
"location": {
"_id": "5f4de72b5596ee2234b3c11c",
"city": "Mumbai",
"state": "Maharashtra",
"country": "India",
"zip_code": 40997,
"address": "Apollo Bandar, Colaba",
"createdAt": "2020-09-01T06:16:11.425Z",
"updatedAt": "2020-09-01T06:16:11.425Z",
"__v": 0,
"id": "5f4de72b5596ee2234b3c11c"
},
"image": "www.image.com",
"reputation": 900,
"price": 1000,
"availability": 2,
"user_id": "5f4d2496804c5379496475a6",
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:16:11.429Z",
"__v": 0
}
...
]
}
PATCH /v1/items/5eb97457f2130e4060365dd4
Parameter | Type | Description |
---|---|---|
body |
Object |
Required. all keys which you want to update |
{
"success": true,
"message": "Item updated successfully",
"item": {
"category": "resort",
"reputationBadge": "green",
"_id": "5f4de72b5596ee2234b3c11d",
"name": "The Taz hotel",
"ratings": 0,
"location": {
"_id": "5f4de72b5596ee2234b3c11c",
"city": "Mumbai",
"state": "Maharashtra",
"country": "India",
"zip_code": 40009,
"address": "Apollo Bandar, Colaba",
"createdAt": "2020-09-01T06:16:11.425Z",
"updatedAt": "2020-09-01T06:16:11.425Z",
"__v": 0,
"id": "5f4de72b5596ee2234b3c11c"
},
"image": "www.image.com",
"reputation": 900,
"price": 1000,
"availability": 2,
"user_id": "5f4d2496804c5379496475a6",
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:29:15.343Z",
"__v": 0
}
}
DELETE /v1/items/5eb97457f2130e4060365dd4
Delete the item using [item_id]
params
Parameter | Type | Description |
---|---|---|
item_id |
string |
Required. The valid item id |
GET /v1/user/
Getting the user details.
{
"result": {
"id": String,
"email": String,
"name": String
}
}
POST /v1/bookings/bookItem
Parameter | Type | Description |
---|---|---|
name |
String |
Required. The name of the customer |
item_id |
String |
Required. The valid item id for booking |
{
"success": true,
"message": 'Booking done successfull',
"booking": {
"_id": "5f4de72b5596ee2234b3c11d",
"name": "Sourabh khurana",
"item_id": "5f4de72b5596ee2234b3c11c",
"price": 1000,
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:29:15.343Z",
"__v": 0
}
}
To get all bookings
GET /v1/bookings
{
"success": true,
"bookings": [{
"_id": "5f4de72b5596ee2234b3c11d",
"name": "Sourabh khurana",
"item_id": "5f4de72b5596ee2234b3c11c",
"price": 1000,
"createdAt": "2020-09-01T06:16:11.429Z",
"updatedAt": "2020-09-01T06:29:15.343Z",
"__v": 0
}
...
]
}
- Sourabh Khurana