Skip to content

About

Historical 2019 Node.js interview exercise for hotel-room allocation, constraint parsing and controller tests; current runtime reproduction remains unverified.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

Hotel Booking Constraint API

A historical 2019 interview exercise in Node.js/Express: allocate guests to rooms using a small rule parser, with controller tests for accepted and rejected bookings. This repository demonstrates an earlier approach to business-rule modeling; it has not been modernized or assessed as a production booking service.

Current engineering portfolio · Professional work and contact

Problem and constraints

The API accepts guest counts under bookings and returns room assignments or an error array. The original rule definitions and allocation branches are in ApiController.js:

  • Guest categories are adult, children and infant.
  • The booking-wide capacity check counts adults and children together, with a maximum of seven; infants are excluded from that count.
  • Room rules set a maximum of three for each category. Children and infants require an accompanying adult.
  • The implementation distributes adults across rooms and handles minors in separate allocation branches. This is a specific exercise implementation, not a general allocation solver or a guarantee that every input ordering and boundary works.

These describe the checked-in rules, not a newly recovered or expanded interview specification.

API examples

routes/index.js defines GET /api and POST /api/booking. The health response is {"message":"API Endpoint"}.

Example request to POST http://localhost:3000/api/booking:

{"bookings":{"adult":6}}

Response:

{"booking":{"rooms":[{"adult":3},{"adult":3}]}}

Over-capacity request:

{"bookings":{"adult":6,"children":2,"infant":1}}

Response:

{"error":["Too many guests"]}

The original README showed that second request as a success. It exceeds the implemented non-infant capacity and has been corrected here. The original examples and historical test transcript remain in the 2019 README at its recorded revision.

Constraint-parser design

initConstraint reads min/max conditions and one level of dependent guest-category conditions from the rule objects. checkConstraintForMultipleRooms derives qualification information; booking performs allocation and formats errors. The intent was reuse across similar rules, but parsing and allocation remain in the same controller. The booking-wide capacity check is separate from the parser, and allocation contains duplicated category branches.

This separation is worth inspecting alongside its limits: coercive parseInt handling is not strict integer/schema validation, and the code iterates request properties while constructing rooms. No claim of complete malformed-input handling or optimal allocation is made.

Tests and verification

test/test.js contains Mocha/Chai tests using mocked Express requests/responses for adult-only, mixed-guest, over-capacity, missing-data and rule-validation cases. These call controller functions; they do not establish a deployed HTTP service.

The original README recorded 25 passing tests (283 ms) in 2019. That is historical output, not a newly executed suite result. No dependency installation or full application/test run was performed for this documentation update. A bounded dependency-free controller probe confirmed the two examples above using the source with only its export function keywords removed for a Node VM context. It also observed an initialization error for a mixed request of four adults, two children and one infant under direct current-JavaScript semantics; this probe does not reproduce the original Babel toolchain.

Historical local setup

The repository has npm/Babel configuration but no committed lockfile or Node version pin. Inspect package.json, .babelrc and nodemon.json before attempting an isolated local reproduction.

Original commands:

npm install
npm run prod
npm test

These are retained as historical instructions, not verified current setup:

  • dev and prod invoke npm-run-all, which is not declared in package.json.
  • The test script uses a Windows-style executable path; it is not portable as written to a POSIX shell.
  • prod cleans/builds with Babel and starts a nodemon/Babel watcher. It is not a production deployment procedure.
  • The original Windows instructions suggested installing win-node-env; it is not a committed dependency.
  • Dependency ranges are old and unlocked. Compatibility, vulnerabilities and a reproducible installation require separate maintenance work.

The server uses port 3000 by default. No current hosted deployment is verified; the old “deployment in progress” note has been retired. No runtime, dependency, script or hosting changes are included in this documentation update.

Limitations and license

This is an interview artifact with incomplete runtime verification, coercive input handling and known allocation/tooling concerns. Do not treat it as a current security or production-readiness example. It remains available for historical inspection alongside the current public engineering projects.

The existing GNU GPL v3 license is unchanged. Original implementation and commit history are preserved.

About

Historical 2019 Node.js interview exercise for hotel-room allocation, constraint parsing and controller tests; current runtime reproduction remains unverified.

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages