GithubHelp home page GithubHelp logo

booking-clone-api's Introduction

Booking Clone API

This is an Express application providing a REST API to the Booking Clone application.

REST API Documentation

Generally it is a RESTful API and returns results in JSON format.

Registration of the user

It allows to register a new user.

Request

POST /api/auth/register

  • Body

    {
      "email": "[valid user email address]",
      "password": "[user password in plain text]",
      "repeatPassword": "[repeated user password in plain text]",
      "firstName": "[user first name]",
      "lastName": "[user last name]",
      "role": "[role of the user (user | hotelOwner)]",
      "isSmsAllowed": [true | false],
      "phoneNumber": "[user phone number]",
      "tin": "[tax identification number of the hotel owner]"
    }

    Required fields:

    email, password, repeatPassword, firstName, lastName, role, isSmsAllowed

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "userId": "[user identifier]",
      "token": "[JWT Token]"
    }
  • Error Response:

    • Status Code: 409 Conflict

      Body:

      {
        "message": "Account with this email address already exists."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "[Data validation error message]"
      }

User login

It allows user to log in.

Request

POST /api/auth/login

  • Body

    {
      "email": "[valid user email address]",
      "password": "[user password in plain text]"
    }

    Required fields:

    email, password

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "userId": "[user identifier]",
      "token": "[JWT Token]"
    }

    The JWT token is also returned in response headers as X-Auth-Token. This token must be sent in every future requests where user need to be authenticated.

  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Email or password is wrong."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "[Data validation error message]"
      }

Request resetting user password

It sends user an email with the link to reset his/her password.

Request

POST /api/auth/requestPasswordReset

  • Body

    {
      "email": "[valid user email address]"
    }

    Required fields:

    email

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "success": true
    }
  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "User does not exists."
      }

      or

      Body:

      {
        "message": "[Data validation error message]"
      }

Reset user password

It allows user to reset his/her password.

Request

POST /api/auth/resetPassword

  • Body

    {
      "userId": "[user identifier]",
      "token": "[valid JWT token]",
      "password": "[user new password in plain text]"
    }

    Required fields:

    userId, token, password

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "success": true
    }
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Invalid or expired password reset token."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "[Data validation error message]"
      }

Get user info

It returns data about logged in user.

Request

GET /api/user/me

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "isVerified": [true | false],
      "role": "[user role (user | hotelOwner)]",
      "_id": "[user identifier]",
      "email": "[user email]",
      "firstName": "[user first name]",
      "lastName": "[user last name]",
      "isSmsAllowed": [true | false]
    }
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
          "message": "Invalid token."
      }
      

Get reservations

It returns logged in user all hotel reservations.

Request

GET /api/reservations

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

    Body for standard user:

    [
        {
            "_id": "[reservation identifier]",
            "startDate": "[reservation start date]",
            "endDate": "[reservation end date]",
            "people": {
                "adults": [number of adults],
                "children": [number of children]
            },
            "hotel": {
                "name": "[name of the hotel]",
                "address": {
                    "country": "[country in which the hotel is located]",
                    "city": "[city where the hotel is located]",
                    "zipcode": "[postal code where the hotel is located]",
                    "street": "[street the hotel is located on]",
                    "buildingNumber": [number of the building where hotel is located]
                },
                "room": {
                    "roomNumber": "[room number]",
                    "price": [price of the room for one night],
                    "description": "[room description]"
                }
            }
        },
        ...
    ]

    Body for hotel owner:

    [
        {
            "_id": "[reservation identifier]",
            "isPaid": [true | false],
            "startDate": "[reservation start date]",
            "endDate": "[reservation end date]",
            "people": {
                "adults": [number of adults],
                "children": [number of children]
            },
            "hotel": {
                "name": "[name of the hotel]",
                "address": {
                    "country": "[country in which the hotel is located]",
                    "city": "[city where the hotel is located]",
                    "zipcode": "[postal code where the hotel is located]",
                    "street": "[street the hotel is located on]",
                    "buildingNumber": [number of the building where hotel is located]
                },
                "room": {
                    "roomNumber": "[room number]",
                    "price": [price of the room for one night],
                    "description": "[room description]"
                }
            },
            "user": {
                "email": "[email of the user who booked the room]",
                "firstName": "[first name of the user who booked the room]",
                "lastName": "[last name of the user who booked the room]"
            }
        },
        ...
    ]
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Invalid token."
      }

