From 670f1588d023cd52c7a2e94dc0506dee35074a48 Mon Sep 17 00:00:00 2001 From: "Mahesh Warang (warangm)" Date: Fri, 4 Nov 2022 10:26:24 +0530 Subject: [PATCH] Update clubdetails.js --- routes/clubdetails.js | 131 +++++++++++------------------------------- 1 file changed, 34 insertions(+), 97 deletions(-) diff --git a/routes/clubdetails.js b/routes/clubdetails.js index 56083d2..430064c 100644 --- a/routes/clubdetails.js +++ b/routes/clubdetails.js @@ -1,113 +1,50 @@ -const express = require('express'); -const router = express.Router() -const Club = require('../models/club'); +import express from "express"; +import { + createClub, + getAllClub, + updateClub, + getClub, + deleteClubs, + countByType, + featuredClub, + searchQ, + registerClub, +} from "../controllers/club.js"; +import { verifyAdmin, verifyUser} from "../utils/verifyToken.js"; - - - - - - router.post('/',async(req,res)=>{ - - const club=new Club({ - name:req.body.name, - email:req.body.email, - photo:req.body.photo, - location:req.body.location, - type:req.body.type, - president_mail:req.body. president_mail - }) - try{ - const newClub=await club.save() - res.status(201).json(newClub) - } - catch(err){ - res.status(201).json({message:err.message}) - } - -}) - -router.get('/:id', getClubdetails, (req,res) => { - // console.log(res.clubdetails.clubname) - res.send(res.clubdetails.clubname) - }) - -router.get('/',async(req,res) => { - try { - const clubdetails = await Club.find() - res.json(clubdetails) - } catch(err) { - res.status(500).json({message: err.message}) - } -}) - - - - - +const router = express.Router(); -router.patch('/:id',getClubdetails, async(req,res) => { -if(req.body.clubname != null) { - res.clubdetails.clubname = req.body.clubname -} +//CRUD -if(req.body.email != null) { - res.clubdetails.email = req.body.email -} +//Create +router.post('/create-club',verifyAdmin, createClub) -if(req.body.description != null) { - res.clubdetails.description = req.body.description -} +//update +router.put("/update/:id", verifyAdmin, updateClub); -if(req.body.image != null) { - res.clubdetails.image = req.body.image -} +//update user +router.put("/update-user/:id",verifyUser,registerClub) +//delete +router.delete("/delete/:id", verifyAdmin, deleteClubs); +//get +router.get("/get/:id", getClub); +//get list -if(req.body.location != null) { - res.clubdetails.location= req.body.location -} +router.get("/getAll", getAllClub); -if(req.body.registrationtime != null) { - res.clubdetails.registrationtime = req.body.registrationtime -} -if(req.body.type != null) { - res.clubdetails.type = req.body.type -} +router.get("/countByClubs", getAllClub); +router.get("/countByType", countByType); -try { - const updatedClubdetails = await res.clubdetails.save() - res.json(updatedClubdetails) -} catch(err) { - res.status(400).json({message: err.message}) -} -}) -router.delete('/:id',getClubdetails, async(req,res) => { - try { -await res.clubdetails.remove() -res.json({message: "Deleted club"}) - }catch { - return res.status(500).json({message: err.message}) - } - }) +//Featured Club -async function getClubdetails(req,res,next) { - let clubdetails - try { - clubdetails = await Club.findById(req.params.id) - if(clubdetails == null){ - return res.status(404).json({message: "cannot find club"}) - } - } catch (err){ - return res.status(500).json({message: err.message}) - } - res.clubdetails = clubdetails - next() -} +router.get("/featured", featuredClub); +//search +router.get("/search", searchQ); -module.exports = router \ No newline at end of file +export default router;