replaced vague notes with specific intended use, also fixed modal on top of modal for reviews

This commit is contained in:
jackiettran
2025-11-25 16:40:42 -05:00
parent 13268784fd
commit 8de814fdee
16 changed files with 282 additions and 85 deletions

View File

@@ -0,0 +1,210 @@
"use strict";
module.exports = {
up: async (queryInterface, Sequelize) => {
await queryInterface.createTable("Rentals", {
id: {
type: Sequelize.UUID,
defaultValue: Sequelize.UUIDV4,
primaryKey: true,
},
itemId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "Items",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
renterId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "Users",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
ownerId: {
type: Sequelize.UUID,
allowNull: false,
references: {
model: "Users",
key: "id",
},
onUpdate: "CASCADE",
onDelete: "CASCADE",
},
startDateTime: {
type: Sequelize.DATE,
allowNull: false,
},
endDateTime: {
type: Sequelize.DATE,
allowNull: false,
},
totalAmount: {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
},
platformFee: {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
},
payoutAmount: {
type: Sequelize.DECIMAL(10, 2),
allowNull: false,
},
status: {
type: Sequelize.ENUM(
"pending",
"confirmed",
"declined",
"active",
"completed",
"cancelled",
"returned_late",
"returned_late_and_damaged",
"damaged",
"lost"
),
allowNull: false,
},
paymentStatus: {
type: Sequelize.ENUM("pending", "paid", "refunded", "not_required"),
allowNull: false,
},
payoutStatus: {
type: Sequelize.ENUM("pending", "completed", "failed"),
allowNull: true,
},
payoutProcessedAt: {
type: Sequelize.DATE,
},
stripeTransferId: {
type: Sequelize.STRING,
},
refundAmount: {
type: Sequelize.DECIMAL(10, 2),
},
refundProcessedAt: {
type: Sequelize.DATE,
},
refundReason: {
type: Sequelize.TEXT,
},
stripeRefundId: {
type: Sequelize.STRING,
},
cancelledBy: {
type: Sequelize.ENUM("renter", "owner"),
},
cancelledAt: {
type: Sequelize.DATE,
},
declineReason: {
type: Sequelize.TEXT,
},
stripePaymentMethodId: {
type: Sequelize.STRING,
},
stripePaymentIntentId: {
type: Sequelize.STRING,
},
paymentMethodBrand: {
type: Sequelize.STRING,
},
paymentMethodLast4: {
type: Sequelize.STRING,
},
chargedAt: {
type: Sequelize.DATE,
},
deliveryMethod: {
type: Sequelize.ENUM("pickup", "delivery"),
defaultValue: "pickup",
},
deliveryAddress: {
type: Sequelize.TEXT,
},
intendedUse: {
type: Sequelize.TEXT,
},
itemRating: {
type: Sequelize.INTEGER,
},
itemReview: {
type: Sequelize.TEXT,
},
itemReviewSubmittedAt: {
type: Sequelize.DATE,
},
itemReviewVisible: {
type: Sequelize.BOOLEAN,
defaultValue: false,
},
renterRating: {
type: Sequelize.INTEGER,
},
renterReview: {
type: Sequelize.TEXT,
},
renterReviewSubmittedAt: {
type: Sequelize.DATE,
},
renterReviewVisible: {
type: Sequelize.BOOLEAN,
defaultValue: false,
},
itemPrivateMessage: {
type: Sequelize.TEXT,
},
renterPrivateMessage: {
type: Sequelize.TEXT,
},
actualReturnDateTime: {
type: Sequelize.DATE,
},
lateFees: {
type: Sequelize.DECIMAL(10, 2),
defaultValue: 0.0,
},
damageFees: {
type: Sequelize.DECIMAL(10, 2),
defaultValue: 0.0,
},
replacementFees: {
type: Sequelize.DECIMAL(10, 2),
defaultValue: 0.0,
},
itemLostReportedAt: {
type: Sequelize.DATE,
},
damageAssessment: {
type: Sequelize.JSONB,
defaultValue: {},
},
createdAt: {
type: Sequelize.DATE,
allowNull: false,
},
updatedAt: {
type: Sequelize.DATE,
allowNull: false,
},
});
// Add indexes
await queryInterface.addIndex("Rentals", ["itemId"]);
await queryInterface.addIndex("Rentals", ["renterId"]);
await queryInterface.addIndex("Rentals", ["ownerId"]);
await queryInterface.addIndex("Rentals", ["status"]);
},
down: async (queryInterface, Sequelize) => {
await queryInterface.dropTable("Rentals");
},
};

View File