Make a room reservation

It allows user to book a room in the hotel.

Request

POST /api/reservations

  • Body

    {
        "user": "[user identifier]",
        "hotel": "[hotel identifier]",
        "room": "[room identifier]",
        "startDate": "[reservation start date]",
        "endDate": "[reservation end date]",
        "people": {
            "adults": [number of adults in the room],
            "children": [number of children in the room]
        }
    }

    Required fields:

    user, hotel, room, startDate, endDate, people

Response

  • Success Response:

    Status Code: 200 OK

    {
      "reservationId": "[reservation identifier]"
    }
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Invalid token."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "You are not allowed to make a reservation."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "The room is not available."
      }

      or

      Body:

      {
        "message": "Hotel does not exist."
      }

      or

      Body:

      {
        "message": "Room does not exist"
      }

      or

      Body:

      {
        "message": "Exceeded number of visitors."
      }

      or

      Body:

      {
        "message": "[Data validation error message]"
      }

Update reservation payment

It allows to update users reservation payment.

Request

PUT /api/reservations/pay/:id

  • Body No body data required.

  • Params

    :id - reservation identifier

Response

  • Success Response:

    Status Code: 200 OK

    {
      "success": true
    }
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Invalid token."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Reservation not found."
      }

Cancel a room reservation

It allows user to cancel a room reservation in the hotel.

Request

DELETE /api/reservations/:id

  • Body

    No body data required.

  • Params

    :id - reservation identifier

Response

  • Success Response:

    Status Code: 200 OK

    {
      "success": true
    }
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Invalid token."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "You are not allowed to cancel this reservation."
      }
    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Reservation not found."
      }

      or

      Body:

      {
        "message": "An error occurred while checking hotel owner."
      }

      or

      Body:

      {
        "message": "The reservation cannot be cancelled."
      }

Get all hotels for hotel owner

It allows the hotel owner to get all his hotels

Request

GET /api/hotelOwner/hotels

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
      {
        "description": "[hotel description]",
        "_id": "[hotel identifier]",
        "localization": {
          "_id": "[localization identifier]",
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
        },
        "phoneNumber": "[hotel phone number]",
        "name": "[hotel name]",
        "email": "[hotel email]",
        "rooms": [
          {
            "description": "[room description]",
            "_id": "[room identifier]",
            "roomNumber": "[room nuber]",
            "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
          },
            "price": [room price],
            "createdAt": "[created date]",
            "updatedAt": "[updated date]"
          }
        ],
        "ownerId": "[hotel owner identifier]",
        "clientsRates": [hotel clients rates],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
      }
    ]
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied."
      }

      or

      Body:

      {
        "message": "User is not verified."
      }

Add new hotel

It allows the hotel owner to add new hotel

Request

POST /api/hotelOwner/hotels

  • Body

    {
        "name": "[hotel name]",
        "description": "[hotel description]",
        "localization": {
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
        },
        "email": "[hotel email]",
        "rooms": [
          {
            "description": "[room description]",
            "roomNumber": "[room nuber]",
            "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
            },
            "price": [room price]
          }
        ],
    }

    Required fields:

    all localization fields, phoneNumber, name, email, roomNumber, beds, price

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
      {
        "description": "[hotel description]",
        "_id": "[hotel identifier]",
        "localization": {
          "_id": "[localization identifier]",
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
        },
        "phoneNumber": "[hotel phone number]",
        "name": "[hotel name]",
        "email": "[hotel email]",
        "rooms": [
          {
            "description": "[room description]",
            "_id": "[room identifier]",
            "roomNumber": "[room nuber]",
            "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
            },
            "price": [room price],
            "createdAt": "[created date]",
            "updatedAt": "[updated date]"
          }
        ],
        "ownerId": "[hotel owner identifier]",
        "clientsRates": [hotel clients rates],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
      }
    ]
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied."
      }

      or

      Body:

      {
        "message": "User is not verified."
      }

Update hotel

It allows the hotel owner to update hotel

Request

