From 6d0beccea097e1b4afcd57b3b207ce8e998b0c76 Mon Sep 17 00:00:00 2001 From: jackiettran <41605212+jackiettran@users.noreply.github.com> Date: Sat, 1 Nov 2025 22:33:59 -0400 Subject: [PATCH] refactor mylistings and my rentals --- backend/routes/rentals.js | 8 ++++---- backend/services/emailService.js | 12 ++++++------ .../emails/rentalCompletionCongratsToOwner.html | 2 +- backend/tests/unit/routes/rentals.test.js | 12 ++++++------ frontend/src/App.tsx | 12 ++++++------ frontend/src/components/Navbar.tsx | 4 ++-- frontend/src/pages/EarningsDashboard.tsx | 2 +- frontend/src/pages/EditItem.tsx | 2 +- frontend/src/pages/ItemDetail.tsx | 2 +- frontend/src/pages/{MyListings.tsx => Owning.tsx} | 10 +++++----- frontend/src/pages/Profile.tsx | 6 +++--- frontend/src/pages/RentItem.tsx | 2 +- frontend/src/pages/{MyRentals.tsx => Renting.tsx} | 6 +++--- frontend/src/services/api.ts | 4 ++-- 14 files changed, 42 insertions(+), 42 deletions(-) rename frontend/src/pages/{MyListings.tsx => Owning.tsx} (99%) rename frontend/src/pages/{MyRentals.tsx => Renting.tsx} (99%) diff --git a/backend/routes/rentals.js b/backend/routes/rentals.js index c0b0f6f..21825dc 100644 --- a/backend/routes/rentals.js +++ b/backend/routes/rentals.js @@ -53,7 +53,7 @@ const checkAndUpdateReviewVisibility = async (rental) => { return rental; }; -router.get("/my-rentals", authenticateToken, async (req, res) => { +router.get("/renting", authenticateToken, async (req, res) => { try { const rentals = await Rental.findAll({ where: { renterId: req.user.id }, @@ -72,7 +72,7 @@ router.get("/my-rentals", authenticateToken, async (req, res) => { res.json(rentals); } catch (error) { const reqLogger = logger.withRequestId(req.id); - reqLogger.error("Error in my-rentals route", { + reqLogger.error("Error in renting route", { error: error.message, stack: error.stack, userId: req.user.id, @@ -81,7 +81,7 @@ router.get("/my-rentals", authenticateToken, async (req, res) => { } }); -router.get("/my-listings", authenticateToken, async (req, res) => { +router.get("/owning", authenticateToken, async (req, res) => { try { const rentals = await Rental.findAll({ where: { ownerId: req.user.id }, @@ -100,7 +100,7 @@ router.get("/my-listings", authenticateToken, async (req, res) => { res.json(rentals); } catch (error) { const reqLogger = logger.withRequestId(req.id); - reqLogger.error("Error in my-listings route", { + reqLogger.error("Error in owning route", { error: error.message, stack: error.stack, userId: req.user.id, diff --git a/backend/services/emailService.js b/backend/services/emailService.js index 79dfe0f..043806d 100644 --- a/backend/services/emailService.js +++ b/backend/services/emailService.js @@ -442,7 +442,7 @@ class EmailService {

Rental Period: {{startDate}} to {{endDate}}

{{earningsSection}} {{stripeSection}} -

View My Listings

+

View My Listings

` ), @@ -697,7 +697,7 @@ class EmailService { async sendRentalRequestEmail(rental) { const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000"; - const approveUrl = `${frontendUrl}/my-listings?rentalId=${rental.id}`; + const approveUrl = `${frontendUrl}/owning?rentalId=${rental.id}`; // Fetch owner details const owner = await User.findByPk(rental.ownerId, { @@ -754,7 +754,7 @@ class EmailService { async sendRentalRequestConfirmationEmail(rental) { const frontendUrl = process.env.FRONTEND_URL || "http://localhost:3000"; - const viewRentalsUrl = `${frontendUrl}/my-rentals`; + const viewRentalsUrl = `${frontendUrl}/renting`; // Fetch renter details const renter = await User.findByPk(rental.renterId, { @@ -1539,7 +1539,7 @@ class EmailService { paymentMessage: paymentMessage, earningsSection: earningsSection, stripeSection: stripeSection, - rentalDetailsUrl: `${frontendUrl}/my-listings?rentalId=${rental.id}`, + rentalDetailsUrl: `${frontendUrl}/owning?rentalId=${rental.id}`, }; const htmlContent = this.renderTemplate( @@ -1615,7 +1615,7 @@ class EmailService {

- Leave a Review + Leave a Review

`; } else { @@ -1749,7 +1749,7 @@ class EmailService { returnedDate: returnedDate, earningsSection: earningsSection, stripeSection: stripeSection, - myListingsUrl: `${frontendUrl}/my-listings`, + owningUrl: `${frontendUrl}/owning`, }; const ownerHtmlContent = this.renderTemplate( diff --git a/backend/templates/emails/rentalCompletionCongratsToOwner.html b/backend/templates/emails/rentalCompletionCongratsToOwner.html index 99fffbc..b256c65 100644 --- a/backend/templates/emails/rentalCompletionCongratsToOwner.html +++ b/backend/templates/emails/rentalCompletionCongratsToOwner.html @@ -355,7 +355,7 @@

Have more items sitting idle? Turn them into income! List camping gear, tools, party supplies, sports equipment, or anything else that others might need.

- View My Listings + View My Listings

Thank you for being an excellent host on RentAll!

diff --git a/backend/tests/unit/routes/rentals.test.js b/backend/tests/unit/routes/rentals.test.js index 2ee5546..23fa0a7 100644 --- a/backend/tests/unit/routes/rentals.test.js +++ b/backend/tests/unit/routes/rentals.test.js @@ -66,7 +66,7 @@ describe('Rentals Routes', () => { jest.clearAllMocks(); }); - describe('GET /my-rentals', () => { + describe('GET /renting', () => { it('should get rentals for authenticated user', async () => { const mockRentals = [ { @@ -86,7 +86,7 @@ describe('Rentals Routes', () => { mockRentalFindAll.mockResolvedValue(mockRentals); const response = await request(app) - .get('/rentals/my-rentals'); + .get('/rentals/renting'); expect(response.status).toBe(200); expect(response.body).toEqual(mockRentals); @@ -108,14 +108,14 @@ describe('Rentals Routes', () => { mockRentalFindAll.mockRejectedValue(new Error('Database error')); const response = await request(app) - .get('/rentals/my-rentals'); + .get('/rentals/renting'); expect(response.status).toBe(500); expect(response.body).toEqual({ error: 'Failed to fetch rentals' }); }); }); - describe('GET /my-listings', () => { + describe('GET /owning', () => { it('should get listings for authenticated user', async () => { const mockListings = [ { @@ -129,7 +129,7 @@ describe('Rentals Routes', () => { mockRentalFindAll.mockResolvedValue(mockListings); const response = await request(app) - .get('/rentals/my-listings'); + .get('/rentals/owning'); expect(response.status).toBe(200); expect(response.body).toEqual(mockListings); @@ -151,7 +151,7 @@ describe('Rentals Routes', () => { mockRentalFindAll.mockRejectedValue(new Error('Database error')); const response = await request(app) - .get('/rentals/my-listings'); + .get('/rentals/owning'); expect(response.status).toBe(500); expect(response.body).toEqual({ error: 'Failed to fetch listings' }); diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 7aacfb0..b04aab6 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -15,8 +15,8 @@ import ItemDetail from './pages/ItemDetail'; import EditItem from './pages/EditItem'; import RentItem from './pages/RentItem'; import CreateItem from './pages/CreateItem'; -import MyRentals from './pages/MyRentals'; -import MyListings from './pages/MyListings'; +import Renting from './pages/Renting'; +import Owning from './pages/Owning'; import Profile from './pages/Profile'; import PublicProfile from './pages/PublicProfile'; import Messages from './pages/Messages'; @@ -117,18 +117,18 @@ const AppContent: React.FC = () => { } /> - + } /> - + } /> diff --git a/frontend/src/components/Navbar.tsx b/frontend/src/components/Navbar.tsx index 9806609..3382498 100644 --- a/frontend/src/components/Navbar.tsx +++ b/frontend/src/components/Navbar.tsx @@ -194,13 +194,13 @@ const Navbar: React.FC = () => {
  • - + Renting
  • - + Owning {pendingRequestsCount > 0 && ( diff --git a/frontend/src/pages/EarningsDashboard.tsx b/frontend/src/pages/EarningsDashboard.tsx index eefc012..882657f 100644 --- a/frontend/src/pages/EarningsDashboard.tsx +++ b/frontend/src/pages/EarningsDashboard.tsx @@ -36,7 +36,7 @@ const EarningsDashboard: React.FC = () => { const fetchEarningsData = async () => { try { // Get completed rentals where user is the owner - const response = await rentalAPI.getMyListings(); + const response = await rentalAPI.getListings(); const rentals = response.data || []; // Filter for completed rentals with earnings data diff --git a/frontend/src/pages/EditItem.tsx b/frontend/src/pages/EditItem.tsx index ec16813..eef0116 100644 --- a/frontend/src/pages/EditItem.tsx +++ b/frontend/src/pages/EditItem.tsx @@ -173,7 +173,7 @@ const EditItem: React.FC = () => { const fetchAcceptedRentals = async () => { try { - const response = await rentalAPI.getMyListings(); + const response = await rentalAPI.getListings(); const rentals: Rental[] = response.data; // Filter for accepted rentals for this specific item const itemRentals = rentals.filter( diff --git a/frontend/src/pages/ItemDetail.tsx b/frontend/src/pages/ItemDetail.tsx index 2acfe52..dde74ac 100644 --- a/frontend/src/pages/ItemDetail.tsx +++ b/frontend/src/pages/ItemDetail.tsx @@ -48,7 +48,7 @@ const ItemDetail: React.FC = () => { const checkIfAlreadyRenting = async () => { try { - const response = await rentalAPI.getMyRentals(); + const response = await rentalAPI.getRentals(); const rentals: Rental[] = response.data; // Check if user has an active rental for this item const hasActiveRental = rentals.some( diff --git a/frontend/src/pages/MyListings.tsx b/frontend/src/pages/Owning.tsx similarity index 99% rename from frontend/src/pages/MyListings.tsx rename to frontend/src/pages/Owning.tsx index a77a514..080e254 100644 --- a/frontend/src/pages/MyListings.tsx +++ b/frontend/src/pages/Owning.tsx @@ -10,7 +10,7 @@ import DeclineRentalModal from "../components/DeclineRentalModal"; import ConditionCheckModal from "../components/ConditionCheckModal"; import ReturnStatusModal from "../components/ReturnStatusModal"; -const MyListings: React.FC = () => { +const Owning: React.FC = () => { // Helper function to format time const formatTime = (timeString?: string) => { if (!timeString || timeString.trim() === "") return ""; @@ -66,12 +66,12 @@ const MyListings: React.FC = () => { const [rentalForReturn, setRentalForReturn] = useState(null); useEffect(() => { - fetchMyListings(); + fetchListings(); fetchOwnerRentals(); fetchAvailableChecks(); }, [user]); - const fetchMyListings = async () => { + const fetchListings = async () => { if (!user) return; try { @@ -124,7 +124,7 @@ const MyListings: React.FC = () => { const fetchOwnerRentals = async () => { try { - const response = await rentalAPI.getMyListings(); + const response = await rentalAPI.getListings(); setOwnerRentals(response.data); } catch (err: any) { console.error("Failed to fetch owner rentals:", err); @@ -698,4 +698,4 @@ const MyListings: React.FC = () => { ); }; -export default MyListings; +export default Owning; diff --git a/frontend/src/pages/Profile.tsx b/frontend/src/pages/Profile.tsx index 44c8e46..ed82449 100644 --- a/frontend/src/pages/Profile.tsx +++ b/frontend/src/pages/Profile.tsx @@ -155,7 +155,7 @@ const Profile: React.FC = () => { ); // Fetch rentals where user is the owner (rentals on user's items) - const ownerRentalsResponse = await rentalAPI.getMyListings(); + const ownerRentalsResponse = await rentalAPI.getListings(); const ownerRentals: Rental[] = ownerRentalsResponse.data; const acceptedRentals = ownerRentals.filter((r) => @@ -194,14 +194,14 @@ const Profile: React.FC = () => { const fetchRentalHistory = async () => { try { // Fetch past rentals as a renter - const renterResponse = await rentalAPI.getMyRentals(); + const renterResponse = await rentalAPI.getRentals(); const pastRenterRentals = renterResponse.data.filter((r: Rental) => ["completed", "cancelled"].includes(r.status) ); setPastRenterRentals(pastRenterRentals); // Fetch past rentals as an owner - const ownerResponse = await rentalAPI.getMyListings(); + const ownerResponse = await rentalAPI.getListings(); const pastOwnerRentals = ownerResponse.data.filter((r: Rental) => ["completed", "cancelled"].includes(r.status) ); diff --git a/frontend/src/pages/RentItem.tsx b/frontend/src/pages/RentItem.tsx index a4813ba..d4bdc9c 100644 --- a/frontend/src/pages/RentItem.tsx +++ b/frontend/src/pages/RentItem.tsx @@ -223,7 +223,7 @@ const RentItem: React.FC = () => {
    diff --git a/frontend/src/pages/MyRentals.tsx b/frontend/src/pages/Renting.tsx similarity index 99% rename from frontend/src/pages/MyRentals.tsx rename to frontend/src/pages/Renting.tsx index c1ebd7e..b771c89 100644 --- a/frontend/src/pages/MyRentals.tsx +++ b/frontend/src/pages/Renting.tsx @@ -7,7 +7,7 @@ import ReviewItemModal from "../components/ReviewModal"; import RentalCancellationModal from "../components/RentalCancellationModal"; import ConditionCheckModal from "../components/ConditionCheckModal"; -const MyRentals: React.FC = () => { +const Renting: React.FC = () => { // Helper function to format time const formatTime = (timeString?: string) => { if (!timeString || timeString.trim() === "") return ""; @@ -66,7 +66,7 @@ const MyRentals: React.FC = () => { const fetchRentals = async () => { try { - const response = await rentalAPI.getMyRentals(); + const response = await rentalAPI.getRentals(); setRentals(response.data); } catch (err: any) { setError(err.response?.data?.message || "Failed to fetch rentals"); @@ -470,4 +470,4 @@ const MyRentals: React.FC = () => { ); }; -export default MyRentals; +export default Renting; diff --git a/frontend/src/services/api.ts b/frontend/src/services/api.ts index d8c7fe1..b6569af 100644 --- a/frontend/src/services/api.ts +++ b/frontend/src/services/api.ts @@ -203,8 +203,8 @@ export const itemAPI = { export const rentalAPI = { createRental: (data: any) => api.post("/rentals", data), - getMyRentals: () => api.get("/rentals/my-rentals"), - getMyListings: () => api.get("/rentals/my-listings"), + getRentals: () => api.get("/rentals/renting"), + getListings: () => api.get("/rentals/owning"), getPendingRequestsCount: () => api.get("/rentals/pending-requests-count"), updateRentalStatus: (id: string, status: string) => api.put(`/rentals/${id}/status`, { status }),