Skip to content

401-advanced-javascript-billybunn/lab-08

Repository files navigation

CF LAB

LAB 8: Data Modeling

Build Status

Author: Billy Bunn

Links and Resources

Documentation

/models

Contains data models and tests for Categories and Products interfaces

Modules

/categories.js

get(_id) -> returns a single category or entire category collection

Used for GET requests. Searches (memory) database for and category with entered _id and returns it. Returns entire category list if called without an _id. Returns error message if _id is not found.

post(record) -> adds a category to the database

Used for POST requests. Validates entry with validate method, creates and appends UUID to entry, and adds it to the database. If a valid entry, returns the added category. Returns error message if entry does not contain all fields required by the schema.

put(_id, entry) -> edits content of a category in the database

Used for PUT requests. Validates entry with validate method, searches for category with _id entered, updates that category with entry, and saves it to the database. If a valid entry, returns the updated category.

delete(_id) -> deletes a category in the database

Used for DELETE requests. Searches database for _id entered, removes the category with matching _id from the database, and returns an empty object upon success. Returns error message if _id is not found.

validate(record) -> compares record entry against required keys in schema, returns true / false

Used for all POST and PUT requests. Checks if all required fields in the schema are present in record entered. Returns true or false.

Setup

.env requirements

  • npm i
  • PORT - assign a port number
  • MONGODB_URI - URL to the running mongo instance/db

Running the app

  • npm start

Tests

  • How do you run tests?
    • npm run test
    • npm run lint

UML

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published