Elevators is split into three layers. Service, simulation and state.
-
Service layer is a koa app with router and middlewares handling requests.
-
Simulation layer handles all business logic of elevators.
NOTE: Elevator algorithm is simple FIFO, but the design should make it easy to improve.
-
State layer handles data. It could be replaced with database to keep the data persistent between server resets.
Clone repo and go inside it:
git clone [email protected]:czaaru/elevators-api.git
cd elevators-apiMake sure node is running correct version and install dependencies:
nvm use
yarnStart in dev mode:
yarn start:watchRun tests in watch mode:
yarn jest --watchAll request return list of elevators following type:
enum Direction {
UP = 1,
DOWN = -1,
NONE = 0,
}
interface Elevator {
currentFloor: number;
destinations: number[];
direction: Direction;
}
type ResponseBody = Record<number, Elevator>;GET /elevators- return current state of applicationPOST /elevators- create elevator with id posted in bodyPOST /elevators/pickup- add floor to destination of one of the elevatorsPUT /elevators/:id- update elevator of id with posted bodyPOST /simiulation/step- do a step in a simulationDELETE /simulation/reset/- reset elevators to initial state
This repository uses travis to test and typecheck the application before deploying automatically to Heroku.