Skip to content

Commit

Permalink
Merge branch 'main' into upload-image
Browse files Browse the repository at this point in the history
  • Loading branch information
hustlerZzZ authored Jun 26, 2024
2 parents 31f6081 + a0ec7c8 commit a712eaf
Show file tree
Hide file tree
Showing 25 changed files with 956 additions and 292 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/autocomment-iss-close.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Comment on Issue Close

on:
Expand Down Expand Up @@ -26,4 +27,34 @@ jobs:
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
=======
name: Comment on Issue Close

on:
issues:
types: [closed]

jobs:
greet-on-close:
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Greet User
uses: actions/github-script@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const issue = context.payload.issue;
const issueCreator = issue.user.login;
const issueNumber = issue.number;
const greetingMessage = `Hello @${issueCreator}! Your issue #${issueNumber} has been closed. Thank you for your contribution!`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueNumber,
body: greetingMessage
>>>>>>> Stashed changes
});
39 changes: 39 additions & 0 deletions .github/workflows/close-old-issue.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Close Old Issues
on:
schedule:
Expand Down Expand Up @@ -34,4 +35,42 @@ jobs:
-d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments"
fi
=======
name: Close Old Issues
on:
schedule:
- cron: "0 0 * * *"

jobs:
close-issues:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Close Old Issues
run: |
open_issues=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues?state=open" \
| jq -r '.[] | .number')
for issue in $open_issues; do
# Get the last updated timestamp of the issue
last_updated=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue" \
| jq -r '.updated_at')
days_since_update=$(( ( $(date +%s) - $(date -d "$last_updated" +%s) ) / 86400 ))
if [ $days_since_update -gt 30 ]; then
curl -s -X PATCH -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"state":"closed"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue"
# Add a comment explaining when the issue will be closed
curl -s -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github.v3+json" \
-d '{"body":"This issue has been automatically closed because it has been inactive for more than 30 days. If you believe this is still relevant, feel free to reopen it or create a new one. Thank you!"}' \
"https://api.github.com/repos/${{ github.repository }}/issues/$issue/comments"
fi
>>>>>>> Stashed changes
done
37 changes: 37 additions & 0 deletions .github/workflows/close-old-pr.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< Updated upstream
name: Close Stale PRs

on:
Expand Down Expand Up @@ -32,3 +33,39 @@ jobs:
operations-per-run: 30
remove-stale-when-updated: true
debug-only: false
=======
name: Close Stale PRs

on:
schedule:
- cron: '0 0 * * *' # Runs daily at midnight
pull_request:
types:
- opened
- reopened
- synchronize

permissions:
pull-requests: write
issues: write

jobs:
close_stale_prs:
runs-on: ubuntu-latest
permissions:
pull-requests: write

steps:
- uses: actions/stale@v7
with:
repo-token: ${{ secrets.GH_TOKEN }}
stale-pr-message: 'This PR has been automatically closed due to inactivity from the owner for 15 days.'
days-before-pr-stale: 15
days-before-pr-close: 0
exempt-pr-author: false
exempt-pr-labels: ''
only-labels: ''
operations-per-run: 30
remove-stale-when-updated: true
debug-only: false
>>>>>>> Stashed changes
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<head>
<meta charset="utf-8" />
<!-- <link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> -->
<link rel="icon" type="image/x-icon" href="./Favicon.jpg">
<link rel="icon" type="image/x-icon" href="./new_favicon.png">
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta
Expand Down
Binary file added public/new_favicon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
40 changes: 40 additions & 0 deletions server/config/passport.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const passport = require('passport');
const GoogleStrategy = require('passport-google-oauth20').Strategy;
const User = require('../models/studentLoginInfo');
const Canteen = require('../models/canteenLoginInfo');

passport.use(new GoogleStrategy({
clientID: process.env.GOOGLE_CLIENT_ID,
clientSecret: process.env.GOOGLE_CLIENT_SECRET,
callbackURL: '/auth/google/callback'
},
async (accessToken, refreshToken, profile, done) => {
try {
let user = await User.findOne({ googleId: profile.id });
if (!user) {
user = await User.create({
googleId: profile.id,
name: profile.displayName,
email: profile.emails[0].value,
});
}
return done(null, user);
} catch (error) {
return done(error, null);
}
}));

passport.serializeUser((user, done) => {
done(null, user.id);
});

passport.deserializeUser(async (id, done) => {
try {
const user = await User.findById(id);
done(null, user);
} catch (error) {
done(error, null);
}
});

module.exports = passport;
40 changes: 31 additions & 9 deletions server/controllers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ exports.studentSignup = async (req, res) => {
console.log("This is jwt", process.env.JWT_SECRET);
try {
console.log(req.body);
const { name, email, collegeName, accountType, password, confirmPassword } =
await req.body;
const { name, email, collegeName, accountType, password, confirmPassword } = req.body;

if (password !== confirmPassword) {
return res.status(400).json({
Expand All @@ -28,14 +27,12 @@ exports.studentSignup = async (req, res) => {
});
}

const existingUser = await User.findOne({
email,
});
const existingUser = await User.findOne({ email });

if (existingUser) {
return res.status(400).json({
success: false,
message: "User alredy exist",
message: "User already exists",
});
}

Expand All @@ -59,17 +56,42 @@ exports.studentSignup = async (req, res) => {
password: hashedPassword,
});

await user.save();
const payload = {
email: user.email,
id: user._id,
accountType: user.accountType,
};

let token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "2h",
});

// creating a session
const session = new Session({
userId: user._id,
token,
});
await session.save();

user.password = undefined;

res.cookie("token", token, {
httpOnly: true,
secure: true,
maxAge: 3600000,
});

return res.status(200).json({
success: true,
message: "User created succesfully",
message: "User created successfully",
token,
user,
});
} catch (error) {
console.error(error);
return res.status(500).json({
success: false,
message: "USer can not be registred",
message: "User cannot be registered",
});
}
};
Expand Down
88 changes: 88 additions & 0 deletions server/controllers/canteenController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const Dinner = require('../models/dinner');
const Canteen = require("../models/canteenLoginInfo");
const { uploader, uploadImage } = require('../config/cloudinaryConfig');

const Feedback = require("../models/feedback")
const Session = require("../models/session")




const getAllCanteen = async (req ,res , next) =>{
Expand Down Expand Up @@ -41,6 +45,87 @@ const getBreakfast = async (req, res, next) => {
res.status(500).json({ success: false, error: error.message });
}
};
catch(error){
res.status(500).json({success : false , error : error});
}
}
const feedback = async (req, res) => {
const { canteenId, feedback, rating } = req.body;
const token = req.body.studentId; // This is the token

try {
// Find the session with the given token
const session = await Session.findOne({ token });

if (!session) {
return res.status(404).json({ message: 'Session not found' });
}

const userId = session.userId; // Extract userId from the session

const newFeedback = new Feedback({
canteen: canteenId,
student: userId,
comment: feedback,
rating: rating,
});

const savedFeedback = await newFeedback.save();
res.status(201).json(savedFeedback);
} catch (error) {
res.status(500).json({ message: 'Error saving feedback', error: error.message });
}
};
const canteenFeedbackRender = async (req, res) => {
try {
const reviews = await Feedback.aggregate([
{ $sample: { size: 3 } }, // Fetch 3 random feedback entries
{
$lookup: {
from: 'students', // Collection name for students
localField: 'student',
foreignField: '_id',
as: 'studentInfo'
}
},
{
$lookup: {
from: 'canteens', // Collection name for canteens
localField: 'canteen',
foreignField: '_id',
as: 'canteenInfo'
}
},
{
$addFields: {
studentName: { $arrayElemAt: ['$studentInfo.name', 0] },
canteenName: { $arrayElemAt: ['$canteenInfo.name', 0] }
}
},
{
$project: {
_id: 1,
comment: 1,
rating: 1,
createdAt: 1,
studentName: 1,
canteenName: 1
}
}
]);

res.json(reviews);
} catch (error) {
res.status(500).json({ message: error.message });
}
};

const getLunch = async(req , res , next) =>{

try{
const id = req.params.id;

const lunchData = await Lunch.find({ canteen: id }).select("dish").select("dishId").exec();

const getLunch = async (req, res, next) => {
try {
Expand Down Expand Up @@ -328,4 +413,7 @@ module.exports = {
updateBreakfastDish,
updateLunchDish,
updateDinnerDish,

feedback,
canteenFeedbackRender
};
29 changes: 29 additions & 0 deletions server/models/Review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const mongoose = require('mongoose');

const reviewSchema = new mongoose.Schema({
user_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
product_id: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Product',
required: true
},
rating: {
type: Number,
required: true,
min: 1,
max: 5
},
review_text: {
type: String,
required: true
}
}, {
timestamps: true
});

const Review = mongoose.model('Review', reviewSchema);
module.exports = Review;
Loading

0 comments on commit a712eaf

Please sign in to comment.