Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <section id="detailsPage">
- <div id="detailsInfo">
- <h1>Name: {{electronic.name}}</h1>
- <div class="info"><img src="./image/laptop.webp"></div>
- <div class="info">
- <h3>Type: {{electronic.type}}</h3>
- <h3>Year of Production: {{electronic.production}}</h3>
- <h3>Years of Exploitation: {{electronic.exploitation}}</h3>
- <h3>Damages: {{electronic.damages}}</h3>
- <h3>Description: {{electronic.description}}</h3>
- <h2>Price: {{electronic.price}}</h2>
- </div>
- {{#if isAuthenticated}}
- <!--If there is user logged in-->
- <div class="buttons">
- <!--If user is not owner of the toy post-->
- <a href="#" class="buy-btn">Buy</a>
- {{#if isOwner}}
- <!--If user is owner-->
- <a href="#" class="edit-btn">Edit</a>
- <a href="#" class="delete-btn">Delete</a>
- {{else}}
- <!--If user is not the owner and is bought this toy-->
- <p><span class="buy">Thank You For Your Purchase</span></p>
- {{/if}}
- </div>
- </div>
- </section>
- ----------------------------------------------
- const Electronic = require("../models/Electronic")
- exports.create = (data) => Electronic.create(data)
- exports.getAll = () => Electronic.find()
- exports.singleCreature = (elecronicId) => Electronic.findById(elecronicId)
- ------------------------------------------------------------------------------------
- const router = require("express").Router()
- const electronicService = require("../services/electronicService")
- router.get("/catalog",async (req,res) => {
- const electronics = await electronicService.getAll().lean()
- res.render("post/catalog",{electronics})
- })
- router.get("/create", (req,res) => {
- res.render("post/create")
- })
- router.post("/create",async (req,res) => {
- const{name,type,damages,image,description,production,exploitation,price,buyingList} = req.body
- const payload = {name,type,damages,image,description,production,exploitation,price,buyingList,owner: req.user}
- await electronicService.create(payload)
- res.redirect("/posts/catalog")
- })
- router.get("/:electronicsId/details", async (req,res) => {
- const{electronicsId} = req.params
- const electronic = await electronicService.singleCreature(electronicsId).lean()
- const {user} = req
- const {owner} = electronic
- const isOwner = user?._id === owner.toString()
- res.render("post/details", {electronic, isOwner})
- })
- module.exports = router
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement