WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open

done #18

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
13 changes: 12 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const express = require("express");
const mongoose = require("mongoose");
const dotenv = require("dotenv");
const cors = require("cors");
require('dotenv').config();



const {
Expand Down Expand Up @@ -36,6 +38,7 @@ const {
filterActivityGuest,
guestFilterItineraries,
register,
getActivitiesByCategoryForGuest
} = require("./Routes/guestController");
const {
searchProductSeller,
Expand Down Expand Up @@ -74,6 +77,8 @@ const {
} = require("./Routes/adminController");

const {
getActivitiesByCategory,
shareItem,
SortActivities,
filterActivity,
searchProductTourist,
Expand All @@ -94,6 +99,8 @@ const {
addRatingAndComment,
updateTouristPreferences,
changePasswordTourist,

setPreferredCurrency,
addLoyaltyPoints,
fileComplaint,
viewMyComplaints,
Expand Down Expand Up @@ -155,7 +162,8 @@ app.get("/home", (req, res) => {
});

app.use(express.json());

app.get("/activities/by-category",getActivitiesByCategory);
app.post("/share",shareItem);
app.post("/addTourist", createTourist);
app.post("/register", register);

Expand Down Expand Up @@ -231,6 +239,8 @@ app.delete("/deleteTouristItineraries/:id", deleteTouristItinerary);
app.get("/tourist-itineraries", getItinerariesByDateRange);
app.get("/filterProducts", filterProducts);
app.get("/filterHistoricalTags", filterHistoricalByTag);
app.get("/activities/category",getActivitiesByCategoryForGuest);


//seller Controller
app.post("/createSeller", createSeller);
Expand Down Expand Up @@ -279,6 +289,7 @@ app.get("/getAdv/:id", getAdsById);

////////////////////////////////////////////
app.put("/cpTourist/:id", changePasswordTourist);
app.put("/cpTourist/:id/currency", setPreferredCurrency);
app.put("/cpAdmin/:id", changePasswordAdmin);
app.get("/getadmin", getadmin);
app.put("/cpAdvertiser/:id", changePasswordAdvertiser);
Expand Down
5 changes: 5 additions & 0 deletions src/Models/Tourist.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ const { ObjectId } = mongoose.Schema;

const touristSchema = new Schema(
{
preferredCurrency: {
type: String,
default: "USD" // Set a default currency, like USD
},
username: {
type: String,
required: true,
Expand Down Expand Up @@ -47,6 +51,7 @@ const touristSchema = new Schema(
required: true,
}
},

{ timestamps: true }
);

Expand Down
30 changes: 30 additions & 0 deletions src/Routes/guestController.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,39 @@ const filterHistoricalByTag = async (req, res) => {
}
};

const getActivitiesByCategoryForGuest = async (req, res) => {
const { category } = req.query; // Expecting category ID as a query parameter

if (!category) {
return res.status(400).json({ error: "Category is required to view activities." });
}
// Check if the category is a valid MongoDB ObjectId
if (!mongoose.Types.ObjectId.isValid(category)) {
return res.status(400).json({ error: "Invalid category ID format." });
}

try {
// Find activities that belong to the specified category, with populated category data
const activities = await Activity.find({ category })
.populate("category", "name") // Populate category with only the name field
.populate("tags", "name") // Optional: Populate tags with name field
.populate("creator", "name"); // Optional: Populate creator with name field

if (activities.length === 0) {
return res.status(404).json({ message: "No activities found for this category." });
}

res.status(200).json(activities);
} catch (error) {
console.error("Error fetching activities by category:", error);
res.status(500).json({ error: "Internal server error." });
}
};

module.exports = {
filterActivityGuest,
guestFilterItineraries,
register,
filterHistoricalByTag,
getActivitiesByCategoryForGuest
};
100 changes: 99 additions & 1 deletion src/Routes/touristController.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,75 @@ const Historical = require("../Models/Historical");
const Tourist = require("../Models/Tourist.js");
const TourGuide=require("../Models/TourGuide.js");
const Category = require("../Models/Category.js");

const nodemailer = require("nodemailer");

const Complaint = require("../Models/Complaint.js");

const { default: mongoose } = require("mongoose");


// Function to retrieve activities by category
const getActivitiesByCategory = async (req, res) => {
const { category } = req.query; // Expecting 'category' as a query parameter

if (!category) {
return res.status(400).json({ error: "Category is required for filtering activities." });
}

// Check if the category is a valid MongoDB ObjectId
if (!mongoose.Types.ObjectId.isValid(category)) {
return res.status(400).json({ error: "Invalid category ID format." });
}

try {
// Find activities that belong to the specified category, with populated category data
const activities = await Activity.find({ category })
.populate("category", "name") // Populate category with only the name field
.populate("tags", "name") // Optional: Populate tags with name field
.populate("creator", "name"); // Optional: Populate creator with name field

if (activities.length === 0) {
return res.status(404).json({ message: "No activities found for this category." });
}

res.status(200).json(activities);
} catch (error) {
console.error("Error fetching activities by category:", error);
res.status(500).json({ error: "Internal server error." });
}
};

const generateShareableLink = (itemType, itemId) => {
return `${process.env.BASE_URL}/${itemType}/${itemId}`;
};

// Method to share via copy link or email
const shareItem = async (req, res) => {
const { itemId, itemType } = req.body;

let item;
try {
// Fetch the item based on type and id
if (itemType === "activity") item = await Activity.findById(itemId);
else if (itemType === "itinerary") item = await Itinerary.findById(itemId);
else if (itemType === "historical") item = await Historical.findById(itemId);
else return res.status(400).json({ message: "Invalid item type." });

if (!item) return res.status(404).json({ message: "Item not found." });

// Generate the link
const shareableLink = generateShareableLink(itemType, itemId);

// Return the shareable link
res.status(200).json({ link: shareableLink });
} catch (error) {
res.status(500).json({ message: "Error generating share link", error });
}
};



const createTourist = async (req, res) => {
const { username, password, email, mobile, nationality, dob, job } = req.body;
try {
Expand Down Expand Up @@ -648,6 +714,34 @@ const changePasswordTourist = async (req, res) => {
res.status(500).json({ message: "Error updating password", error });
}
};
// Method to set preferred currency for a tourist
const setPreferredCurrency = async (req, res) => {
const { currency } = req.body; // Expecting 'currency' in the request body
const touristId = req.params.id; // Get the tourist's ID from the request params

if (!currency) {
return res.status(400).json({ error: "Currency is required to set preferred currency." });
}

try {
const tourist = await Tourist.findByIdAndUpdate(
touristId,
{ preferredCurrency: currency }, // Set the preferred currency
{ new: true } // Return the updated document
);

if (!tourist) {
return res.status(404).json({ error: "Tourist not found" });
}

res.status(200).json({ message: "Preferred currency updated successfully", tourist });
} catch (error) {
console.error("Error updating preferred currency:", error);
res.status(500).json({ error: "Internal server error." });
}
};



//Sprint 2 requirements requirement 70 & 71
function calculatePoints(paymentAmount, level) {
Expand Down Expand Up @@ -756,6 +850,8 @@ const redeemMyPoints= async (req, res) =>{


module.exports = {
getActivitiesByCategory,
shareItem,
getProducts,
SortActivities,
getItineraries,
Expand All @@ -780,8 +876,10 @@ module.exports = {
addRatingAndComment,
updateTouristPreferences,
changePasswordTourist,

setPreferredCurrency,

addLoyaltyPoints,
fileComplaint,
viewMyComplaints,
redeemMyPoints,
};
Loading