PUT /api/hotelOwner/hotels/:id

  • Body

    {
      "[hotel field]": "[new value]"
    }

Response

  • Success Response:

    Status Code: 200 OK

  • Body:

    [
      {
        "description": "[hotel description]",
        "_id": "[hotel identifier]",
        "localization": {
          "_id": "[localization identifier]",
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
        },
        "phoneNumber": "[hotel phone number]",
        "name": "[hotel name]",
        "email": "[hotel email]",
        "rooms": [
          {
            "description": "[room description]",
            "_id": "[room identifier]",
            "roomNumber": "[room nuber]",
              "beds": {
                "single": "[single beds number]",
                "double": "[double beds number]"
            },
            "price": [room price],
            "createdAt": "[created date]",
            "updatedAt": "[updated date]"
          }
        ],
        "ownerId": "[hotel owner identifier]",
        "clientsRates": [hotel clients rates],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
      }
    ]
  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Hotel not found."
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied."
      }

      or

      Body:

      {
        "message": "User is not verified."
      }

Delete hotel

It allows the hotel owner to delet hotel

Request

DELETE /api/hotelOwner/hotels/:id

  • Query

    It allows to remove a hotel even if they have any reservation.

    forceDelete = true

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Remove reservations first or check `force delete` flag"
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Forbidden"
      }

      or

      Body:

      {
        "message": "User is not verified."
      }

Add room to a hotel

It allows the hotel owner to add room to a hotel

Request

POST /api/hotelOwner/hotels/:id/addRoom

  • Body

    [
      {
        "description": "[room description]",
        "roomNumber": [room number]",
        "beds": {
          "single": "[single beds number]",
          "double": "[double beds number]"
        },
        "price": "[price]"
      }
    ]
    

    Required fields:

    roomNumber, beds, single, double, price

Response

  • Success Response:

    Status Code: 200 OK

    [
      {
        "description": "[hotel description]",
        "_id": "[hotel identifier]",
        "localization": {
          "_id": "[localization identifier]",
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
        },
        "phoneNumber": "[hotel phone number]",
        "name": "[hotel name]",
        "email": "[hotel email]",
        "rooms": [
          {
            "description": "[room description]",
            "_id": "[room identifier]",
            "roomNumber": "[room nuber]",
            "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
            },
            "price": [room price],
            "createdAt": "[created date]",
            "updatedAt": "[updated date]"
          }
        ],
        "ownerId": "[hotel owner identifier]",
        "clientsRates": [hotel clients rates],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
      }
    ]
  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Hotel with provided ID was not found."
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Forbidden"
      }

      or

      Body:

      {
        "message": "User is not verified."
      }

Get all hotels

It allows to get all hotels

Request

GET /api/hotels

  • Query

    pageNumber = [ page number ] pageSize = [ page size ] city = [ "city" ]

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "hotels":[
          {
          "description": "[hotel description]",
          "_id": "[hotel identifier]",
          "localization": {
              "_id": "[localization identifier]",
              "city": "[localization city]",
              "country": "[localization country]",
              "zipcode": "[localization zipcode]",
              "street": "[localization street]",
              "buildingNumber": [localization building number]
          },
          "phoneNumber": "[hotel phone number]",
          "name": "[hotel name]",
          "email": "[hotel email]",
          "rooms": [
              {
              "description": "[room description]",
              "_id": "[room identifier]",
              "roomNumber": "[room nuber]",
              "beds": {
                "single": "[single beds number]",
                "double": "[double beds number]"
              },
              "price": [room price],
              "createdAt": "[created date]",
              "updatedAt": "[updated date]"
              }
          ],
          "ownerId": "[hotel owner identifier]",
          "clientsRates": [hotel clients rates],
          "createdAt": "[created date]",
          "updatedAt": "[updated date]"
          }
      ],
      "pages": [pages number]
    }
  • Error Response:

    No error

    Get all available hotels

It allows to get all hotels

Request

GET /api/hotels/getAvailable

  • Query

    pageNumber = [ page number ] pageSize = [ page size city = [ "page number" ] adults = [ "adults number" ] children = [ "children number" ] startDate = [ "start date" ] endDate = [ "end date" ]

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "hotels":[
          {
          "description": "[hotel description]",
          "_id": "[hotel identifier]",
          "localization": {
              "_id": "[localization identifier]",
              "city": "[localization city]",
              "country": "[localization country]",
              "zipcode": "[localization zipcode]",
              "street": "[localization street]",
              "buildingNumber": [localization building number]
          },
          "phoneNumber": "[hotel phone number]",
          "name": "[hotel name]",
          "email": "[hotel email]",
          "rooms": [
              {
              "description": "[room description]",
              "_id": "[room identifier]",
              "roomNumber": "[room nuber]",
              "beds": {
                "single": "[single beds number]",
                "double": "[double beds number]"
              },
              "price": [room price],
              "createdAt": "[created date]",
              "updatedAt": "[updated date]"
              }
          ],
          "ownerId": "[hotel owner identifier]",
          "clientsRates": [hotel clients rates],
          "createdAt": "[created date]",
          "updatedAt": "[updated date]"
          }
      ],
      "pages": [pages number]
    }
  • Error Response:

    No error

Get limited amount hotels

It allows to get limited amount hotels

Request

GET /api/hotels/getLimitedHotels/:limit

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
        {
        "description": "[hotel description]",
        "_id": "[hotel identifier]",
        "localization": {
            "_id": "[localization identifier]",
            "city": "[localization city]",
            "country": "[localization country]",
            "zipcode": "[localization zipcode]",
            "street": "[localization street]",
            "buildingNumber": [localization building number]
        },
        "phoneNumber": "[hotel phone number]",
        "name": "[hotel name]",
        "email": "[hotel email]",
        "rooms": [
            {
            "description": "[room description]",
            "_id": "[room identifier]",
            "roomNumber": "[room nuber]",
            "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
            },
            "price": [room price],
            "createdAt": "[created date]",
            "updatedAt": "[updated date]"
            }
        ],
        "ownerId": "[hotel owner identifier]",
        "clientsRates": [hotel clients rates],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
        }
    ]
  • Error Response:

    No error

Get hotel by id

It allows to get hotel by id

Request

GET /api/hotels/:id

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    {
      "description": "[hotel description]",
      "_id": "[hotel identifier]",
      "localization": {
          "_id": "[localization identifier]",
          "city": "[localization city]",
          "country": "[localization country]",
          "zipcode": "[localization zipcode]",
          "street": "[localization street]",
          "buildingNumber": [localization building number]
      },
      "phoneNumber": "[hotel phone number]",
      "name": "[hotel name]",
      "email": "[hotel email]",
      "rooms": [
          {
          "description": "[room description]",
          "_id": "[room identifier]",
          "roomNumber": "[room nuber]",
          "beds": {
              "single": "[single beds number]",
              "double": "[double beds number]"
          },
          "price": [room price],
          "createdAt": "[created date]",
          "updatedAt": "[updated date]"
          }
      ],
      "ownerId": "[hotel owner identifier]",
      "clientsRates": [hotel clients rates],
      "createdAt": "[created date]",
      "updatedAt": "[updated date]"
    }
  • Error Response:

    • Status Code: 404 Not found

      Body:

      {
        "message": "Hotel not found."
      }

Get available hotel rooms

It allows to get available hotel rooms

Request

GET /api/hotels/:id/availableRooms

  • Query

    startDate = [ "start date" ] endDate = [ "end date" ] adults = [ "adults number" ] children = [ "children number" ]

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
        {
        "description": "[room description]",
        "_id": "[room identifier]",
        "roomNumber": "[room nuber]",
        "beds": {
          "single": "[single beds number]",
          "double": "[double beds number]"
        },
        "price": [room price],
        "createdAt": "[created date]",
        "updatedAt": "[updated date]"
        }
    ]
  • Error Response:

    • Status Code: 404 Not found

      Body:

      {
        "message": "Hotel not found."
      }

Get all users

It allows the administrator to get all users

Request

GET /api/admin/users

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
        {
            "isVerified": [true | false],
            "role": "[role of the user (user | hotelOwner)]",
            "_id": "[user identifier]",
            "email": "[user email address]"
            "password": "[user password]",
            "firstName": "[user first name]",
            "lastName": "[user last name]",
            "phoneNumber": "[user phone number]",
            "tin": "[tax identification number of the hotel owner]"
            "isSmsAllowed": [true | false],
        }
    ]
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Forbidden"
      }

