Advertisement
Stanchevvv

Untitled

Oct 21st, 2023
780
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     <section id="detailsPage">
  2.             <div id="detailsInfo">
  3.                 <h1>Name: {{electronic.name}}</h1>
  4.                 <div class="info"><img src="./image/laptop.webp"></div>
  5.  
  6.                 <div class="info">
  7.                     <h3>Type: {{electronic.type}}</h3>
  8.                     <h3>Year of Production: {{electronic.production}}</h3>
  9.                     <h3>Years of Exploitation: {{electronic.exploitation}}</h3>
  10.                     <h3>Damages: {{electronic.damages}}</h3>
  11.                     <h3>Description: {{electronic.description}}</h3>
  12.                     <h2>Price: {{electronic.price}}</h2>
  13.                 </div>
  14.  
  15.             {{#if isAuthenticated}}
  16.                 <!--If there is user logged in-->
  17.                 <div class="buttons">
  18.                    
  19.                     <!--If user is not owner of the toy post-->
  20.                     <a href="#" class="buy-btn">Buy</a>
  21.                  {{#if isOwner}}  
  22.                     <!--If user is owner-->
  23.                     <a href="#" class="edit-btn">Edit</a>
  24.                     <a href="#" class="delete-btn">Delete</a>
  25.                 {{else}}
  26.                     <!--If user is not the owner and is bought this toy-->
  27.                     <p><span class="buy">Thank You For Your Purchase</span></p>
  28.              {{/if}}
  29.                 </div>
  30.             </div>
  31.         </section>    
  32. ----------------------------------------------
  33.  
  34. const Electronic = require("../models/Electronic")
  35.  
  36. exports.create = (data) => Electronic.create(data)
  37.  
  38. exports.getAll = () => Electronic.find()
  39.  
  40. exports.singleCreature = (elecronicId) => Electronic.findById(elecronicId)
  41. ------------------------------------------------------------------------------------
  42. const router = require("express").Router()
  43. const electronicService = require("../services/electronicService")
  44.  
  45. router.get("/catalog",async (req,res) => {
  46.    const electronics = await electronicService.getAll().lean()
  47.     res.render("post/catalog",{electronics})
  48. })
  49.  
  50. router.get("/create", (req,res) => {
  51.     res.render("post/create")
  52. })
  53.  
  54. router.post("/create",async (req,res) => {
  55.     const{name,type,damages,image,description,production,exploitation,price,buyingList} = req.body
  56.     const payload = {name,type,damages,image,description,production,exploitation,price,buyingList,owner: req.user}
  57.     await electronicService.create(payload)
  58.     res.redirect("/posts/catalog")
  59. })
  60.  
  61. router.get("/:electronicsId/details", async (req,res) => {
  62.     const{electronicsId} = req.params
  63.     const electronic = await electronicService.singleCreature(electronicsId).lean()
  64.     const {user} = req
  65.    
  66.     const {owner} = electronic
  67.     const isOwner = user?._id === owner.toString()
  68.  
  69.  
  70.     res.render("post/details", {electronic, isOwner})
  71. })
  72.  
  73.  
  74. module.exports = router
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement