Skip to content

Commit

Permalink
Merge pull request #80 from tanish35/master
Browse files Browse the repository at this point in the history
Add github workflow
  • Loading branch information
tanish35 authored Oct 7, 2024
2 parents 045c547 + 9487f29 commit 1d90eca
Show file tree
Hide file tree
Showing 6 changed files with 526 additions and 66 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/issue_fetcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Fetch Issue Details

on:
issue_comment:
types: [created]

jobs:
fetch-issue-details:
runs-on: ubuntu-latest
steps:
- name: Check if comment references an issue
id: check
run: |
echo "COMMENT_BODY=${{ github.event.comment.body }}" >> $GITHUB_ENV
echo "ISSUE_NUMBER=$(echo '${{ github.event.comment.body }}' | grep -o '#[0-9]*' | tr -d '#')" >> $GITHUB_ENV
if [ -z "${{ env.ISSUE_NUMBER }}" ]; then
echo "No issue reference found." >> $GITHUB_ENV
exit 0
fi
- name: Fetch issue details
id: fetch_issue
run: |
ISSUE_DETAILS=$(gh issue view ${{ env.ISSUE_NUMBER }} --json title,body,state)
echo "ISSUE_DETAILS=${ISSUE_DETAILS}" >> $GITHUB_ENV
- name: Post issue details as a comment
if: success() && env.ISSUE_NUMBER != ''
run: |
gh issue comment ${{ github.event.issue.number }} --body "Issue #${{ env.ISSUE_NUMBER }} Details:\n\nTitle: ${{ fromJson(env.ISSUE_DETAILS).title }}\n\nState: ${{ fromJson(env.ISSUE_DETAILS).state }}\n\nDescription:\n\n${{ fromJson(env.ISSUE_DETAILS).body }}"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78 changes: 72 additions & 6 deletions backend/src/controllers/userControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ const googleSignInOrSignUp = asyncHandler(
},
});
if (!user) {
let isCollegeEmail;

if (checkCollegeEmail(email)) {
isCollegeEmail = true;
} else {
isCollegeEmail = await Verifier.isAcademic(email);
}
const user = await prisma.user.create({
data: {
email,
name: displayName,
collegeEmailVerified: false,
collegeEmailVerified: isCollegeEmail,
emailVerified: true,
},
});
Expand All @@ -35,16 +42,18 @@ const googleSignInOrSignUp = asyncHandler(
secure: false,
sameSite: "lax",
});
return res.status(201).json({ message: "User created" });
const userId = user.user_id;
return res.status(201).json({ isCollegeEmail, userId });
}
const exp = Date.now() + 1000 * 60 * 60 * 24 * 30;
const isCollegeEmail = false;
const token = jwt.sign({ sub: user.user_id, exp }, process.env.SECRET);
res.cookie("Authorization", token, {
httpOnly: true,
secure: false,
sameSite: "lax",
});
res.status(200).json({ message: "User logged in" });
res.status(200).json({ isCollegeEmail });
}
);

Expand All @@ -65,11 +74,18 @@ const githubSignInOrSignUp = asyncHandler(
}

if (!user) {
let isCollegeEmail;

if (checkCollegeEmail(email)) {
isCollegeEmail = true;
} else {
isCollegeEmail = await Verifier.isAcademic(email);
}
const user = await prisma.user.create({
data: {
email,
name: displayName,
collegeEmailVerified: false,
collegeEmailVerified: isCollegeEmail,
emailVerified: true,
},
});
Expand All @@ -80,16 +96,17 @@ const githubSignInOrSignUp = asyncHandler(
secure: false,
sameSite: "lax",
});
return res.status(201).json({ message: "User created" });
return res.status(201).json({ isCollegeEmail });
}
const exp = Date.now() + 1000 * 60 * 60 * 24 * 30;
const isCollegeEmail = false;
const token = jwt.sign({ sub: user.user_id, exp }, process.env.SECRET);
res.cookie("Authorization", token, {
httpOnly: true,
secure: false,
sameSite: "lax",
});
res.status(200).json({ message: "User logged in" });
res.status(200).json({ isCollegeEmail });
}
);

Expand Down Expand Up @@ -394,6 +411,54 @@ const addCourseToUser = asyncHandler(async (req: Request, res: Response) => {
res.status(201).json({ message: "Course added to user" });
});

// @ts-ignore
const addDetailsToUser = asyncHandler(async (req: Request, res: Response) => {
const { collegeName, courseName, isOnline, location, id } = req.body;
if (!collegeName || !courseName || !location || isOnline === undefined) {
return res.status(400).json({ message: "Please provide all fields" });
}
let college = await prisma.college.findFirst({
where: {
name: collegeName,
},
});
if (!college) {
college = await prisma.college.create({
data: {
name: collegeName,
location,
},
});
}
const college_id = college.college_id;
let course = await prisma.course.findFirst({
where: {
name: courseName,
},
});
let course_id;
if (course) {
course_id = course.course_id;
} else {
course = await prisma.course.create({
data: {
name: courseName,
college_id,
isOnline,
},
});
course_id = course.course_id;
}
await prisma.userCourse.create({
data: {
user_id: id,
course_id,
college_id,
},
});
res.status(201).json({ message: "Course added to user" });
});

export {
registerUser,
loginUser,
Expand All @@ -403,4 +468,5 @@ export {
addCourseToUser,
googleSignInOrSignUp,
githubSignInOrSignUp,
addDetailsToUser,
};
2 changes: 2 additions & 0 deletions backend/src/routes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
addCourseToUser,
googleSignInOrSignUp,
githubSignInOrSignUp,
addDetailsToUser,
} from "../controllers/userControllers";
import checkAuth from "../middleware/checkAuth";

Expand All @@ -22,5 +23,6 @@ router.get("/get/:userId", checkAuth, getUserDetailsById); // get the user detai
router.post("/addcourse", checkAuth, addCourseToUser); // add a course to the current user
router.post("/google", googleSignInOrSignUp); // sign in or sign up using google
router.post("/github", githubSignInOrSignUp); // sign in or sign up using github
router.post("/addDetails", checkAuth, addDetailsToUser); // add details to the current user

export default router;
Loading

0 comments on commit 1d90eca

Please sign in to comment.