Get all hotel owners

It allows the administrator to get all hotel owners

Request

GET /api/admin/hotelOwner

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

    Body:

    [
        {
            "isVerified": [true | false],
            "role": "[role of the user (user | hotelOwner)]",
            "_id": "[user identifier]",
            "email": "[user email address]"
            "password": "[user password]",
            "firstName": "[user first name]",
            "lastName": "[user last name]",
            "phoneNumber": "[user phone number]",
            "tin": "[tax identification number of the hotel owner]"
            "isSmsAllowed": [true|false],
        }
    ]
  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Forbidden"
      }

Change user role to hotel owner

It allows the administrator to change user role

Request

PUT /api/admin/acceptUserToHotelOwner/:id

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied"
      }

Verify hotel owner

It allows the administrator to verify hotel owner

Request

PUT /api/admin/verifyHotelOwner/:id

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied"
      }

Remove hotel owner

It allows the administrator to remove hotel owner

Request

DELETE /api/admin/hotelOwner/:id

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Remove hotel(s) first"
      }

      or

      Body:

      {
        "message": "Hotel owner with provided id not found"
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied"
      }

Remove users

It allows the administrator to remove users

Request

DELETE /api/admin/users

  • Query

    It allows to remove a user even if they have any reservation.

    forceDelete = true

  • Body

    ;['user identifier']

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "User not found"
      }

      or

      Body:

      {
        "message": "Remove reservations first"
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied"
      }

Remove hotels

It allows the administrator to remove users

Request

DELETE /api/admin/hotels/:id

  • Query

    It allows to remove a hotel even if they have any reservation.

    forceDelete = true

  • Body

    No body data required.

Response

  • Success Response:

    Status Code: 200 OK

  • Error Response:

    • Status Code: 400 Bad Request

      Body:

      {
        "message": "Hotel not found"
      }

      or

      Body:

      {
        "message": "Remove reservations first"
      }
    • Status Code: 401 Unauthorized

      Body:

      {
        "message": "Access denied."
      }
    • Status Code: 403 Forbidden

      Body:

      {
        "message": "Access denied"
      }

booking-clone-api's People

Contributors

bartoszbialecki avatar gorajakub avatar hoolek77 avatar ibednorz avatar pdybowski avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

ibednorz

booking-clone-api's Issues

redo reservation route

allow user or hotel owner to see reservations
allow user or hotel owner to make a reservation
allow user to remove their reservations
pay for a reservation

some of them should be done

API call - hotel owner panel

GET get hotels for logged hotel owner
POST add new hotel
PUT edit hotel
POST/DELETE to delete hotel (is reserved - error)
POST remove client reservation - when room is not paid and there are more then 3 days

all of these need auth

Fix hotel validation and routes for hotel owner

Validation:
validate object does not have required validations

Hotel Owner:
DELETE:
When deleting hotel we should check if hotel exists

Hotel Owner:
GET:
we should get hotels only for logged in hotel owner, not all hotels

image

Deploy on heroku

Main will be connected to the heroku server

"user": "[email protected]",
"pass": "BOOKINGcloneAPI"

heroku command to set variables:

  • heroku config:set NODE_ENV=production
    (remember NOT TO use string)
  • heroku config - shows what variables are set

env variables to set:
NODE_ENV="production"
JWT_PRIVATE_KEY="whatever"
bookingclone_db=stringToOurDataBaseThatWeCreate

make sure that bookingclone_db is in custom_environment-variables.json file
like below:
"db": "bookingclone_db"

lets sat in default.json we have "db" variable with mongodb//localhost bla bla
to change it to the productino we need to add mapping to this variable in custom-env-var file

OR

in our case if you dont want to change everyhing you have to figure it out what is what

link to our production db will look like that:
image

of course password and user name must be changed to what we have

registration and login

req:
required from users schema:
username
password
firstName
secondName
email

optional
PhoneNumber
isOwner
tin (coś jak NIP)

prepare super admin and hotel owner

fix room and localization schema (effort 3)

room shouldnt have hotelId
zip code should be string
number should be a function in validation

