Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
463 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
const express = require('express'); | ||
|
||
|
||
const router = express.Router() | ||
const User = require('../models/user') | ||
|
||
|
||
router.get('/:id',getUsers,(req,res) => { | ||
|
||
|
||
console.log(res.data) | ||
res.send(res.data); | ||
}) | ||
|
||
|
||
router.post('/',async(req,res)=>{ | ||
console.log(req.body.name); | ||
const user=new User({ | ||
|
||
email:req.body.email, | ||
student_id:req.body.student_id, | ||
name:req.body.name, | ||
password:req.body.password, | ||
type:req.body.type | ||
}) | ||
try{ | ||
const newUser=await user.save() | ||
res.status(201).json(newUser) | ||
} | ||
catch(err){ | ||
res.status(201).json({message:err.message}) | ||
} | ||
}) | ||
|
||
async function getUsers(req,res,next){ | ||
let data; | ||
try{ | ||
|
||
data=await User.findById(req.params.id); | ||
|
||
if(data==null) | ||
{ | ||
|
||
return res.status(404); | ||
} | ||
} | ||
catch(err){ | ||
|
||
return res.status(500); | ||
} | ||
res.data=data; | ||
next(); | ||
} | ||
|
||
router.get('/:id', getStudent, (req,res) => { | ||
|
||
console.log(res.studentdetails.email) | ||
res.send(res.studentdetails.name) | ||
}) | ||
|
||
async function getStudent(req,res,next) { | ||
let studentdetails | ||
try { | ||
studentdetails = await Club.findById(req.params.id) | ||
if(studentdetails == null){ | ||
return res.status(404).json({message: "cannot find club"}) | ||
} | ||
} catch (err){ | ||
return res.status(500).json({message: err.message}) | ||
} | ||
res.studentdetails = studentdetails | ||
next() | ||
} | ||
|
||
|
||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
const express = require('express'); | ||
const router = express.Router() | ||
const Club = require('../models/club'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
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}) | ||
} | ||
}) | ||
|
||
|
||
|
||
|
||
|
||
|
||
router.patch('/:id',getClubdetails, async(req,res) => { | ||
if(req.body.clubname != null) { | ||
res.clubdetails.clubname = req.body.clubname | ||
} | ||
|
||
if(req.body.email != null) { | ||
res.clubdetails.email = req.body.email | ||
} | ||
|
||
if(req.body.description != null) { | ||
res.clubdetails.description = req.body.description | ||
} | ||
|
||
if(req.body.image != null) { | ||
res.clubdetails.image = req.body.image | ||
} | ||
|
||
if(req.body.location != null) { | ||
res.clubdetails.location= req.body.location | ||
} | ||
|
||
if(req.body.registrationtime != null) { | ||
res.clubdetails.registrationtime = req.body.registrationtime | ||
} | ||
|
||
if(req.body.type != null) { | ||
res.clubdetails.type = req.body.type | ||
} | ||
|
||
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}) | ||
} | ||
}) | ||
|
||
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() | ||
} | ||
|
||
|
||
|
||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
const express = require('express'); | ||
const router = express.Router() | ||
const Event = require('../models/event'); | ||
|
||
|
||
|
||
|
||
|
||
router.post('/', async(req,res)=>{ | ||
// console.log("hii"); | ||
console.log("called") | ||
const events=new Event({ | ||
|
||
eventname:req.body.eventname, | ||
clubname:req.body.clubname, | ||
description:req.body.description, | ||
image:req.body.image, | ||
location:req.body.location, | ||
time:req.body. time, | ||
|
||
}) | ||
try{ | ||
|
||
const newEvents=await events.save() | ||
console.log(newEvents) | ||
res.status(201).json(newEvents) | ||
|
||
} | ||
catch(err){ | ||
console.log("error") | ||
res.status(201).json({message:err.message}) | ||
} | ||
|
||
}) | ||
|
||
router.get('/',async(req,res) => { | ||
try { | ||
const eventdetails = await Event.find() | ||
res.json(eventdetails) | ||
console.log(eventdetails) | ||
} catch(err) { | ||
res.status(500).json({message: err.message}) | ||
} | ||
}) | ||
|
||
router.patch('/:id',getEventdetails, async(req,res) => { | ||
if(req.body.eventname != null) { | ||
res.eventdetails.eventname = req.body.eventname | ||
} | ||
|
||
if(req.body.description != null) { | ||
res.eventdetails.description = req.body.description | ||
} | ||
|
||
|
||
if(req.body.image != null) { | ||
res.eventdetails.image = req.body.image | ||
} | ||
|
||
if(req.body.location != null) { | ||
res.eventdetails.location= req.body.location | ||
} | ||
|
||
if(req.body.time != null) { | ||
res.eventdetails.time = req.body.time | ||
} | ||
|
||
|
||
|
||
try { | ||
const updatedEventdetails = await res.eventdetails.save() | ||
res.json(updatedEventdetails) | ||
} catch(err) { | ||
res.status(400).json({message: err.message}) | ||
} | ||
}) | ||
|
||
router.delete('/:id',getEventdetails, async(req,res) => { | ||
try { | ||
await res.eventdetails.remove() | ||
res.json({message: "Deleted event"}) | ||
}catch { | ||
return res.status(500).json({message: err.message}) | ||
} | ||
}) | ||
|
||
router.get('/:id', getEventdetails, (req,res) => { | ||
console.log(res.eventdetails.eventname) | ||
res.send(res.eventdetails) | ||
}) | ||
|
||
async function getEventdetails(req,res,next) { | ||
let eventdetails | ||
try { | ||
eventdetails = await Event.findById(req.params.id) | ||
if(eventdetails == null){ | ||
return res.status(404).json({message: "cannot find event"}) | ||
} | ||
} catch (err){ | ||
return res.status(500).json({message: err.message}) | ||
} | ||
res.eventdetails = eventdetails | ||
next() | ||
} | ||
|
||
|
||
|
||
|
||
module.exports = router |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
const express = require('express'); | ||
|
||
|
||
const router = express.Router() | ||
const User = require('../models/user') | ||
|
||
|
||
|
||
router.post('/',async(req,res)=>{ | ||
|
||
|
||
|
||
var email = req.body.email; | ||
var password = req.body.password; | ||
const username=await User.findOne({email:email | ||
,password:password}); | ||
console.log(username); | ||
if(username==null) | ||
{ | ||
return res.status(400).json("False") | ||
} | ||
try{ | ||
|
||
res.status(200).json(username) | ||
} | ||
catch(err){ | ||
res.status(201).json({message:err.message}) | ||
} | ||
|
||
|
||
}) | ||
|
||
// router.post('/',async(req,res)=>{ | ||
// console.log(req.body.name); | ||
// const user=new User({ | ||
|
||
// name:req.body.name, | ||
// email:req.body.email, | ||
// password:req.body.password, | ||
// type:req.body.type | ||
// }) | ||
// try{ | ||
// const newUser=await user.save() | ||
// res.status(201).json(newUser) | ||
// } | ||
// catch(err){ | ||
// res.status(201).json({message:err.message}) | ||
// } | ||
// }) | ||
|
||
|
||
|
||
module.exports = router |
Oops, something went wrong.