Skip to content
Snippets Groups Projects
Select Git revision
  • 63fa4023d8f484bcc1763f817d93081b6e75e971
  • main default
2 results

Graph.css

Blame
  • genres.js 1.60 KiB
    const express = require("express");
    const GenreModel = require("../models/genre");
    const router = express.Router();
    
    module.exports = router;
    
    router.get("/", async function (req, res) {
      try {
        const getGenres = await GenreModel.find({});
        res.send(getGenres);
      } catch (error) {
        console.log(error);
      }
    });
    
    router.get("/genre/id/:id", async function (req, res) {
      try {
        const genreId = await req.params["id"];
        const getGenres = await GenreModel.findOne({ id: genreId });
        res.send(getGenres.name);
      } catch (error) {
        console.log(error);
      }
    });
    
    // router.post("/new", async function (req, res) {
    //   try {
    //     const newGenre = new GenreModel({
    //       // Genre attributes
    //       publisher: req.body.publisher,
    //       title: req.body.title,
    //       date: req.body.date,
    //       imageURL: req.body.imageURL,
    //       viewers: req.body.viewers,
    //     });
    
    //     // Create a new genre instance
    //     const createdGenre = await newGenre.save();
    
    //     // What to do after genre has been saved !
    //     console.log("Genre Saved");
    //     res.send(createdGenre);
    //   } catch (error) {
    //     console.log(error);
    //   }
    // });
    
    // router.put("/id/:id", async function (req, res) {
    //   try {
    //     const genreId = await req.params["id"];
    //     await GenreModel.findByIdAndUpdate(genreId, {
    //       publisher: req.body.publisher,
    //       title: req.body.title,
    //       date: req.body.date,
    //       imageURL: req.body.imageURL,
    //       viewers: req.body.viewers,
    //     });
    //     res.send("Done");
    //   } catch (error) {
    //     console.log(error);
    //     res.send("Invalid Id");
    //   }
    // });