Skip to content

Commit

Permalink
fix: minor changes to the routes
Browse files Browse the repository at this point in the history
  • Loading branch information
tamalCodes committed Sep 7, 2023
1 parent 02bc55b commit 8d05551
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 78 deletions.
53 changes: 25 additions & 28 deletions config/passport-googleAuth-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,10 @@ passport.use(
callbackURL: process.env.CALLBACK_URL,
},
async function (accessToken, refreshToken, profile, done) {
User.findOne({ email: profile.emails[0].value }).exec(function (
err,
user,
) {
if (err) {
return;
}
try {
let user = await User.findOne({
email: profile.emails[0].value,
}).exec();

if (user) {
return done(null, user);
Expand All @@ -27,22 +24,18 @@ passport.use(

if (!lastname) lastname = " ";

User.create(
{
firstname: firstname,
lastname: lastname,
email: profile.emails[0].value,
password: crypto.randomBytes(20).toString("hex"),
},
function (err, user) {
if (err) {
return;
}
return done(null, user);
},
);
user = await User.create({
firstname: firstname,
lastname: lastname,
email: profile.emails[0].value,
password: crypto.randomBytes(20).toString("hex"),
});

return done(null, user);
}
});
} catch (err) {
return done(err);
}
},
),
);
Expand All @@ -51,14 +44,18 @@ passport.serializeUser(function (user, done) {
done(null, user.id);
});

// deserializing the user the key in the cookies
passport.deserializeUser(function (id, done) {
User.findById(id, function (err, user) {
if (err) {
return done(null, user);
passport.deserializeUser(async function (id, done) {
try {
const user = await User.findById(id).exec();

if (!user) {
return done(null, false);
}

return done(null, user);
});
} catch (err) {
return done(err);
}
});

module.exports = passport;
19 changes: 0 additions & 19 deletions routes/club/Club.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const express = require("express");
const Club = require("../../schema/club/ClubSchema");
const router = express.Router();
const bcrypt = require("bcryptjs");
const Events = require("../../schema/club/EventSchema");
var jwt = require("jsonwebtoken");

router.get("/", async (req, res) => {
Expand Down Expand Up @@ -90,22 +89,4 @@ router.post("/login", async (req, res) => {
}
});

//* Route 3 - Create Event

router.post("/createevent", async (req, res) => {
try {
const { eventname, eventlocation, eventdate, eventdescription } = req.body;
const eventData = Events({
Eventname: eventname,
Eventdate: eventdate,
Eventlocation: eventlocation,
Eventdescription: eventdescription,
});
await eventData.save();
res.status(200).json(eventData);
} catch (e) {
res.status(500).json({ message: "Internal Server Error" });
}
});

module.exports = router;
11 changes: 0 additions & 11 deletions routes/display/Display.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
const express = require("express");
const Club = require("../../schema/club/ClubSchema");
const User = require("../../schema/user/UserSchema");
const Events = require("../../schema/club/EventSchema");
const router = express.Router();

//* Route 1 - Show all avaialble Users in the DB
Expand All @@ -30,14 +29,4 @@ router.get("/clubs", async (req, res) => {
}
});

//* Route 3 - Show all the other events
router.get("/events", async (req, res) => {
try {
const allEvents = await Events.find({});
return res.status(200).json(allEvents);
} catch (error) {
res.status(500).json({ message: "Internal Server Error" });
}
});

module.exports = router;
18 changes: 0 additions & 18 deletions schema/club/EventSchema.js

This file was deleted.

13 changes: 11 additions & 2 deletions schema/user/UserSchema.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
const mongoose = require("mongoose");

const UserSchema = mongoose.Schema({
firstname: {
usertype: {
type: String,
},
slug: {
type: String,
required: true,
},
lastname: {
name: {
type: String,
required: true,
},
firstname: {
type: String,
},
lastname: {
type: String,
},
email: {
type: String,
required: true,
Expand Down

0 comments on commit 8d05551

Please sign in to comment.