Skip to content

Instantly share code, notes, and snippets.

View nathleia's full-sized avatar

paul altefogt nathleia

  • nathleia llc
View GitHub Profile
const getDecks = useCallback(async () => {
try {
const response = await listDecks(signal);
setDecks(response.data);
} catch (error) {
console.log(error);
}
}, [signal]);
// get decks when first rendered
// 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);
}
// 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;
}
@nathleia
nathleia / expressWasteProfile.json
Created October 18, 2021 14:37
Express Waste Profile Json
{
"meta": {
"sections": {
"generator": {
"completed": true,
"valid": true
},
"billing": {
"completed": true,
"valid": true
// 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]] })
}
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 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",
{
"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"
// 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
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>