This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getDecks = useCallback(async () => { | |
| try { | |
| const response = await listDecks(signal); | |
| setDecks(response.data); | |
| } catch (error) { | |
| console.log(error); | |
| } | |
| }, [signal]); | |
| // get decks when first rendered |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CONTROLLER | |
| async function list(req, res, next) { | |
| // get is_showing from the query params | |
| const { query } = req; | |
| const { is_showing } = query; | |
| // pass our is_showing to the service | |
| const data = await moviesService.list(is_showing); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // TODO: Add ability to create a new note | |
| app.post("/notes", (req,res,next)=>{ | |
| const {data: {text}={} }= req.body | |
| // if we don't get note data, return 400 | |
| if(!text || text === ''){ | |
| res.status(400).json({msg: 'Missing or empty request body'}); | |
| return; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "meta": { | |
| "sections": { | |
| "generator": { | |
| "completed": true, | |
| "valid": true | |
| }, | |
| "billing": { | |
| "completed": true, | |
| "valid": true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // list middleware function | |
| function list(req, res) { | |
| const urlId = Number(req.params.urlId) | |
| console.log(`list function urlId ${urlId}`) | |
| const byResult = urlId ? use => use.urlId === urlId : () => true | |
| const result = uses.filter(byResult); | |
| console.log(result); | |
| res.json({ data: [result[0]] }) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| async function create(req, res, next) { | |
| // your solution here | |
| const data = await restaurantsService.create(req.body.data).catch(next); | |
| res.status(201).json({data}); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // This line is required if you want to make use of the .env file. | |
| require("dotenv").config(); | |
| //you'll see that a URL variable is set so that | |
| //if the NODE_ENV environment variable is equal to the string "production", | |
| //PRODUCTION_DATABASE_URL will be used. | |
| //Otherwise, DEVELOPMENT_DATABASE_URL will be used. | |
| const { | |
| NODE_ENV = "development", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "name": "zid-pf-javascript-on-your-machine-05-package-json", | |
| "version": "1.0.0", | |
| "description": "Javascript-On-My-Machine", | |
| "keywords": [], | |
| "author": "Shavon", | |
| "license": "ISC", | |
| "devDependencies": { | |
| "chai": "^4.3.4", | |
| "mocha": "^8.3.2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Service | |
| function count() { | |
| // knex likes to return arrays for everything | |
| // we can use the .first() function to just get the first item | |
| // in the array, since we are just getting a count, and therefore we know that | |
| // there is only going to be a single item in the array | |
| return knex("restaurants").count("restaurant_id").first(); | |
| } | |
| // Controller |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from "react"; | |
| function Clock () { | |
| const time = new Date().getHours() | |
| if (time < 12) | |
| return <p>Good Morning!</p> | |
| if (time >= 12 && time <= 18) | |
| return <p>Good Afternoon!</p> | |
| if (time >= 18) | |
| return <p>Good Evening!</p> |
NewerOlder