Skip to content

irwin-r/ooh-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ooh-api

Version

A RESTful API for managing shopping centre locations & their respective assets.

Foreword/Rationale

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

Checklist

  • 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

Regrets/Thoughts

  • 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 :(

Requirements

  • Node.js 10.x
  • Postgres
  • Yarn

Install

yarn

Usage

The following environment variables are exposed to you to configure the application:

  • DATABASE_DIALECT -- defaults to postgres
  • DATABASE_HOST
  • DATABASE_NAME
  • DATABASE_PASSWORD
  • DATABASE_PORT
  • DATABASE_USERNAME
  • LISTEN_PORT -- defaults to 3000
  • NODE_ENV -- must be defined, or you can use yarn start:local for local development
yarn start

Run tests

yarn test

Author

👤 Irwin Razaghi [email protected]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published