Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 18 additions & 13 deletions client/src/apis/student.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import { message } from "antd";

export const getStudent = async (id, navigate) => {
try {
console.log("get student", backendURL)
console.log("get student", backendURL);
const response = await axios.get(`${backendURL}/api/v1/students/${id}`, {
withCredentials: true,
withCredentials: true
});
console.log(response.data);
return response.data;
Expand All @@ -20,21 +20,20 @@ export const updateStudent = async (id, data) => {
try {
console.log(data);
const response = await axios.put(`${backendURL}/api/v1/students/${id}`, data, {
withCredentials: true,
withCredentials: true
});

return response.data;
} catch (error) {
console.log(error);
return error?.response?.data || error;

}
};

export const getAppliedJobsByStudents = async (id, navigate) => {
try {
const response = await axios.get(`${backendURL}/api/v1/students/${id}/intern-applied`, {
withCredentials: true,
withCredentials: true
});
console.log(response);
return response.data;
Expand All @@ -46,17 +45,23 @@ export const getAppliedJobsByStudents = async (id, navigate) => {

export const applyToJobs = async (id, internId, navigate) => {
try {
const response = await axios.post(`${backendURL}/api/v1/students/${id}/intern-apply/${internId}`, {
withCredentials: true,
});
const response = await axios.post(
`${backendURL}/api/v1/job/apply`,
{
job_id: internId,
user_id: id
},
{
headers: {
"Content-Type": "application/json"
},
withCredentials: true
}
);
// console.log(response);
return response.data;
} catch (error) {
console.log(error);
if (error?.response?.status === 400) {
message.error("Already Applied");
return error?.response?.data;
}
// navigate("/500");
return error?.response?.data || error;
}
Expand All @@ -65,7 +70,7 @@ export const applyToJobs = async (id, internId, navigate) => {
export const getAllStudents = async (navigate) => {
try {
const response = await axios.get(`${backendURL}/api/v1/students`, {
withCredentials: true,
withCredentials: true
});
return response.data;
} catch (error) {
Expand Down
16 changes: 6 additions & 10 deletions client/src/student/pages/internships/InternshipCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,21 @@ function InternshipCard({ arr }) {
message.success("Applied Successfully");
navigate(`/student/applied`);
} else {
// console.log(res);
if (res.message === "Already applied") {
return;
}
// message.error("Failed to apply");
message.error(res.message || "Failed to apply");
}
};

useEffect(() => {
if (arr.applicants) {
console.log(`applied ${arr}`);
const appliedOrNot = arr.applicants.find(
(person) => {if(person === user.connection_id){
const appliedOrNot = arr.applicants.find((person) => {
if (person === user.connection_id) {
console.log(person);
console.log(user.connection_id);
return true;
}}
);
console.log(appliedOrNot)
}
});
console.log(appliedOrNot);
if (appliedOrNot) {
setApplied(true);
}
Expand Down
6 changes: 1 addition & 5 deletions client/src/student/pages/internships/InternshipDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,7 @@ export default function DriveDetail() {
message.success("Applied Successfully");
navigate(`/student/applied`);
} else {
// console.log(res);
if (res.message === "Already applied") {
return;
}
// message.error("Failed to apply");
message.error(res.message || "Failed to apply");
}
};

Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"marked": "^12.0.2",
"mongoose": "^8.12.1",
"multer": "^1.4.5-lts.1",
"node-cron": "^4.1.1",
"node-fetch": "^3.3.2",
"querystring": "^0.2.1",
"sanitize-html": "^2.13.0",
Expand Down
36 changes: 26 additions & 10 deletions server/src/admin/controller/updates.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,27 @@
import logger from "../../utils/logger.js";
import Updates from "../models/updates.js";

import axios from "axios";
const createUpdate = async (req, res) => {
try {
const { title, description, link } = req.body;
const update = await Updates.create({ title, description, link });
logger.info(`Update created with ID: ${update._id}, title: ${title}`);

const notificationResponse = await axios.post(
`${process.env.NOTIFICATION_URL}/create`,
{
title,
message: description,
link,
},
{
headers: {
"Content-Type": "application/json",
},
}
);
logger.info("Notification sent successfully:", notificationResponse.data);

return res.status(201).json({
status: "success",
message: "Update created successfully",
Expand Down Expand Up @@ -45,7 +61,7 @@ const getUpdateById = async (req, res) => {
try {
const update = await Updates.findById(id);
if (!update) {
logger.warn(`Update with ID ${id} not found`);
logger.warn(`Update with ID ${id} not found`);
return res.status(404).json({
status: "error",
message: "Update not found",
Expand Down Expand Up @@ -81,14 +97,14 @@ const editUpdate = async (req, res) => {
data: null,
});
}

return res.status(200).json({
status: "success",
message: "Update edited successfully",
data: update,
});
} catch (err) {
logger.error(`Error editing update with ID ${id}: ${err.message}`);
logger.error(`Error editing update with ID ${id}: ${err.message}`);
res.status(500).json({
status: "error",
message: "Internal server error",
Expand All @@ -103,12 +119,12 @@ const deleteUpdate = async (req, res) => {
const { id } = req.params;
const update = await Updates.findByIdAndDelete(id);
if (!update) {
logger.warn(`update not found!`);
return res.status(404).json({
status: "error",
message: "Update not found",
data: null,
});
logger.warn(`update not found!`);
return res.status(404).json({
status: "error",
message: "Update not found",
data: null,
});
}
logger.info(`Update with ID ${id} was deleted`);
return res.status(200).json({
Expand Down
69 changes: 49 additions & 20 deletions server/src/auth/controllers/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ import dotenv from "dotenv";
import querystring from "querystring";
import jwt from "jsonwebtoken";
import { roles } from "../../utils/roles.js";
import { createUser, getUserFromToken } from "../../users/controller.js";
import {
createUser,
getUserFromToken,
generateEmailVerificationToken,
} from "../../users/controller.js";
import { User } from "../../users/model.js";
import logger from "../../utils/logger.js";
import { frontendUrl } from "../../../frontend-url.js";
Expand Down Expand Up @@ -97,6 +101,7 @@ export const onedriveRedirect = async (req, res) => {
user_id: findUser._id,
connection_id: findUser.connection_id,
typeOfUser: findUser.typeOfUser,
isVerified: findUser.isVerified,
};

const stringify = JSON.stringify(userCookie);
Expand All @@ -123,34 +128,58 @@ export const onedriveRedirect = async (req, res) => {
name: userDataFromGraphApi.name,
email: userDataFromGraphApi.email,
typeOfUser: state,
isVerified: false,
});

// Generate email verification token and send verification email
const verificationToken = generateEmailVerificationToken(createdUser);
const verificationLink = `${
process.env.EMAIL_VERIFICATION_URL || frontendUrl
}/api/users/verify?token=${verificationToken}`;
try {
await axios.post(`${process.env.EMAIL_URL}/send-email`, {
emails: [createdUser.email],
subject: "Verify your email for Research Intern Portal, IIT Guwahati",
message: `Welcome! Please verify your email by clicking the following link: ${verificationLink}\n\nIf you did not request this, please ignore this email.`,
});
} catch (err) {
logger.error("Failed to send verification email", err);
}

const newUserCookie = {
name: createdUser.name,
user_id: createdUser._id,
connection_id: createdUser.connection_id,
typeOfUser: createdUser.typeOfUser,
isVerified: createdUser.isVerified,
};

// if (newUserCookie) {
// try {
// await axios.post(`${process.env.NOTIFICATION_URL}/createOne`, {
// title: "Welcome to Research Intern Portal, IIT Guwahati",
// message:
// "We are glad to have you on board! Feel free to explore the platform and reach out to us in case of any queries. We recommend you to complete your profile to get the best experience.",
// link: `/profile`,
// userIds: [createdUser.connection_id],
// });
// await axios.post(`${process.env.EMAIL_URL}/send-email`, {
// emails: [createdUser.email],
// subject: "Welcome to Research Intern Portal, IIT Guwahati",
// message: `We are glad to have you on board! Feel free to explore the platform and reach out to us in case of any queries. We recommend you to complete your profile to get the best experience.`,
// });
// } catch (err) {
// console.log(err);
// logger.error(err);
// }
// }
if (newUserCookie) {
try {
const notificationResponse = await axios.post(
`${process.env.NOTIFICATION_URL}/createOne`,
{
title: "Welcome to Research Intern Portal, IIT Guwahati",
message:
"We are glad to have you on board! Feel free to explore the platform and reach out to us in case of any queries. We recommend you to complete your profile to get the best experience.",
link: `/${createdUser.typeOfUser}/profile/overview`,
userIds: [createdUser.connection_id],
},
{
headers: {
"Content-Type": "application/json",
},
}
);
logger.info(
"Notification sent successfully:",
notificationResponse.data
);
} catch (err) {
console.log(err);
logger.error(err);
}
}

const stringify = JSON.stringify(newUserCookie);

Expand Down
4 changes: 2 additions & 2 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import adminUpdateRoutes from "./admin/routes/updates.js";
import studentRoutes from "./students/routes/student.js";
import jobRoutes from "./recruiter/routes/jobs.js";
import recruiterRoutes from "./recruiter/routes/recruiter.js";

import jobExpiryNotifier from "./recruiter/notifier.js";
const app = express();

setupSwagger(app);
Expand Down Expand Up @@ -53,7 +53,6 @@ app.use("/api/v1/students", studentRoutes);
// app.use("/api/v1/recruiters", verifyJWT, recruiterGuard, recruiterRoutes);
app.use("/api/v1/recruiters", recruiterRoutes);
app.use("/api/v1/job", jobRoutes);

app.use("/api/v1/admin/bugs", bugRoutes);

// test route
Expand All @@ -65,5 +64,6 @@ app.get("/ping", (req, res) => {
app.use(errorHandler);
app.listen(data.PORT, async () => {
await connectToDb();
jobExpiryNotifier();
logger.info(`Server is running on ${data.PORT}`);
});
Loading