G2A Many GEOs
SHARE
TWEET

Untitled

a guest Mar 31st, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const express = require("express");
  2. const burger = require("../models/burger");
  3.  
  4. var router = express.Router();
  5.  
  6. router.get("/", function(req, res) {
  7.     burger.selectAll(function(data) {
  8.       var hbsObject = {
  9.         burger: data
  10.       };
  11.       console.log(hbsObject);
  12.       res.render("index", hbsObject);
  13.     });
  14.   });
  15.  
  16.   router.post("/api/burgers", function(req, res) {
  17.     burger.insertOne([
  18.       "name", "devoured"
  19.     ], [
  20.       req.body.name, req.body.devoured
  21.     ], function(result) {
  22.       // Send back the ID of the new quote
  23.       res.json({ id: result.insertId });
  24.     });
  25.   });
  26.  
  27.   router.put("/api/burgers/:id", function(req, res) {
  28.     var condition = "id = " + req.params.id;
  29.  
  30.     console.log("condition", condition);
  31.  
  32.     burger.updateOne({
  33.       devoured: req.body.devoured
  34.     }, condition, function(result) {
  35.       if (result.changedRows == 0) {
  36.         // If no rows were changed, then the ID must not exist, so 404
  37.         return res.status(404).end();
  38.       } else {
  39.         res.status(200).end();
  40.       }
  41.     });
  42.   });
  43.  
  44.   // Export routes for server.js to use.
  45.   module.exports = router;
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top