A RESTful API for managing shopping centre locations & their respective assets.
I'm a big fan of frameworks like Nest, which make it really hard to do the wrong thing. In a technical test, however, that's probably not the best way to demonstrate understanding or skill.
So, with this technical test, I've opted to utilise a relatively vanilla Express solution with little in the way of external dependencies. At present, I've only really used the following:
- Boom - Hapi's library which makes it cleaner to throw exceptions
- Celebrate - A wrapper around Hapi's Joi, providing payload JSON schema validation
- Pino - A very fast logging library, although in hindsight, there wasn't much logging :p
- Sequelize - By far the heaviest dependency in the project. A full-blown, multi-flavour, SQL ORM
Also, none of this was derived from any third-party boilerplate. Feel free to scrutinise the commit history to see how this project got to where it is :P
- MUST have an API server written in JavaScript
- MUST have routes for Shopping Centres
- MUST have routes for Assets
- MUST persist data to a database using some flavour of SQL
- MUST be secured against anonymous access
- MUST contain tests using a testing framework
- SHOULD track which user makes changes to the data
- SHOULD allow marking Assets “inactive” for when they’re receiving maintenance, and re-activating them later
- COULD have a UI (but don’t worry about UX)
- COULD support searching for Assets by Name, Shopping Centre, or Status
- ESM (ECMAScript Modules -- .mjs) rock, but there are many gotchas around them;
- A lot of libraries (i.e. Celebrate, Sequelize) don't have their exports defined in a manner which allows you to directly grab them from an
import
directive. - As ESM are still in an experimental phase, there's no support for stubbing/proxying objects, which makes testing difficult
- With the above in mind, we're forced to leverage a third-party Sequelize library to provide mocks, which does a sub-par job and doesn't handle querying well nor does it allow C/U/D operations.
- Having not used Sequelize in a while, nor previously in conjunction with ESM, these issues were an unpleasant surprise :P
- ORMs make a case against DAOs as you're essentially doubling up in a lot of areas, but DAOs and the CQRS pattern are great for testability. That said, as a result of ESMs not supporting function proxying, their use case was invalidated in this example :(
- Node.js 10.x
- Postgres
- Yarn
yarn
The following environment variables are exposed to you to configure the application:
DATABASE_DIALECT
-- defaults topostgres
DATABASE_HOST
DATABASE_NAME
DATABASE_PASSWORD
DATABASE_PORT
DATABASE_USERNAME
LISTEN_PORT
-- defaults to3000
NODE_ENV
-- must be defined, or you can useyarn start:local
for local development
yarn start
yarn test
👤 Irwin Razaghi [email protected]
- Github: @irwin-r