refactor mylistings and my rentals

This commit is contained in:
jackiettran
2025-11-01 22:33:59 -04:00
parent 16272ba373
commit 6d0beccea0
14 changed files with 42 additions and 42 deletions

View File

@@ -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,

View File

@@ -442,7 +442,7 @@ class EmailService {
<p><strong>Rental Period:</strong> {{startDate}} to {{endDate}}</p>
{{earningsSection}}
{{stripeSection}}
<p><a href="{{myListingsUrl}}" class="button">View My Listings</a></p>
<p><a href="{{owningUrl}}" class="button">View My Listings</a></p>
`
),
@@ -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 {
</ul>
</div>
<p style="text-align: center;">
<a href="${frontendUrl}/my-rentals?rentalId=${rental.id}&action=review" class="button">Leave a Review</a>
<a href="${frontendUrl}/renting?rentalId=${rental.id}&action=review" class="button">Leave a Review</a>
</p>
`;
} else {
@@ -1749,7 +1749,7 @@ class EmailService {
returnedDate: returnedDate,
earningsSection: earningsSection,
stripeSection: stripeSection,
myListingsUrl: `${frontendUrl}/my-listings`,
owningUrl: `${frontendUrl}/owning`,
};
const ownerHtmlContent = this.renderTemplate(

View File

@@ -355,7 +355,7 @@
<p>Have more items sitting idle? Turn them into income! List camping gear, tools, party supplies, sports equipment, or anything else that others might need.</p>
<p style="text-align: center;">
<a href="{{myListingsUrl}}" class="button">View My Listings</a>
<a href="{{owningUrl}}" class="button">View My Listings</a>
</p>
<p>Thank you for being an excellent host on RentAll!</p>

View File

@@ -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' });