Skip to content
437 lines of Node/Express.js: routes and middleware for my to do list API.
JavaScript CSS
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
browser
project-4-boss-machine
public
server
README.md
data_struct.js
index.html
package-lock.json
package.json
read-evs-devNotes.md
read-evs-devNotes.txt
server.js
webpack.config.js

README.md

Boss Machine

  • I wrote pretty much the entire backend routes in /bossMachine/server
  • Location of my code: bossMachine/server
  • Lines of my code: 437 lines
  • Time this project took to complete: 30 hours
  • Lots of that time was spent conferring with classmates and looking things up
  • The front end (not by me!) is all in React.js

Description of the routes and methods:

  • /api/minions
    • GET /api/minions to get an array of all minions.
    • POST /api/minions to create a new minion and save it to the database.
    • GET /api/minions/:minionId to get a single minion by id.
    • PUT /api/minions/:minionId to update a single minion by id.
    • DELETE /api/minions/:minionId to delete a single minion by id.
  • /api/ideas
    • GET /api/ideas to get an array of all ideas.
    • POST /api/ideas to create a new idea and save it to the database.
    • GET /api/ideas/:ideaId to get a single idea by id.
    • PUT /api/ideas/:ideaId to update a single idea by id.
    • DELETE /api/ideas/:ideaId to delete a single idea by id.
  • /api/meetings
    • GET /api/meetings to get an array of all meetings.
    • POST /api/meetings to create a new meeting and save it to the database.
    • DELETE /api/meetings to delete all meetings from the database.

Description of the methods in Node.js

getAllFromDatabase:

  • Takes only the single argument for model name. Returns the array of elements in the database or null if an invalid argument is supplied

getFromDatabaseById:

  • Takes the model name argument and a second string argument representing the unique ID of the element. Returns the instance with valid inputs and -1 with an invalid id.

addToDatabase:

  • Takes the model name argument and a second argument which is an object with the key-value pairs of the new instance. addToDatabase handles assigning .id properties to the instances. It does not check to make sure that valid inputs are supplied, so you will have to add those checks to your routes if necessary. addToDatabase will return the newly-created instance from the database. This function will validate the schema of the instance to create and throw an error if it is invalid.

updateInstanceInDatabase:

  • Takes the model name argument and a second argument which is an object representing an updated instance. The instance provided must have a valid .id property which will be used to match. updateInstanceInDatabase will return the updated instance in the database or null with invalid inputs. This function will validate the schema of the updated instance and throw an error if it is invalid.

deleteFromDatabasebyId:

  • Takes the model name argument and a second string argument representing the unique ID of the element to delete. Returns true if the delete occurs properly and false if the element is not found.

deleteAllFromDatabase:

  • Takes only the single argument for model name. Deletes all elements from the proper model and returns a new, empty array. You will only need to use this function for a /api/meetings route.

The Schemas

  • Minion:
    • id: string
    • name: string
    • title: string
    • salary: number
  • Idea
    • id: string
    • name: string
    • description: string
    • numWeeks: number
    • weeklyRevenue: number
  • Meeting
    • time: string
    • date: JS Date object
    • day: string
    • note: string

Note that many values that could be numbers are in fact strings. Since this is an outward facing API, I can't trust that data is always provided by a client. My code transforms between String and Number JavaScript types in order to provide full functionality in the API.

Testing

Notes for me in the future in case I forget the syntax for invoking the Mocha Chai:

`

To run these tests, first open the root project directory in your terminal. Then run npm install to install all necessary testing dependencies (you will only need to do this step once). Finally, run npm run test. You will see a list of tests that ran with information about whether or not each test passed. After this list, you will see more specific output about why each failing test failed. While they are open in a terminal window, these tests will re-run every time you save server files. If you want to quit the testing loop, use Ctrl + C. If you only want to run the tests once, you can run the mocha command in the terminal from your project root directory. `

You can’t perform that action at this time.