@@ -124,7 +124,7 @@ const Rental = sequelize.define("Rental", {
deliveryAddress: {
type: DataTypes.TEXT,
},
notes: {
intendedUse: {
type: DataTypes.TEXT,
},
// Renter's review of the item (existing fields renamed for clarity)

View File

@@ -183,7 +183,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
endDateTime,
deliveryMethod,
deliveryAddress,
notes,
intendedUse,
stripePaymentMethodId,
} = req.body;
@@ -274,7 +274,7 @@ router.post("/", authenticateToken, requireVerifiedEmail, async (req, res) => {
status: "pending",
deliveryMethod,
deliveryAddress,
notes,
intendedUse,
};
// Only add stripePaymentMethodId if it's provided (for paid rentals)
@@ -1099,7 +1099,7 @@ router.post("/:id/cancel", authenticateToken, async (req, res) => {
// Mark item return status (owner only)
router.post("/:id/mark-return", authenticateToken, async (req, res) => {
try {
const { status, actualReturnDateTime, notes, statusOptions } = req.body;
const { status, actualReturnDateTime, statusOptions } = req.body;
const rentalId = req.params.id;
const userId = req.user.id;
@@ -1133,7 +1133,6 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
status: "completed",
payoutStatus: "pending",
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
notes: notes || null,
});
// Fetch full rental details with associations for email
@@ -1177,15 +1176,13 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
status: "damaged",
payoutStatus: "pending",
actualReturnDateTime: actualReturnDateTime || rental.endDateTime,
notes: notes || null,
};
// Check if ALSO returned late
if (statusOptions?.returned_late && actualReturnDateTime) {
const lateReturnDamaged = await LateReturnService.processLateReturn(
rentalId,
actualReturnDateTime,
notes
actualReturnDateTime
);
damageUpdates.status = "returned_late_and_damaged";
damageUpdates.lateFees = lateReturnDamaged.lateCalculation.lateFee;
@@ -1207,8 +1204,7 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
const lateReturn = await LateReturnService.processLateReturn(
rentalId,
actualReturnDateTime,
notes
actualReturnDateTime
);
updatedRental = lateReturn.rental;
@@ -1221,7 +1217,6 @@ router.post("/:id/mark-return", authenticateToken, async (req, res) => {
status: "lost",
payoutStatus: "pending",
itemLostReportedAt: new Date(),
notes: notes || null,
});
// Send notification to customer service

View File

@@ -303,7 +303,7 @@ class TemplateManager {
<p><strong>Total Amount:</strong> ${{totalAmount}}</p>
<p><strong>Your Earnings:</strong> ${{payoutAmount}}</p>
<p><strong>Delivery Method:</strong> {{deliveryMethod}}</p>
<p><strong>Renter Notes:</strong> {{rentalNotes}}</p>
<p><strong>Intended Use:</strong> {{intendedUse}}</p>
<p><a href="{{approveUrl}}" class="button">Review & Respond</a></p>
<p>Please respond to this request within 24 hours.</p>
`

View File

@@ -53,7 +53,6 @@ class RentalFlowEmailService {
* @param {string} rental.totalAmount - Total rental amount
* @param {string} rental.payoutAmount - Owner's payout amount
* @param {string} rental.deliveryMethod - Delivery method
* @param {string} rental.notes - Rental notes from renter
* @returns {Promise<{success: boolean, messageId?: string, error?: string}>}
*/
async sendRentalRequestEmail(owner, renter, rental) {
@@ -88,7 +87,7 @@ class RentalFlowEmailService {
? parseFloat(rental.payoutAmount).toFixed(2)
: "0.00",
deliveryMethod: rental.deliveryMethod || "Not specified",
rentalNotes: rental.notes || "No additional notes provided",
intendedUse: rental.intendedUse || "Not specified",
approveUrl: approveUrl,
};

View File

@@ -60,10 +60,9 @@ class LateReturnService {
* Process late return and update rental with fees
* @param {string} rentalId - Rental ID
* @param {Date} actualReturnDateTime - When item was returned
* @param {string} notes - Optional notes about the return
* @returns {Object} - Updated rental with late fee information
*/
static async processLateReturn(rentalId, actualReturnDateTime, notes = null) {
static async processLateReturn(rentalId, actualReturnDateTime) {
const rental = await Rental.findByPk(rentalId, {
include: [{ model: Item, as: "item" }],
});
@@ -84,10 +83,6 @@ class LateReturnService {
payoutStatus: "pending",
};
if (notes) {
updates.notes = notes;
}
const updatedRental = await rental.update(updates);
// Send notification to customer service if late return detected

View File

@@ -295,8 +295,8 @@
</table>
<div class="info-box">
<p><strong>Renter's Notes:</strong></p>
<p>{{rentalNotes}}</p>
<p><strong>Intended Use:</strong></p>
<p>{{intendedUse}}</p>
</div>
<div style="text-align: center">

View File

@@ -289,7 +289,6 @@ describe('Rentals Routes', () => {
endDateTime: '2024-01-15T18:00:00.000Z',
deliveryMethod: 'pickup',
deliveryAddress: null,
notes: 'Test rental',
stripePaymentMethodId: 'pm_test123',
};

View File

@@ -449,7 +449,6 @@ describe('EmailService', () => {
totalAmount: 150.00,
payoutAmount: 135.00,
deliveryMethod: 'pickup',
notes: 'Please have it ready by 9am',
item: { name: 'Power Drill' }
};
@@ -522,7 +521,6 @@ describe('EmailService', () => {
totalAmount: 0,
payoutAmount: 0,
deliveryMethod: 'pickup',
notes: null,
item: { name: 'Free Item' }
};
@@ -531,39 +529,6 @@ describe('EmailService', () => {
expect(result.success).toBe(true);
});
it('should handle missing rental notes', async () => {
const mockOwner = {
email: 'owner@example.com',
firstName: 'John'
};
const mockRenter = {
firstName: 'Jane',
lastName: 'Doe'
};
User.findByPk
.mockResolvedValueOnce(mockOwner)
.mockResolvedValueOnce(mockRenter);
const rental = {
id: 1,
ownerId: 10,
renterId: 20,
startDateTime: new Date('2024-12-01T10:00:00Z'),
endDateTime: new Date('2024-12-03T10:00:00Z'),
totalAmount: 100,
payoutAmount: 90,
deliveryMethod: 'delivery',
notes: null, // No notes
item: { name: 'Test Item' }
};
const result = await emailService.sendRentalRequestEmail(rental);
expect(result.success).toBe(true);
expect(mockSend).toHaveBeenCalled();
});
it('should generate correct approval URL', async () => {
const mockOwner = {
email: 'owner@example.com',
@@ -589,7 +554,6 @@ describe('EmailService', () => {
totalAmount: 100,
payoutAmount: 90,
deliveryMethod: 'pickup',
notes: 'Test notes',
item: { name: 'Test Item' }
};