Skip to content
Merged
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
18 changes: 15 additions & 3 deletions backend/controllers/questionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ const Session = require("../models/Session");
const addQuestionToSession = async (req, res) => {
try {
const { sessionId, questions } = req.body;


if (!sessionId || !Array.isArray(questions) || questions.length === 0) {
return res.status(400).json({
success: false,
message: "Valid sessionId and non-empty questions array are required.",
});
}

const session = await Session.findById(sessionId);

if (!session) {
Expand Down Expand Up @@ -65,6 +72,11 @@ const addQuestionToSession = async (req, res) => {
const togglePinQuestion = async (req, res) => {
try {
const question = await Question.findById(req.params.id);
if (!question) {
return res
.status(404)
.json({ success: false, message: "Question not found" });
}

const session = await Session.findById(question.session);
if (!session) {
Expand All @@ -73,7 +85,7 @@ const togglePinQuestion = async (req, res) => {
.json({ success: false, message: "Session not found" });
}

if (session.user.toString() !== req.user.id) {
if (session.user.toString() !== req.user._id.toString()) {
return res.status(403).json({
success: false,
message: "Unauthorized access",
Expand Down Expand Up @@ -124,7 +136,7 @@ const updateQuestionNote = async (req, res) => {
.json({ success: false, message: "Session not found" });
}

if (session.user.toString() !== req.user.id) {
if (session.user.toString() !== req.user._id.toString()) {
return res.status(403).json({
success: false,
message: "Unauthorized access",
Expand Down
4 changes: 2 additions & 2 deletions backend/controllers/resumeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ const Resume = require("../models/Resume");
const saveResume = async (req, res) => {
try {
const { title, latexCode, resumeId } = req.body;
const userId = req.user._id || req.user.id;
const userId = req.user._id;

if (!title || !latexCode) {
return res.status(400).json({ success: false, message: "Title and LaTeX code are required." });
Expand Down Expand Up @@ -249,7 +249,7 @@ const saveResume = async (req, res) => {
*/
const getMyResumes = async (req, res) => {
try {
const userId = req.user._id || req.user.id;
const userId = req.user._id;
const resumes = await Resume.find({ user: userId }).sort({ updatedAt: -1 });
res.status(200).json({ success: true, resumes });
} catch (error) {
Expand Down
10 changes: 5 additions & 5 deletions backend/controllers/sessionController.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ exports.createSession = async (req, res) => {
*/
exports.getMySessions = async (req, res) => {
try {
const userId = req.user._id || req.user.id;
const userId = req.user._id;
const session = await Session.find({ user: userId })
.sort({ createdAt: -1 })
.populate("questions");
Expand Down Expand Up @@ -160,10 +160,10 @@ exports.deleteSession = async (req, res) => {
const { id } = req.params;
const userId = req.user._id;

const session = await Session.findOne({
_id: id,
user: userId,
}).session(transaction);
const session = await Session.findOne({
_id: id,
user: userId,
}).session(transaction);

if (!session) {
throw new Error("SESSION_NOT_FOUND");
Expand Down
Loading