Facebook
From Round Agouti, 1 Month ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 29
  1. const express = require("express");
  2. const router = express.Router();
  3.  
  4. // importujesz sobie middleware
  5. const { auth } = require("../middleware/auth");
  6.  
  7.  
  8. const { db } = require("../startup/db");
  9.  
  10.  
  11.  
  12.  
  13.  
  14. // uzywasz sobie tego middleware jako parameter endopinta - w tym przypadku dla express.js - inny framework do api moze miec inna skldnie
  15. router.get("/forcultivation/:id", auth, async (req, res) => {
  16.   const { id } = req.params;
  17.   const query = "SELECT * FROM device WHERE cultivation_id=?";
  18.   const devices = await db(query, id);
  19.   return res.status(200).json(devices);
  20. });