{"id":16327364,"url":"https://github.com/willsams/example-hotel-reservation-system","last_synced_at":"2026-01-27T02:02:44.307Z","repository":{"id":79214411,"uuid":"462082621","full_name":"WillSams/example-hotel-reservation-system","owner":"WillSams","description":"An example is a JavaScript GraphQL API that allows the creation and listing of reservations, along with the ability to list available rooms for a given date range.","archived":false,"fork":false,"pushed_at":"2024-11-19T11:09:18.000Z","size":1200,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-30T09:01:42.795Z","etag":null,"topics":["apollo-server-hapi","direnv","docker","graphql","graphql-api","hapijs","knexjs","nodejs","nvm","postgresql"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/WillSams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"ko_fi":"samswebs"}},"created_at":"2022-02-22T00:46:44.000Z","updated_at":"2024-09-02T23:35:10.000Z","dependencies_parsed_at":"2023-12-15T00:27:00.914Z","dependency_job_id":"64dd3c25-8ddc-474c-970b-b9a19cd5d0ae","html_url":"https://github.com/WillSams/example-hotel-reservation-system","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/WillSams/example-hotel-reservation-system","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fexample-hotel-reservation-system","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fexample-hotel-reservation-system/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fexample-hotel-reservation-system/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fexample-hotel-reservation-system/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/WillSams","download_url":"https://codeload.github.com/WillSams/example-hotel-reservation-system/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/WillSams%2Fexample-hotel-reservation-system/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28796962,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-27T01:07:07.743Z","status":"online","status_checked_at":"2026-01-27T02:00:07.755Z","response_time":168,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apollo-server-hapi","direnv","docker","graphql","graphql-api","hapijs","knexjs","nodejs","nvm","postgresql"],"created_at":"2024-10-10T23:11:14.724Z","updated_at":"2026-01-27T02:02:44.290Z","avatar_url":"https://github.com/WillSams.png","language":"JavaScript","funding_links":["https://ko-fi.com/samswebs"],"categories":[],"sub_categories":[],"readme":"# Hotel Reservation System\n\nCompleted as part of a weekend code challenge, simulates booking reservations in a hotel.  Please see the following `Pre-req` section before attempting to process reservations.\n\n**Usage:**\n\n```bash\n# List all existing booked reservations\ncurl http://localhost:$API_PORT/graphql \\\n    -H 'Content-Type: application/json' \\\n    -d '{\"query\": \"query { reservations { RoomId CheckinDate CheckoutDate  } }\"}'\n\n# Create a new reservation\n# Note: if there is an overlap, you'll see a \n#   'Reservation dates overlap with an existing reservation' error message\n# To see the aforementioned error, run this mutation a multiple times\ncurl http://localhost:$API_PORT/graphql \\\n    -H 'Content-Type: application/json' \\\n    -d '{ \"query\": \"mutation { createReservation( input: { roomId: \\\"91754a14-4885-4200-a052-e4042431ffb8\\\", checkinDate: \\\"2020-12-31\\\", checkoutDate: \\\"2021a-01-02\\\", totalCharge: 111 }) { Id RoomId CheckinDate CheckoutDate TotalCharge } }\" }'\n\n# List Available Rooms for a given date range\ncurl http://localhost:$API_PORT/graphql \\\n    -H 'Content-Type: application/json' \\\n    -d '{\"query\": \"query { availableRooms( startDate: \\\"2023-12-31\\\", endDate: \\\"2024-01-02\\\" numBeds: 1, allowSmoking: false) { Id NumBeds AllowSmoking DailyRate CleaningFee } }\" }'\n```\n\n## Pre-requisites\n\nAlthough Apple Mac links are also provided, the instructions below are more reliable for Debian-based distros (Ubuntu, Linux Mint, etc.) but they can also work under [Windows using the Windows Subsystem for Linux (WSL)](https://docs.microsoft.com/en-us/windows/wsl/about).  The following tools need to be installed:\n\n- [Direnv](https://direnv.net) to load environment variables needed for this project.  Simply executing `sudo apt install direnv` in your terminal (command line) should work in most cases.\n- [Docker](https://www.docker.com) to simplify usage of our Postgres SQL RDBMS dependency for development \u0026 testing.  If on Debian-based distro, see instructions below if Docker is not already installed.\n- [NodeJS](https://nodejs.org/en/download/).\n- [nvm](https://github.com/nvm-sh/nvm) - Used to manage NodeJS versions.\n\n## Install Node Packages\n\nExecute the following within your terminal:\n\n```bash\nnvm use             # To eliminate any issues, install/use the version listed in .nvmrc. \nnpm i               # install the packages needed for project \n```\n\n## Create the database\n\nFinally, let's create and seed the databases and our Reservations and Rooms tables:\n\n```bash\n# Create the databases and seed them\ncd src/db\nNODE_ENV=development | ./create_db.sh \u0026\u0026 npm run refresh\nNODE_ENV=test | ./create_db.sh \u0026\u0026 npm run refresh\n```\n\n## Running the script\n\nStart the GraphQL API by running in the background `npm run dev \u0026`.\n\nExecute `npm run process_requests` to book the reservations listed in `requests.json`.  Each request are processed in the order provided as if they were real-time requests.  The following rules are observed:\n\n- When a room is reserved, it cannot be reserved by another guest on overlapping dates.\n- Whenever there are multiple available rooms for a request, the room with the lower final price is assigned.\n- Whenever a request is made for a single room, a double bed room may be assigned (if no single is available?).\n- Smokers are not placed in non-smoking rooms.\n- Non-smokers are not placed in allowed smoking rooms.\n- Final price for reservations are determined by daily price * num of days requested, plus the cleaning fee.\n\nVerification can be achieved by matching the [`answers.json`](./src/answers.json) to the output of the following API request:\n\n```bash\ncurl -X POST \\\n-H \"Content-Type: application/json\" \\\n-d '{ \"query\":\"query { reservations { Id RoomId CheckinDate CheckoutDate TotalCharge } }\" }' \\\nhttp://localhost:4000/graphql\n```\n\nAlternatively, [Apollo's GraphQL Studio](https://studio.apollographql.com) can be accessed in your web browser via `http://localhost:4000/graphql`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillsams%2Fexample-hotel-reservation-system","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillsams%2Fexample-hotel-reservation-system","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillsams%2Fexample-hotel-reservation-system/lists"}