Skip to content

Commit

Permalink
small condition fix for checking if user same as request host
Browse files Browse the repository at this point in the history
  • Loading branch information
Goutam112 committed Nov 9, 2023
1 parent 3fe5340 commit 102bbd2
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions backend/controllers/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports.editLostRequest = async (req, res, next) => {
let imageUrls = [];

try {
if (lostItem.host !== user._id) {
if (!lostItem.host.equals(user._id)) {
throw new Error('403 Unauthorized: User does not own lost request');
}

Expand Down Expand Up @@ -134,7 +134,7 @@ module.exports.editFoundRequest = async (req, res, next) => {
let imageUrls = [];

try {
if (foundItem.host !== user._id) {
if (!foundItem.host.equals(user._id)) {
throw new Error('403 Unauthorized: User does not own found request');
}

Expand Down Expand Up @@ -195,7 +195,7 @@ module.exports.getSimilarItems = async (req, res, next) => {
if (!req.user._id.equals(lostItem.host._id)) {
return res.status(403).json({ message: 'Only the lost item host can fetch similar items' });
}

const foundItems = await FoundItem.find(
// exclude the current user's found items
// host: { $ne: mongoose.Types.ObjectId(excludedHostId) }
Expand Down Expand Up @@ -227,15 +227,15 @@ module.exports.getSimilarItems = async (req, res, next) => {
const topResults = searchResults
// .slice(0, 30) // Limit to the top 30 results
.map(result => ({ ...result.item._doc, score: result.score }));

res.status(200).json(topResults);
} catch (error) {
console.error("Error fetching similar items:", error);
res.status(500).json({ message: 'Error fetching similar items' });
}
}

async function uploadToS3(folder, file) {
async function uploadToS3 (folder, file) {
const fileName = `${folder}/${uuidv4()}-${file.originalname}`;

const command = new PutObjectCommand({
Expand Down

0 comments on commit 102bbd2

Please sign in to comment.