Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const express = require("express");
- const burger = require("../models/burger");
- var router = express.Router();
- router.get("/", function(req, res) {
- burger.selectAll(function(data) {
- var hbsObject = {
- burger: data
- };
- console.log(hbsObject);
- res.render("index", hbsObject);
- });
- });
- router.post("/api/burgers", function(req, res) {
- burger.insertOne([
- "name", "devoured"
- ], [
- req.body.name, req.body.devoured
- ], function(result) {
- // Send back the ID of the new quote
- res.json({ id: result.insertId });
- });
- });
- router.put("/api/burgers/:id", function(req, res) {
- var condition = "id = " + req.params.id;
- console.log("condition", condition);
- burger.updateOne({
- devoured: req.body.devoured
- }, condition, function(result) {
- if (result.changedRows == 0) {
- // If no rows were changed, then the ID must not exist, so 404
- return res.status(404).end();
- } else {
- res.status(200).end();
- }
- });
- });
- // Export routes for server.js to use.
- module.exports = router;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement