From 4f632e7e2c013d49c5c8192fd0e578982ce72ef3 Mon Sep 17 00:00:00 2001 From: Suzy Date: Sun, 4 Jun 2023 21:59:04 +0530 Subject: [PATCH 1/8] fix: solve repetition in events --- src/pages/events/index.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/pages/events/index.tsx b/src/pages/events/index.tsx index c81ecc9e..ca49eaa5 100644 --- a/src/pages/events/index.tsx +++ b/src/pages/events/index.tsx @@ -1,4 +1,4 @@ -import { sortEventsByDate, sortEventsByFilter } from '@/lib/helper'; +import { sortEventsByFilter } from '@/lib/helper'; import { EventType } from '@/lib/types'; import Event from '@/components/upcoming/Event'; @@ -119,12 +119,6 @@ const EventPage: NextPage = () => { )} - -
- {sortEventsByDate(events).map((event) => ( - - ))} -
From 2287deb628413eb1439c7b55d327adce2fb205f2 Mon Sep 17 00:00:00 2001 From: Suzy Date: Sat, 24 Jun 2023 20:46:15 +0530 Subject: [PATCH 2/8] fix: fix error for react import --- src/pages/privacy.tsx | 2 +- src/pages/terms.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/privacy.tsx b/src/pages/privacy.tsx index 3cfa3e5f..e5427736 100644 --- a/src/pages/privacy.tsx +++ b/src/pages/privacy.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +// import React from 'react'; export default function PrivacyPolicy() { return ( diff --git a/src/pages/terms.tsx b/src/pages/terms.tsx index 35f5f2f1..fe1cc8dc 100644 --- a/src/pages/terms.tsx +++ b/src/pages/terms.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +// import React from 'react'; export default function Terms() { return ( From 0f65a8dcd89de5166f4c14f2049f0c8be3de2129 Mon Sep 17 00:00:00 2001 From: Suzy Date: Sat, 24 Jun 2023 21:59:36 +0530 Subject: [PATCH 3/8] feat: add server --- server/.gitignore | 3 + server/index.js | 36 +++++++++++ server/package.json | 22 +++++++ server/schema/cfps/CfpsSchema.js | 47 ++++++++++++++ server/schema/events/EventsSchema.js | 47 ++++++++++++++ server/schema/hackathon/hackathonSchema.js | 47 ++++++++++++++ server/schema/mongo.connect.js | 23 +++++++ server/schema/user/UserSchema.js | 44 +++++++++++++ server/src/cpfs/cfp.router.js | 74 +++++++++++++++++++++ server/src/cpfs/cfp.service.js | 70 ++++++++++++++++++++ server/src/events/event.service.js | 72 +++++++++++++++++++++ server/src/events/events.router.js | 70 ++++++++++++++++++++ server/src/hackathons/hackathon.router.js | 75 ++++++++++++++++++++++ server/src/hackathons/hackathon.service.js | 69 ++++++++++++++++++++ server/src/users/user.router.js | 62 ++++++++++++++++++ server/src/users/user.service.js | 51 +++++++++++++++ 16 files changed, 812 insertions(+) create mode 100644 server/.gitignore create mode 100644 server/index.js create mode 100644 server/package.json create mode 100644 server/schema/cfps/CfpsSchema.js create mode 100644 server/schema/events/EventsSchema.js create mode 100644 server/schema/hackathon/hackathonSchema.js create mode 100644 server/schema/mongo.connect.js create mode 100644 server/schema/user/UserSchema.js create mode 100644 server/src/cpfs/cfp.router.js create mode 100644 server/src/cpfs/cfp.service.js create mode 100644 server/src/events/event.service.js create mode 100644 server/src/events/events.router.js create mode 100644 server/src/hackathons/hackathon.router.js create mode 100644 server/src/hackathons/hackathon.service.js create mode 100644 server/src/users/user.router.js create mode 100644 server/src/users/user.service.js diff --git a/server/.gitignore b/server/.gitignore new file mode 100644 index 00000000..a0add908 --- /dev/null +++ b/server/.gitignore @@ -0,0 +1,3 @@ +node_modules +.env +yarn.lock \ No newline at end of file diff --git a/server/index.js b/server/index.js new file mode 100644 index 00000000..b92b52c9 --- /dev/null +++ b/server/index.js @@ -0,0 +1,36 @@ +import { mongoConnect } from './schema/mongo.connect.js'; +import { cfpRouter } from './src/cpfs/cfp.router.js'; +import { eventRouter } from './src/events/events.router.js'; +import { hackathonRouter } from './src/hackathons/hackathon.router.js'; +import { userRouter } from './src/users/user.router.js'; +import cors from 'cors'; +import dotenv from 'dotenv'; +import express from 'express'; + +dotenv.config(); +const app = express(); +const port = process.env.PORT; + +const allowedOrigins = [`${process.env.UI_ENDPOINT}`]; + +const options = { + origin: allowedOrigins, + credentials: true, +}; + +app.use(cors(options)); +await mongoConnect(); + +app.get('/', () => { + throw new Error(''); +}); + +app.use(express.json()); + +app.use('/api/user', userRouter); +app.use('/api/events', eventRouter); +app.use('/api/hackathons', hackathonRouter); +app.use('/api/cfps', cfpRouter); + +// eslint-disable-next-line no-console +app.listen(port, () => console.log(`server is running on ${port}`)); diff --git a/server/package.json b/server/package.json new file mode 100644 index 00000000..9d99d621 --- /dev/null +++ b/server/package.json @@ -0,0 +1,22 @@ +{ + "name": "opensource", + "version": "1.0.0", + "description": "", + "main": "index.js", + "type": "module", + "scripts": { + "dev": "nodemon index.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "body-parser": "^1.20.2", + "cors": "^2.8.5", + "dotenv": "^16.3.1", + "eslint": "^8.43.0", + "http": "^0.0.1-security", + "mongodb": "^5.6.0", + "mongoose": "^7.3.1" + } +} diff --git a/server/schema/cfps/CfpsSchema.js b/server/schema/cfps/CfpsSchema.js new file mode 100644 index 00000000..68c18031 --- /dev/null +++ b/server/schema/cfps/CfpsSchema.js @@ -0,0 +1,47 @@ +import { model, Schema } from 'mongoose'; + +const CfpsSchema = new Schema( + { + name: { + type: String, + require: true, + }, + slug: { + type: String, + require: true, + }, + organizer: { + type: String, + require: true, + }, + description: { + type: String, + require: true, + }, + address: { + type: { isOnline: Boolean, location: String }, + required: true, + }, + image: { + type: Buffer, + require: false, + }, + date: { + type: Date, + require: true, + }, + duration: { + type: Number, + require: true, + }, + tags: { + type: [String], + require: true, + }, + }, + { + timestamps: true, + } +); + +export const CfpModel = model('cfps', CfpsSchema); diff --git a/server/schema/events/EventsSchema.js b/server/schema/events/EventsSchema.js new file mode 100644 index 00000000..b00fe267 --- /dev/null +++ b/server/schema/events/EventsSchema.js @@ -0,0 +1,47 @@ +import { model, Schema } from 'mongoose'; + +const EventsSchema = new Schema( + { + name: { + type: String, + require: true, + }, + slug: { + type: String, + require: true, + }, + organizer: { + type: String, + require: true, + }, + description: { + type: String, + require: true, + }, + address: { + type: { isOnline: Boolean, location: String }, + required: true, + }, + image: { + type: Buffer, + require: false, + }, + date: { + type: Date, + require: true, + }, + duration: { + type: Number, + require: true, + }, + tags: { + type: [String], + require: true, + }, + }, + { + timestamps: true, + } +); + +export const EventModel = model('events', EventsSchema); diff --git a/server/schema/hackathon/hackathonSchema.js b/server/schema/hackathon/hackathonSchema.js new file mode 100644 index 00000000..bdee03b3 --- /dev/null +++ b/server/schema/hackathon/hackathonSchema.js @@ -0,0 +1,47 @@ +import { model, Schema } from 'mongoose'; + +const HackathonSchema = new Schema( + { + name: { + type: String, + require: true, + }, + slug: { + type: String, + require: true, + }, + organizer: { + type: String, + require: true, + }, + description: { + type: String, + require: true, + }, + address: { + type: { isOnline: Boolean, location: String }, + required: true, + }, + image: { + type: Buffer, + require: false, + }, + date: { + type: Date, + require: true, + }, + duration: { + type: Number, + require: true, + }, + tags: { + type: [String], + require: true, + }, + }, + { + timestamps: true, + } +); + +export const HackathonModel = model('hackathon', HackathonSchema); diff --git a/server/schema/mongo.connect.js b/server/schema/mongo.connect.js new file mode 100644 index 00000000..8b5e6cf3 --- /dev/null +++ b/server/schema/mongo.connect.js @@ -0,0 +1,23 @@ +import mongoose, { connect } from 'mongoose'; + +//surprass deprication warning +mongoose.set('strictQuery', false); + +export const mongoConnect = async () => { + const connectionString = + process.env.MONGODB_PROTO + + process.env.MONGODB_USER + + ':' + + process.env.MONGODB_PASSWORD + + '@' + + process.env.MONGODB_URL + + '/' + + process.env.MONGODB_DATABASE; + try { + // eslint-disable-next-line no-console + console.log('connection'); + await connect(connectionString); + } catch (error) { + throw new Error(String(error)); + } +}; diff --git a/server/schema/user/UserSchema.js b/server/schema/user/UserSchema.js new file mode 100644 index 00000000..89a4bd9f --- /dev/null +++ b/server/schema/user/UserSchema.js @@ -0,0 +1,44 @@ +import { model, Schema } from 'mongoose'; + +const UserSchema = new Schema( + { + name: { + type: String, + require: true, + }, + email: { + type: String, + require: true, + }, + password: { + type: String, + require: true, + }, + image: { + type: Buffer, + require: false, + }, + bio: { + type: String, + require: false, + }, + role: { + type: String, + require: true, + }, + socials: { + type: [ + { + name: String, + link: String, + }, + ], + require: false, + }, + }, + { + timestamps: true, + } +); + +export const UserModel = model('user', UserSchema); diff --git a/server/src/cpfs/cfp.router.js b/server/src/cpfs/cfp.router.js new file mode 100644 index 00000000..9f741972 --- /dev/null +++ b/server/src/cpfs/cfp.router.js @@ -0,0 +1,74 @@ +import { CfpService } from './cfp.service.js'; +import express from 'express'; + +export const cfpRouter = express.Router(); + +//get all cfps + +cfpRouter.get('/', async (_, res) => { + try { + const cfps = await CfpService.getAllCfps(); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get cfp by id + +cfpRouter.get('/id/:id', async (req, res) => { + try { + const { id } = req.params; + const cfps = await CfpService.getCfpsById(id); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get cfp by slug + +cfpRouter.get('/slug/:slug', async (req, res) => { + try { + const { slug } = req.params; + const cfps = await CfpService.getCfpsBySlug(slug); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); + +//add cfp +cfpRouter.post('/create', async (req, res) => { + try { + const { data } = req.body; + const cfps = await CfpService.createCfp(data); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); +//update cfp +cfpRouter.post('/update/:id', async (req, res) => { + try { + const { id } = req.params; + const { data } = req.body; + + const cfps = await CfpService.updateCfp(id, data); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); + +//delete cfp by id + +cfpRouter.post('/delete', async (req, res) => { + try { + const { id } = req.body; + const cfps = await CfpService.deleteCfp(id); + res.status(200).send({ success: true, cfps: cfps }); + } catch (error) { + res.status(500).send(error); + } +}); diff --git a/server/src/cpfs/cfp.service.js b/server/src/cpfs/cfp.service.js new file mode 100644 index 00000000..dc3f2047 --- /dev/null +++ b/server/src/cpfs/cfp.service.js @@ -0,0 +1,70 @@ +import { CfpModel } from '../../schema/cfps/CfpsSchema.js'; + +const getAllCfps = async () => { + try { + const cfp = await CfpModel.find({}); + + return cfp; + } catch (error) { + throw new Error(error); + } +}; + +const getCfpsById = async (_id) => { + try { + const cfp = await CfpModel.find({ _id }); + return cfp; + } catch (error) { + throw new Error(error); + } +}; + +const getCfpsBySlug = async (slug) => { + try { + const cfp = await CfpModel.find({ slug }); + return cfp; + } catch (error) { + throw new Error(error); + } +}; + +const createCfp = async (eventInfo) => { + try { + const cfp = new CfpModel(eventInfo); + await cfp.save(); + return cfp; + } catch (error) { + throw new Error(error); + } +}; +const updateCfp = async (_id, updatedValue) => { + try { + const cfp = await CfpModel.findOneAndUpdate( + { _id: _id }, + { $set: updatedValue }, + { returnOriginal: false } + ); + + return cfp; + } catch (error) { + throw new Error(error); + } +}; + +const deleteCfp = async (_id) => { + try { + const cfp = await CfpModel.deleteOne({ _id: _id }); + return cfp; + } catch (error) { + throw new Error(error); + } +}; + +export const CfpService = { + getAllCfps, + getCfpsById, + getCfpsBySlug, + createCfp, + updateCfp, + deleteCfp, +}; diff --git a/server/src/events/event.service.js b/server/src/events/event.service.js new file mode 100644 index 00000000..8fe915c4 --- /dev/null +++ b/server/src/events/event.service.js @@ -0,0 +1,72 @@ +import { EventModel } from '../../schema/events/EventsSchema.js'; + +const getAllEvents = async () => { + try { + const eventData = await EventModel.find({}); + + return eventData; + } catch (error) { + throw new Error(error); + } +}; + +const getEventsById = async (_id) => { + try { + const eventById = await EventModel.find({ _id }); + return eventById; + } catch (error) { + throw new Error(error); + } +}; + +const getEventsBySlug = async (slug) => { + try { + const eventById = await EventModel.find({ slug }); + return eventById; + } catch (error) { + throw new Error(error); + } +}; + +const createEvent = async (eventInfo) => { + try { + const createdEvent = new EventModel(eventInfo); + + await createdEvent?.save(); + + return createdEvent; + } catch (error) { + throw new Error(error); + } +}; +const updateEvent = async (_id, updatedValue) => { + try { + const updatedEvent = await EventModel.findOneAndUpdate( + { _id: _id }, + { $set: updatedValue }, + { returnOriginal: false } + ); + + return updatedEvent; + } catch (error) { + throw new Error(error); + } +}; + +const deleteEvent = async (_id) => { + try { + const event = await EventModel.deleteOne({ _id: _id }); + return event; + } catch (error) { + throw new Error(error); + } +}; + +export const EventService = { + getAllEvents, + getEventsById, + getEventsBySlug, + createEvent, + updateEvent, + deleteEvent, +}; diff --git a/server/src/events/events.router.js b/server/src/events/events.router.js new file mode 100644 index 00000000..859324da --- /dev/null +++ b/server/src/events/events.router.js @@ -0,0 +1,70 @@ +import { EventService } from './event.service.js'; +import express from 'express'; + +export const eventRouter = express.Router(); + +//get all events +eventRouter.get('/', async (_, res) => { + try { + const events = await EventService.getAllEvents(); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get event by id +eventRouter.get('/id/:id', async (req, res) => { + try { + const { id } = req.params; + const events = await EventService.getEventsById(id); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get event by slug +eventRouter.get('/slug/:slug', async (req, res) => { + try { + const { slug } = req.params; + const events = await EventService.getEventsBySlug(slug); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); + +//add event +eventRouter.post('/create', async (req, res) => { + try { + const { data } = req.body; + const events = await EventService.createEvent(data); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); +//update events +eventRouter.post('/update/:id', async (req, res) => { + try { + const { id } = req.params; + const { data } = req.body; + + const events = await EventService.updateEvent(id, data); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); +//delete event by id + +eventRouter.post('/delete', async (req, res) => { + try { + const { id } = req.body; + const events = await EventService.deleteEvent(id); + res.status(200).send({ success: true, events: events }); + } catch (error) { + res.status(500).send(error); + } +}); diff --git a/server/src/hackathons/hackathon.router.js b/server/src/hackathons/hackathon.router.js new file mode 100644 index 00000000..56e76d68 --- /dev/null +++ b/server/src/hackathons/hackathon.router.js @@ -0,0 +1,75 @@ +import { HackathonService } from './hackathon.service.js'; +import express from 'express'; + +export const hackathonRouter = express.Router(); + +//get all hackathon + +hackathonRouter.get('/', async (_, res) => { + try { + const hackathon = await HackathonService.getAllHackathons(); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get hackathon by id + +hackathonRouter.get('/id/:id', async (req, res) => { + try { + const { id } = req.params; + const hackathon = await HackathonService.getHackathonsById(id); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); + +//get hackathon by slug + +hackathonRouter.get('/slug/:slug', async (req, res) => { + try { + const { slug } = req.params; + const hackathon = await HackathonService.getHackathonsBySlug(slug); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); + +//create hackathon +hackathonRouter.post('/create', async (req, res) => { + try { + const { data } = req.body; + const hackathon = await HackathonService.createHackathon(data); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); + +//update hackathon +hackathonRouter.post('/update/:id', async (req, res) => { + try { + const { id } = req.params; + const { data } = req.body; + + const hackathon = await HackathonService.updateHackathon(id, data); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); + +//delete hackathon by id + +hackathonRouter.post('/delete', async (req, res) => { + try { + const { id } = req.body; + const hackathon = await HackathonService.deleteHackathon(id); + res.status(200).send({ success: true, hackathon: hackathon }); + } catch (error) { + res.status(500).send(error); + } +}); diff --git a/server/src/hackathons/hackathon.service.js b/server/src/hackathons/hackathon.service.js new file mode 100644 index 00000000..e1da4a03 --- /dev/null +++ b/server/src/hackathons/hackathon.service.js @@ -0,0 +1,69 @@ +import { HackathonModel } from '../../schema/hackathon/hackathonSchema.js'; + +const getAllHackathons = async () => { + try { + const hackathon = await HackathonModel.find({}); + return hackathon; + } catch (error) { + throw new Error(error); + } +}; + +const getHackathonsById = async (_id) => { + try { + const hackathon = await HackathonModel.find({ _id }); + return hackathon; + } catch (error) { + throw new Error(error); + } +}; + +const getHackathonsBySlug = async (slug) => { + try { + const hackathon = await HackathonModel.find({ slug }); + return hackathon; + } catch (error) { + throw new Error(error); + } +}; + +const createHackathon = async (hackathonInfo) => { + try { + const hackathon = new HackathonModel(hackathonInfo); + await hackathon.save(); + return hackathon; + } catch (error) { + throw new Error(error); + } +}; +const updateHackathon = async (_id, updatedValue) => { + try { + const hackathon = await HackathonModel.findOneAndUpdate( + { _id: _id }, + { $set: updatedValue }, + { returnOriginal: false } + ); + + return hackathon; + } catch (error) { + throw new Error(error); + } +}; + +const deleteHackathon = async (_id) => { + try { + const hackathon = await HackathonModel.deleteOne({ _id: _id }); + return hackathon; + } catch (error) { + throw new Error(error); + } +}; + +export const HackathonService = { + getAllHackathons, + getHackathonsById, + getHackathonsBySlug, + createHackathon, + updateHackathon, + deleteHackathon, +}; diff --git a/server/src/users/user.router.js b/server/src/users/user.router.js new file mode 100644 index 00000000..a46157e2 --- /dev/null +++ b/server/src/users/user.router.js @@ -0,0 +1,62 @@ +import { UserService } from './user.service.js'; +import express from 'express'; + +export const userRouter = express.Router(); + +//get user by id + +userRouter.get('/:id', async (req, res) => { + try { + const { id } = req.params; + const user = await UserService.getUser(id); + res.status(200).send({ success: true, user: user }); + } catch (error) { + res.status(500).send(error); + } +}); + +//create user + +userRouter.post('/register', async (req, res) => { + try { + const { data } = req.body; + + const user = await UserService.createUser(data); + if (user === 'user exists') { + res.status(200).json({ message: 'User already exists' }); + } + res.status(200).send({ success: true, user: 'registration successful' }); + } catch (error) { + res.status(500).send(error); + } +}); + +//login user + +userRouter.post('/login', async (req, res) => { + try { + const user = await UserService.loginUser(); + if (user === 404) { + res.status(404).json({ message: 'User not found' }); + } + if (user === 401) { + res.status(401).json({ message: 'Invalid Credentials' }); + } + res.status(200).send({ success: true, user: 'login successful' }); + } catch (error) { + res.status(500).send(error); + } +}); + +//update user + +userRouter.post('/update/:id', async (req, res) => { + try { + const { id } = req.params; + + const user = await UserService.updateUser(id); + res.status(200).send({ success: true, user: user }); + } catch (error) { + res.status(500).send(error); + } +}); diff --git a/server/src/users/user.service.js b/server/src/users/user.service.js new file mode 100644 index 00000000..510a0477 --- /dev/null +++ b/server/src/users/user.service.js @@ -0,0 +1,51 @@ +import { UserModel } from '../../schema/user/UserSchema.js'; + +const register = async (userInfo) => { + try { + // const { email, ...data } = userInfo + + const newUser = new UserModel(userInfo); + await newUser.save(); + return newUser; + } catch (error) { + throw new Error(error); + } +}; + +// eslint-disable-next-line unused-imports/no-unused-vars +const login = async (userInfo) => { + try { + // const { email, password } = userInfo; + } catch (error) { + throw new Error(error); + } +}; + +const updateUser = async (_id, userInfo) => { + try { + const user = await UserModel.findOneAndUpdate( + { _id: _id }, + { $set: userInfo }, + { returnOriginal: false } + ); + return user; + } catch (error) { + throw new Error(error); + } +}; + +const getUser = async (_id) => { + try { + const user = await UserModel.findOne({ _id }); + return user; + } catch (error) { + throw new Error(error); + } +}; + +export const UserService = { + register, + login, + updateUser, + getUser, +}; From a4ed814899c6d9f009dfaee6ec517d96a8a79bc8 Mon Sep 17 00:00:00 2001 From: Sulagna Ghosh <62666287+suzy-g38@users.noreply.github.com> Date: Sat, 24 Jun 2023 22:10:29 +0530 Subject: [PATCH 4/8] Delete index.tsx --- src/pages/events/index.tsx | 128 ------------------------------------- 1 file changed, 128 deletions(-) delete mode 100644 src/pages/events/index.tsx diff --git a/src/pages/events/index.tsx b/src/pages/events/index.tsx deleted file mode 100644 index ca49eaa5..00000000 --- a/src/pages/events/index.tsx +++ /dev/null @@ -1,128 +0,0 @@ -import { sortEventsByFilter } from '@/lib/helper'; -import { EventType } from '@/lib/types'; - -import Event from '@/components/upcoming/Event'; - -import { NextPage } from 'next'; -import { useState } from 'react'; -import { BsFillFunnelFill } from 'react-icons/bs'; - -const events: EventType[] = [ - { - id: 'id1', - name: 'React India 2023', - location: 'Goa', - date: new Date('06 Oct 2023 GMT'), - link: 'https://www.reactindia.io/', - image: '/images/events/reactIndia.webp', - }, - { - id: 'id2', - name: 'HackCBS', - logo: '/images/events/kronos-logo.png', - location: 'New Delhi', - date: new Date('06 Sept 2023 GMT'), - link: 'https://hackcbs.tech/', - image: '/images/events/bg-2.webp', - }, - { - id: 'id3', - name: 'Hackerstellar', - location: 'New Delhi', - date: new Date('17 Sept 2023 GMT'), - link: 'https://hackerstellar.csikjsce.org/ ', - image: '/images/events/bg-3.jpeg', - }, - { - id: 'id4', - name: 'HackCBS', - location: 'New Delhi', - date: new Date('28 Sept 2023 GMT'), - link: 'https://hackcbs.tech/', - image: '/images/events/bg-4.webp', - }, - { - id: 'id5', - name: 'JSConf India 2023', - location: 'Bengaluru', - date: new Date('02 June 2023 GMT'), - link: 'https://jsconf.in/', - image: '/images/events/bg-4.webp', - }, -]; - -const cities = [ - 'Kolkata', - 'New Delhi', - 'Goa', - 'Mumbai', - 'Bangalore', - 'Hyderabad', - 'Chennai', -]; -const EventPage: NextPage = () => { - const [chosenCity, setChosenCity] = useState(''); - const [showFilter, setShowFilter] = useState(false); - const handleCityEvents = (city: string): void => { - setChosenCity(city); - setShowFilter(false); - }; - - const handleShowFilter = () => { - setShowFilter(!showFilter); - }; - - return ( -
-
-
- - Upcoming Events - -
-
- - -
- {showFilter && - cities.map((city, index) => ( -
handleCityEvents(city)} - className="cursor:pointer rounded-xl bg-base-100/70 text-center sm:pb-10 sm:pt-7 " - > -

{city}

-
- ))} -
-
-
- {sortEventsByFilter(events, chosenCity).length > 0 ? ( -
- {sortEventsByFilter(events, chosenCity).map((event) => ( - - ))} -
- ) : ( -
- - No Upcoming Events in {chosenCity} - -
- )} -
-
-
- ); -}; - -export default EventPage; From c6234c7488b39c4973eb7d2cd0ae25e55961328c Mon Sep 17 00:00:00 2001 From: Deependra Kumar Date: Sun, 25 Jun 2023 20:22:41 +0530 Subject: [PATCH 5/8] package installation --- server/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/server/package.json b/server/package.json index 9d99d621..e5a1e25e 100644 --- a/server/package.json +++ b/server/package.json @@ -15,6 +15,7 @@ "cors": "^2.8.5", "dotenv": "^16.3.1", "eslint": "^8.43.0", + "express": "^4.18.2", "http": "^0.0.1-security", "mongodb": "^5.6.0", "mongoose": "^7.3.1" From 27f8d67c4269c0d39ed4d73f26d988f1bb0b0d35 Mon Sep 17 00:00:00 2001 From: Deependra Kumar Date: Sun, 25 Jun 2023 20:29:15 +0530 Subject: [PATCH 6/8] add event file --- src/pages/events/index.tsx | 134 +++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 src/pages/events/index.tsx diff --git a/src/pages/events/index.tsx b/src/pages/events/index.tsx new file mode 100644 index 00000000..c81ecc9e --- /dev/null +++ b/src/pages/events/index.tsx @@ -0,0 +1,134 @@ +import { sortEventsByDate, sortEventsByFilter } from '@/lib/helper'; +import { EventType } from '@/lib/types'; + +import Event from '@/components/upcoming/Event'; + +import { NextPage } from 'next'; +import { useState } from 'react'; +import { BsFillFunnelFill } from 'react-icons/bs'; + +const events: EventType[] = [ + { + id: 'id1', + name: 'React India 2023', + location: 'Goa', + date: new Date('06 Oct 2023 GMT'), + link: 'https://www.reactindia.io/', + image: '/images/events/reactIndia.webp', + }, + { + id: 'id2', + name: 'HackCBS', + logo: '/images/events/kronos-logo.png', + location: 'New Delhi', + date: new Date('06 Sept 2023 GMT'), + link: 'https://hackcbs.tech/', + image: '/images/events/bg-2.webp', + }, + { + id: 'id3', + name: 'Hackerstellar', + location: 'New Delhi', + date: new Date('17 Sept 2023 GMT'), + link: 'https://hackerstellar.csikjsce.org/ ', + image: '/images/events/bg-3.jpeg', + }, + { + id: 'id4', + name: 'HackCBS', + location: 'New Delhi', + date: new Date('28 Sept 2023 GMT'), + link: 'https://hackcbs.tech/', + image: '/images/events/bg-4.webp', + }, + { + id: 'id5', + name: 'JSConf India 2023', + location: 'Bengaluru', + date: new Date('02 June 2023 GMT'), + link: 'https://jsconf.in/', + image: '/images/events/bg-4.webp', + }, +]; + +const cities = [ + 'Kolkata', + 'New Delhi', + 'Goa', + 'Mumbai', + 'Bangalore', + 'Hyderabad', + 'Chennai', +]; +const EventPage: NextPage = () => { + const [chosenCity, setChosenCity] = useState(''); + const [showFilter, setShowFilter] = useState(false); + const handleCityEvents = (city: string): void => { + setChosenCity(city); + setShowFilter(false); + }; + + const handleShowFilter = () => { + setShowFilter(!showFilter); + }; + + return ( +
+
+
+ + Upcoming Events + +
+
+ + +
+ {showFilter && + cities.map((city, index) => ( +
handleCityEvents(city)} + className="cursor:pointer rounded-xl bg-base-100/70 text-center sm:pb-10 sm:pt-7 " + > +

{city}

+
+ ))} +
+
+
+ {sortEventsByFilter(events, chosenCity).length > 0 ? ( +
+ {sortEventsByFilter(events, chosenCity).map((event) => ( + + ))} +
+ ) : ( +
+ + No Upcoming Events in {chosenCity} + +
+ )} + +
+ {sortEventsByDate(events).map((event) => ( + + ))} +
+
+
+
+ ); +}; + +export default EventPage; From 2fe51c37b327e02e2d86a1bb98d162dd6361842f Mon Sep 17 00:00:00 2001 From: Sulagna Ghosh <62666287+suzy-g38@users.noreply.github.com> Date: Sun, 25 Jun 2023 21:59:10 +0530 Subject: [PATCH 7/8] Update cfp.router.js --- server/src/cpfs/cfp.router.js | 1 + 1 file changed, 1 insertion(+) diff --git a/server/src/cpfs/cfp.router.js b/server/src/cpfs/cfp.router.js index 9f741972..22b784be 100644 --- a/server/src/cpfs/cfp.router.js +++ b/server/src/cpfs/cfp.router.js @@ -11,6 +11,7 @@ cfpRouter.get('/', async (_, res) => { res.status(200).send({ success: true, cfps: cfps }); } catch (error) { res.status(500).send(error); + console.error(error) } }); From ab20c9a0aaf8b8a6cb1e5900b2a4501605179528 Mon Sep 17 00:00:00 2001 From: Suzy Date: Tue, 27 Jun 2023 16:23:16 +0530 Subject: [PATCH 8/8] fix: security issues --- server/package.json | 5 +- server/schema/mongo.connect.js | 2 +- server/src/cpfs/cfp.router.js | 65 +++++++++++++++-------- server/src/cpfs/cfp.service.js | 27 +++++----- server/src/events/events.router.js | 34 +++++++++--- server/src/hackathons/hackathon.router.js | 34 +++++++++--- server/src/users/user.router.js | 18 +++++-- server/src/users/user.service.js | 2 +- 8 files changed, 129 insertions(+), 58 deletions(-) diff --git a/server/package.json b/server/package.json index 9d99d621..4c270f97 100644 --- a/server/package.json +++ b/server/package.json @@ -15,8 +15,11 @@ "cors": "^2.8.5", "dotenv": "^16.3.1", "eslint": "^8.43.0", + "express": "^4.18.2", "http": "^0.0.1-security", + "husky": "^8.0.3", "mongodb": "^5.6.0", - "mongoose": "^7.3.1" + "mongoose": "^7.3.1", + "prettier": "^2.8.8" } } diff --git a/server/schema/mongo.connect.js b/server/schema/mongo.connect.js index 8b5e6cf3..2ab8c1d8 100644 --- a/server/schema/mongo.connect.js +++ b/server/schema/mongo.connect.js @@ -18,6 +18,6 @@ export const mongoConnect = async () => { console.log('connection'); await connect(connectionString); } catch (error) { - throw new Error(String(error)); + throw new Error(error); } }; diff --git a/server/src/cpfs/cfp.router.js b/server/src/cpfs/cfp.router.js index 9f741972..78ca27fd 100644 --- a/server/src/cpfs/cfp.router.js +++ b/server/src/cpfs/cfp.router.js @@ -3,72 +3,91 @@ import express from 'express'; export const cfpRouter = express.Router(); -//get all cfps - +// get all cfps cfpRouter.get('/', async (_, res) => { try { const cfps = await CfpService.getAllCfps(); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); -//get cfp by id - +// get cfp by id cfpRouter.get('/id/:id', async (req, res) => { try { const { id } = req.params; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + const cfps = await CfpService.getCfpsById(id); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); -//get cfp by slug - +// get cfp by slug cfpRouter.get('/slug/:slug', async (req, res) => { try { const { slug } = req.params; + if (!slug) { + res + .status(422) + .send({ success: false, message: 'Invalid slug parameter' }); + } + const cfps = await CfpService.getCfpsBySlug(slug); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); -//add cfp +// add cfp cfpRouter.post('/create', async (req, res) => { try { const { data } = req.body; + + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const cfps = await CfpService.createCfp(data); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); -//update cfp + +// update cfp cfpRouter.post('/update/:id', async (req, res) => { try { const { id } = req.params; const { data } = req.body; - + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const cfps = await CfpService.updateCfp(id, data); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); -//delete cfp by id - +// delete cfp by id cfpRouter.post('/delete', async (req, res) => { try { const { id } = req.body; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id' }); + } const cfps = await CfpService.deleteCfp(id); - res.status(200).send({ success: true, cfps: cfps }); + res.status(200).send({ success: true, cfps }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); diff --git a/server/src/cpfs/cfp.service.js b/server/src/cpfs/cfp.service.js index dc3f2047..ac7fcf39 100644 --- a/server/src/cpfs/cfp.service.js +++ b/server/src/cpfs/cfp.service.js @@ -2,9 +2,8 @@ import { CfpModel } from '../../schema/cfps/CfpsSchema.js'; const getAllCfps = async () => { try { - const cfp = await CfpModel.find({}); - - return cfp; + const cfps = await CfpModel.find({}); + return cfps; } catch (error) { throw new Error(error); } @@ -12,8 +11,8 @@ const getAllCfps = async () => { const getCfpsById = async (_id) => { try { - const cfp = await CfpModel.find({ _id }); - return cfp; + const cfps = await CfpModel.findById(_id); + return cfps; } catch (error) { throw new Error(error); } @@ -21,8 +20,8 @@ const getCfpsById = async (_id) => { const getCfpsBySlug = async (slug) => { try { - const cfp = await CfpModel.find({ slug }); - return cfp; + const cfps = await CfpModel.find({ slug }); + return cfps; } catch (error) { throw new Error(error); } @@ -37,15 +36,15 @@ const createCfp = async (eventInfo) => { throw new Error(error); } }; + const updateCfp = async (_id, updatedValue) => { try { - const cfp = await CfpModel.findOneAndUpdate( - { _id: _id }, + const cfps = await CfpModel.findByIdAndUpdate( + _id, { $set: updatedValue }, - { returnOriginal: false } + { new: true } ); - - return cfp; + return cfps; } catch (error) { throw new Error(error); } @@ -53,8 +52,8 @@ const updateCfp = async (_id, updatedValue) => { const deleteCfp = async (_id) => { try { - const cfp = await CfpModel.deleteOne({ _id: _id }); - return cfp; + const cfps = await CfpModel.deleteOne({ _id }); + return cfps; } catch (error) { throw new Error(error); } diff --git a/server/src/events/events.router.js b/server/src/events/events.router.js index 859324da..a7ef2e4c 100644 --- a/server/src/events/events.router.js +++ b/server/src/events/events.router.js @@ -9,7 +9,7 @@ eventRouter.get('/', async (_, res) => { const events = await EventService.getAllEvents(); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -17,10 +17,14 @@ eventRouter.get('/', async (_, res) => { eventRouter.get('/id/:id', async (req, res) => { try { const { id } = req.params; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + const events = await EventService.getEventsById(id); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -28,10 +32,15 @@ eventRouter.get('/id/:id', async (req, res) => { eventRouter.get('/slug/:slug', async (req, res) => { try { const { slug } = req.params; + if (!slug) { + res + .status(422) + .send({ success: false, message: 'Invalid slug parameter' }); + } const events = await EventService.getEventsBySlug(slug); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -39,10 +48,14 @@ eventRouter.get('/slug/:slug', async (req, res) => { eventRouter.post('/create', async (req, res) => { try { const { data } = req.body; + + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const events = await EventService.createEvent(data); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); //update events @@ -51,10 +64,16 @@ eventRouter.post('/update/:id', async (req, res) => { const { id } = req.params; const { data } = req.body; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const events = await EventService.updateEvent(id, data); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); //delete event by id @@ -62,9 +81,12 @@ eventRouter.post('/update/:id', async (req, res) => { eventRouter.post('/delete', async (req, res) => { try { const { id } = req.body; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id' }); + } const events = await EventService.deleteEvent(id); res.status(200).send({ success: true, events: events }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); diff --git a/server/src/hackathons/hackathon.router.js b/server/src/hackathons/hackathon.router.js index 56e76d68..5037a0b6 100644 --- a/server/src/hackathons/hackathon.router.js +++ b/server/src/hackathons/hackathon.router.js @@ -10,7 +10,7 @@ hackathonRouter.get('/', async (_, res) => { const hackathon = await HackathonService.getAllHackathons(); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -19,10 +19,15 @@ hackathonRouter.get('/', async (_, res) => { hackathonRouter.get('/id/:id', async (req, res) => { try { const { id } = req.params; + + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + const hackathon = await HackathonService.getHackathonsById(id); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -31,10 +36,16 @@ hackathonRouter.get('/id/:id', async (req, res) => { hackathonRouter.get('/slug/:slug', async (req, res) => { try { const { slug } = req.params; + if (!slug) { + res + .status(422) + .send({ success: false, message: 'Invalid slug parameter' }); + } + const hackathon = await HackathonService.getHackathonsBySlug(slug); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -42,10 +53,14 @@ hackathonRouter.get('/slug/:slug', async (req, res) => { hackathonRouter.post('/create', async (req, res) => { try { const { data } = req.body; + + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const hackathon = await HackathonService.createHackathon(data); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -54,11 +69,16 @@ hackathonRouter.post('/update/:id', async (req, res) => { try { const { id } = req.params; const { data } = req.body; - + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const hackathon = await HackathonService.updateHackathon(id, data); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -70,6 +90,6 @@ hackathonRouter.post('/delete', async (req, res) => { const hackathon = await HackathonService.deleteHackathon(id); res.status(200).send({ success: true, hackathon: hackathon }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); diff --git a/server/src/users/user.router.js b/server/src/users/user.router.js index a46157e2..67cb0d63 100644 --- a/server/src/users/user.router.js +++ b/server/src/users/user.router.js @@ -8,10 +8,13 @@ export const userRouter = express.Router(); userRouter.get('/:id', async (req, res) => { try { const { id } = req.params; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } const user = await UserService.getUser(id); res.status(200).send({ success: true, user: user }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -20,14 +23,16 @@ userRouter.get('/:id', async (req, res) => { userRouter.post('/register', async (req, res) => { try { const { data } = req.body; - + if (!data) { + res.status(422).send({ success: false, message: 'Invalid data' }); + } const user = await UserService.createUser(data); if (user === 'user exists') { res.status(200).json({ message: 'User already exists' }); } res.status(200).send({ success: true, user: 'registration successful' }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -44,7 +49,7 @@ userRouter.post('/login', async (req, res) => { } res.status(200).send({ success: true, user: 'login successful' }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); @@ -54,9 +59,12 @@ userRouter.post('/update/:id', async (req, res) => { try { const { id } = req.params; + if (!id) { + res.status(422).send({ success: false, message: 'Invalid id parameter' }); + } const user = await UserService.updateUser(id); res.status(200).send({ success: true, user: user }); } catch (error) { - res.status(500).send(error); + res.status(500).json({ success: false, message: 'Internal server error' }); } }); diff --git a/server/src/users/user.service.js b/server/src/users/user.service.js index 510a0477..74e998ec 100644 --- a/server/src/users/user.service.js +++ b/server/src/users/user.service.js @@ -13,7 +13,7 @@ const register = async (userInfo) => { }; // eslint-disable-next-line unused-imports/no-unused-vars -const login = async (userInfo) => { +const login = async () => { try { // const { email, password } = userInfo; } catch (error) {