check imports and exports everywhere,
check eg. if hotelId(etc) is changed to hotel and change wherever it is needed. Schema has been changed

remove Address from models/adrress.js
remove Room from models/room.js

remember to change it in rotues, schemas and other models

test it

Schema with reservations

_id - reservation id (pamiętać żeby było w mongodb)
hotelId
roomId
startDate
endDate
people: {
adult
children
}
createDate (pamiętać żeby było w mongodb)
updateDate (pamiętać żeby było w mongodb)
isPaid

add route for an admin

GET:
all users

POST:
delete users, body should be table with users ids.
We should check if some user has any reservation
if we cant delete user we should response with array of objectes:
[
{
userId: 2312312,
error: "cos tam sie nie powiodlo"
}
]

PUT:
change hotel owner status

DELETE:
remove hotel (check remove Hotel by owner diagram)
force flag

API call - hotels

GET 5-6 hotels
GET available hotels by startDate/endDate/city
GET hotel by id
GET all hotels

all of these DO NOT need auth

mail/sms

send email and sms (if phone number is provided) after registration

send email and sms (if phone number is provided) after acceptation by super admin(related only to hotel owner)

send email and sms (if phone number is provided) after reservation

send email and sms (if phone number is provided) after removal by super admin

send email and sms (if phone number is provided) when users reservation has been removed

send email and sms (if phone number is provided) when there are 5 days left

Schema with users

body:
userName
firstName
secondName
email
password
phoneNumber?
role: "user" | "hotelOwner" | "admin"
reservationId Array
createDate (pamiętać, żeby dodać w mongo)
updateDate (pamiętać, żeby dodać w mongo)
isVeirifed - false by deafult (related to hotel owner)
tin - undefined/null by deafult (related to hotel owner)

Schema with hotels

_id - hotel id
ownerId
localisation (city, etc)
phoneNumber
name
clientsRate
email
stars
description
rooms: [
{
roomId
beds: {
single: number
double: number
}
price
description
}
]

add 'force remove hotel' endpoint

hotel owner should be able to remove hotel with resrvations as well.
You can modify current endpoint and add query param to the request endpoint

remove all reservations when flag is set to true

change message to:
if (reservation.length > 0)
return res.status(400).send('Remove reservations first, please')

when hotel was deleted successfuly send all hotels for this owner

move validations from model folder to vaidations folder (effort 3)

move validations from model folder to vaidations folder

and

UPDATE: owner/hotel
we should only verify properties that we want to change, we dont need to send whole object there
validateHotel, everything should be required (check hotel schema and add new one if necessary)

login

authentication
req:
userName and password
res:
token - userId, userName

API call - reservation

user panel:
GET all reservations for a user

POST add new reservation
body: hotelId, roomId, startDate, endDate, adults, children, isPaid, userId

all of these need auth

add pagination route to the hotels (effort: 2)

We should have a router to get pagination hotels. There are two ways we can make it.

  1. Using offset and limit
  2. Using cursor and limit

Second one is more safer. Read some docs on the internet. I guess in our case we can use first or second option.

=====

it should be public (no specified tokens)
or you can just edit existing route by adding query to it. Probably better way is to add new route. You have to choose what you prefer

image

see example:

image

fix admin route (effort 3)

get all users:
filter out admins
remove email from path, instead add userId

remove email from each path and instead pass ids

change owner status:

image

check this error in each update function (in the app)

Add route for pagination

We should have a router to get pagination hotels. There are two ways we can make it.

  1. Using offset and limit
  2. Using cursor and limit

Second one is more safer. Read some docs on the internet. I guess in our case we can use first or second option.

API all - admin

GET all hotel owners
GET all users
PUT (accept) hotel owner
POST/DELETE remove hotel owner by userName or email
POST/DELETE remove user by userName or email

all of these need auth

connect local server with production or local db

Fill Development.json file in config folder.
Production.json should have properties but their value must be empty string

Nodejs will automatically use prod or dev file depends on node_env variable

Add new hotel by hotel owner (effort 2)

room shouldnt have hotelId
zip code should be string
number should be a function
we should send just status, we dont need empty object in the response

remove room from collection

chec schema, models whatever you need

tests

add some unit tests using jest or whatever you like
just a few we dont want to waste time for that

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.