Giter VIP home page Giter VIP logo

trbo-coding-task's Introduction

Trbo Test Task Project

I have chosen the Express.js backend framework, utilizing TypeScript for its numerous advantages. Additionally, I have integrated it with MySQL to handle normalized data. It's worth noting that MongoDB could have been an alternative choice considering the nature of the data. For testing purposes, I've employed JEST as the test suite. All service dependencies are provided through a docker-compose stack.

Requirements

  • node 18+
  • npm 9+
  • Recommended: docker plus docker compose

Getting started

  1. Create your own .env from .env.example
  2. npm install
  3. docker-compose up -d
  4. npm run dev

Endpoints

GET /product/import (accepts a product feed as csv file and imports it. Allowed fields: id, title, category, price, sale_price, explanation and stock. Comma must be used as delimiter)
Parameters

None

Responses
http code content-type response
200 application/json { message: 'Products saved successfully' }
400 application/json { message: 'Invalid CSV file' }
406 application/json { message: 'Could not import any products, File is empty or could not be parsed' }
GET /product/list (lists products)
Parameters
name type data type description
sortBy optional string key to sort with, allowed values (id, title, price, sale_price', stock, last_update), must be supplied with sortOrder
sortOrder optional string direction of sort, allowed values (DESC, ASC), must be supplied with sortBy
filterBy optional string filters the list of products by the specified key, must be supplied with filterValue
filterValue optional string filters the list of products by the specified value, must be supplied with filterKey
Responses
http code content-type response
200 application/json JSON string
500 application/json { message: "Could not fetch the list" }
GET /product/recommendations/:sku (retrieves product recommendations)
Parameters
name type data type description example
sku required query path The SKU of the article where you wish recommendations for /product/recommendations/1
Responses
http code content-type response
200 application/json [ { "product_id": 1, "recommended_product_id": 2, "frequency": 4 }, { "product_id": 2, "recommended_product_id": 1, "frequency": 4 } ]
404 application/json { message: Product with SKU XXXX could not be found} }
500 application/json { message: '"Error happend while fetching recommendations"' }
POST /product/sell (submit orders)
Parameters
name type data type description example
products required JSON Array of Objects {"products": [ { "sku": "10", "quantity": 5 }, { "sku": "3", "quantity": 4 } ] }
Responses
http code content-type response
200 application/json { message: 'Products saved successfully' }
404 application/json { message: Product with SKU XXX could not be found }
500 application/json { message: 'Error while saving order' }

Tests

How to run them

npm run test

Important: keep in that unit tests might run against the database specified in the .env file.

Refactoring

This is an MVP. During refactoring, a validator like 'express-validator' should be used to improve input validation and sanitization. For parsing CSV files, a package like 'csv-parser' should be employed. Currently, 'mysql2' is used as the client for the MySQL connection. To enhance testability and simplify replacement, accessing the package's methods without a wrapper should be avoided. Unfortunately, due to time constraints, this was no longer feasible."

trbo-coding-task's People

Contributors

advkarl avatar

Watchers

Karl Magerl avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.