Design and develop a simple REST (convertible to graphQL on a special route) service to power the different features on screens - Home/Index, Details, Cart and Search of this UI Prototype. This is the source code for the assessment.
- Language: Javascript/NodeJS
- Main libraries: node, express, sequelize, sequelize-cli, pg, jest
- Database: PostgreSQL
- External dependencies
- Install PostgreSQL for development.
- Installation
- Install node v14 and yarn (
npm i -g yarn
) - Install dependencies using
yarn
- Install node v14 and yarn (
- Configuration
- Copy
.env.example
to.env
and fill it in with appropriate information
- Copy
- Running
- In development only:
- Use
npx sequelize-cli db:migrate
to run migration file and create all tables in the database. - For the first time run SQL file located at root/seeders/db_seeders.sql on your Postgres database, To seed dummy data and ALTER tables for search functionality.
- Use
yarn test
to run test. - Serve the application using
yarn start
. - both test and start use the same port so one should run at a time.
- To run test, make sure server is not running. else shut down and run
yarn test
- server runs at https://localhost:4000 by default. register on the system using https://localhost:4000/api/v1/register on curl or postman
- Endpoints located at the routes' folder.
- Use
- In development only:
- I assumed that for this service to be secured we needed an authentication system which I implemented along with.
- Test on all features (endpoints)
- none
- For real time implementation of the likes and ratings I would have made use of a service like pusher to integrate into the application if there was more the time.
- Replacing the implemented 'full-text' search with 'Elastic' search for the search feature to improve performance and speed of execution (Although this is also optimal to an extent).
-
- Relationships
- hasOne: Cart
- Attributes/Datatypes
- accUUID/UUID: PK, Auto Increment
- emailVerified/bool: default:false
- uniqueString/text: notNull, for email verification
- email/string: notNull,
- password/string: notNull,
- role/enum: default:user
- Relationships
-
- Relationships
- hasMany: Books
- Attributes/Datatypes
- genreName/string: notNull
- Relationships
-
- Relationships
- hasMany: Likes
- hasMany: Ratings
- belongsTo: Genre
- belongsToMany: Tags
- belongsToMany: Authors
- Attributes/Datatypes
- title/string
- genreId/reference
- description/text
- imagePath/string
- price/double
- copies/integer
- publisher/string
- featured/boolean
- releasedDate/date
- Relationships
-
- Relationships
- belongsToMany: Books
- Attributes/Datatypes
- tagName/string: notNull
- Relationships
-
- Attributes/Datatypes
- bookId/reference: notNull
- tagId/reference: notNull
- Attributes/Datatypes
-
- Relationships
- belongsTo: User
- belongsTo: Book
- Attributes/Datatypes
- rating/double: notNull (0 - 5)
- userId/reference
- bookId/reference
- Relationships
-
- Relationships
- belongsTo: User
- belongsTo: Book
- Attributes/Datatypes
- userId/reference
- bookId/reference
- Relationships
-
- Relationships
- belongsToMany: Books
- Attributes/Datatypes
- name/string: notNull
- Relationships
-
- Attributes/Datatypes
- bookId/reference: notNull
- authorId/reference: notNull
- Attributes/Datatypes
-
- Relationships
- belongsTo: User
- hasMany: Item
- Attributes/Datatypes
- subTotal/double: default:0
- Relationships
-
- Relationships
- belongsTo: Cart
- belongsTo: Book
- Attributes/Datatypes
- quantity/integer
- Relationships