-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Main #196
Open
snehas-05
wants to merge
4
commits into
Harshdev098:main
Choose a base branch
from
snehas-05:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Main #196
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -173,6 +173,37 @@ Follow these steps to run the Research Nexas | |
password varchar(120) unique, | ||
token varchar(130) not null unique | ||
); | ||
|
||
Create the 'badges' table | ||
CREATE TABLE badges ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
name VARCHAR(255) NOT NULL, | ||
description TEXT NOT NULL, | ||
criteria VARCHAR(255) | ||
); | ||
|
||
-- Create the 'student_badges' table (stores which student earned which badge) | ||
CREATE TABLE student_badges ( | ||
id INT AUTO_INCREMENT PRIMARY KEY, | ||
student_id INT NOT NULL, | ||
badge_id INT NOT NULL, | ||
awarded_at DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
FOREIGN KEY (student_id) REFERENCES students(id) ON DELETE CASCADE, | ||
FOREIGN KEY (badge_id) REFERENCES badges(id) ON DELETE CASCADE | ||
); | ||
|
||
|
||
-- Insert some example data into 'student' table | ||
INSERT INTO student (name, email) VALUES ('Alice', '[email protected]'); | ||
|
||
-- Insert example badges into 'badges' table | ||
INSERT INTO badges (name, description, criteria) VALUES | ||
('Research Contributor', 'Awarded for submitting 5 research papers', 'Submit 5 papers'), | ||
('Peer Reviewer', 'Awarded for completing 10 peer reviews', 'Complete 10 reviews'); | ||
|
||
-- Award badges to student (student_badges table) | ||
INSERT INTO student_badges (user_id, badge_id) VALUES (1, 1), (1, 2); | ||
|
||
``` | ||
- Now open code editor(eg. VS Code) | ||
- Now run the following commands in your terminal | ||
|
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 @@ | ||
// Fetch user's badges | ||
function fetchBadges(userId) { | ||
fetch(`/badges/${userId}`) | ||
.then(response => response.json()) | ||
.then(badges => { | ||
const badgeContainer = document.getElementById('badge-container'); | ||
badgeContainer.innerHTML = ''; | ||
|
||
badges.forEach(badge => { | ||
const badgeElement = document.createElement('div'); | ||
badgeElement.classList.add('badge'); | ||
badgeElement.innerHTML = ` | ||
<h3>${badge.name}</h3> | ||
<p>${badge.description}</p> | ||
<small>Earned on: ${new Date(badge.earned_at).toLocaleDateString()}</small> | ||
`; | ||
badgeContainer.appendChild(badgeElement); | ||
}); | ||
}) | ||
.catch(error => console.error('Error fetching badges:', error)); | ||
} | ||
|
||
// Replace with actual userId | ||
fetchBadges(1); | ||
|
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,31 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const db = require('../db'); // Assuming db.js has your MySQL config | ||
|
||
// Get all badges for a user | ||
router.get('/:userId', (req, res) => { | ||
const { userId } = req.params; | ||
const sql = ` | ||
SELECT badges.name, badges.description, user_badges.earned_at | ||
FROM badges | ||
JOIN user_badges ON badges.id = user_badges.badge_id | ||
WHERE user_badges.user_id = ?`; | ||
|
||
db.query(sql, [userId], (err, results) => { | ||
if (err) throw err; | ||
res.json(results); | ||
}); | ||
}); | ||
|
||
// Award a new badge to a user | ||
router.post('/award', (req, res) => { | ||
const { userId, badgeId } = req.body; | ||
const sql = `INSERT INTO user_badges (user_id, badge_id) VALUES (?, ?)`; | ||
|
||
db.query(sql, [userId, badgeId], (err, result) => { | ||
if (err) throw err; | ||
res.json({ message: 'Badge awarded successfully' }); | ||
}); | ||
}); | ||
|
||
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 |
---|---|---|
|
@@ -14,6 +14,29 @@ const { allot, DisplayPapers } = require("../stakeholder/allotment"); | |
const { Dis_fac_papers, fac_signup, fac_login, dis_mail, giverating } = require("../stakeholder/faculty"); | ||
const app = express(); | ||
|
||
const mysql = require('mysql2'); | ||
const dotenv = require('dotenv'); | ||
dotenv.config(); | ||
|
||
const db = mysql.createConnection({ | ||
host: process.env.DB_HOST, | ||
user: process.env.DB_USER, | ||
password: process.env.DB_PASS, | ||
database: process.env.DB_NAME | ||
}); | ||
|
||
db.connect((err) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the function in the config folder will connect to the database remove these lines of code to connect the db |
||
if (err) throw err; | ||
console.log('MySQL connected...'); | ||
}); | ||
|
||
// Importing and setting up the badgesRouter to handle all badge-related routes | ||
// This allows endpoints like '/badges/create' or '/badges/view' to be managed | ||
// within the badgesRouter module, keeping route organization modular and clean | ||
const badgesRouter = require('./routes/badges'); | ||
app.use('/badges', badgesRouter); | ||
|
||
|
||
const globalLimit = rateLimiter({ | ||
windowMs: 30 * 60 * 1000, | ||
max: 100, | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
instead of importing mysql module you can import the function in the config folder of main branch