-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: solve repetition in events * fix: fix error for react import * feat: add server * Delete index.tsx * package installation * add event file * Update cfp.router.js * fix: security issues --------- Co-authored-by: Deependra Kumar <[email protected]>
- Loading branch information
Showing
18 changed files
with
885 additions
and
2 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,3 @@ | ||
node_modules | ||
.env | ||
yarn.lock |
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,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}`)); |
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,25 @@ | ||
{ | ||
"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", | ||
"express": "^4.18.2", | ||
"http": "^0.0.1-security", | ||
"husky": "^8.0.3", | ||
"mongodb": "^5.6.0", | ||
"mongoose": "^7.3.1", | ||
"prettier": "^2.8.8" | ||
} | ||
} |
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,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); |
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,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); |
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,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); |
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,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(error); | ||
} | ||
}; |
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,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); |
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,93 @@ | ||
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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
// 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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
// 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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
// 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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
// 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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); | ||
|
||
// 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 }); | ||
} catch (error) { | ||
res.status(500).json({ success: false, message: 'Internal server error' }); | ||
} | ||
}); |
Oops, something went wrong.
b37b38d
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
vibey – ./
vibey-git-main-unikonf-vibey.vercel.app
vibey-unikonf-vibey.vercel.app
vibey.vercel.app
www.vibey.live
vibey.live