Coder Social home page Coder Social logo

node-db2-project's Introduction

Node DB2 Project Starter Code

Introduction

In this challenge, you will write an API that can be used to manage Cars stored in a Relational Database.

Instructions

Task 1: Project Setup and Submission

Your assignment page on Canvas should contain instructions for submitting this project. If you are still unsure, reach out to School Staff.

Task 2: Minimum Viable Product

Build a RESTful API for an "cars" resource. The client for this API is a car dealer.

Cars Schema

The critical information for each car is the vin, make, model, and mileage. They also track transmission type (manual, automatic...) and status of the title (clean, salvage...), but this information is not always immediately known. Write the "up" and "down" functions inside the data/migrations/01-make_cars_table.js migration file to satisfy the following schema:

field data type metadata
id unsigned integer primary key, auto-increments, generated by database
vin string required, unique
make string required
model string required
mileage numeric required
title string optional
transmission string optional

Write Model Functions

  • Write the following db access functions inside api/cars/cars-model.js using Knex:

    • getAll resolves to an array of car records (or an empty array)
    • getById resolves to a car record by the given id
    • create resolves to the newly created car record

Write Middleware

  • Write the following middlewares inside api/cars/cars-middleware.js:

    • checkCarId returns a status 404 with a { message: "car with id <car id> is not found" } if the id in req.params does not exist in the database.

    • checkCarPayload returns a status 400 with a { message: "<field name> is missing" } if any required field is missing.

    • checkVinNumberValid returns a status 400 with a { message: "vin <vin number> is invalid" } if the vin number is invalid.

    • checkVinNumberUnique returns a status 400 with a { message: "vin <vin number> already exists" } if the vin number already exists in the database.

Write a Cars API

  • Write CR (of CRUD) for the cars resource, using the middleware and model functions described above wherever appropriate inside api/cars/cars-router.js :

    • [GET] /api/cars returns an array of cars sorted by id (or an empty array if there aren't any).
    • [GET] /api/cars/:id returns a car by the given id.
    • [POST] /api/cars returns the created car.
  • Manually test your endpoints with a REST client like Insomnia or Postman to check they are working as expected.

  • Test your endpoints automatically by running npm test.

Notes

  • Test your work manually using Postman or HTTPie. Run automatic tests by executing npm test.
  • You are welcome to create additional files but do not move or rename existing files or folders.
  • Do not alter your package.json file except to install additional libraries or add additional scripts. Do not update existing libs.
  • In your solution, it is essential that you follow best practices and produce clean and professional results.

Task 3: Stretch Problems

  • Add seed data to the database using knex seeds
  • Add [PUT] and [DELETE] operations to your API.
  • Write a schema file for a sales table. This table should track information on the sale of each car. You may wish to research foreign keys in order to link each sale to the entry in cars which sold.

node-db2-project's People

Contributors

ericathompson avatar jamesblacklock avatar ladrillo avatar luishrd avatar mixelpixel avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-db2-project's Issues

License

What is the license of this repo?

We run a non profit called NavGurukul where we are teaching coding to the underprivileged students in India. It gives them access to careers which they couldn't think of before as all of them lack access to a decent higher education.

Was thinking if we can use them there?

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.