-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e39dfc
commit 393e744
Showing
7 changed files
with
571 additions
and
325 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,71 @@ | ||
const mongoose = require('mongoose'); | ||
const mongoose = require('mongoose'); | ||
|
||
const reviewSchema = new mongoose.Schema({ | ||
rentalId: String, | ||
rating: { type: Number, required: true, min: 0, max: 5 }, | ||
comment: String, | ||
}); | ||
const reviewSchema = new mongoose.Schema({ | ||
rentalId: String, | ||
rating: { type: Number, required: true, min: 0, max: 5 }, | ||
comment: String, | ||
}); | ||
|
||
const rentProductSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
price: { type: Number, required: true }, // Base price for the product (purchase price) | ||
image: { type: String, required: true }, | ||
category: { type: [String], required: true }, | ||
const rentProductSchema = new mongoose.Schema({ | ||
name: { type: String, required: true }, | ||
description: { type: String, required: true }, | ||
price: { type: Number, required: true }, // Base price for the product (purchase price) | ||
image: { type: String, required: true }, | ||
category: { type: [String], required: true }, | ||
|
||
|
||
|
||
availabilityStatus: { | ||
type: String, | ||
enum: ['available', 'rented', 'maintenance'], | ||
default: 'available', | ||
}, | ||
|
||
rentalPricePerDay: { | ||
type: Number, | ||
required: true, | ||
min: 0, // Minimum daily rental price | ||
}, | ||
availabilityStatus: { | ||
type: String, | ||
enum: ['available', 'rented', 'maintenance'], | ||
default: 'available', | ||
}, | ||
|
||
rentalPricePerDay: { | ||
type: Number, | ||
required: true, | ||
min: 0, // Minimum daily rental price | ||
}, | ||
|
||
rentalDurationOptions: { | ||
type: [String], | ||
required: true, | ||
enum: ['hourly', 'daily', 'weekly', 'monthly'], | ||
}, // Available rental durations | ||
rentalDurationOptions: { | ||
type: [String], | ||
required: true, | ||
enum: ['hourly', 'daily', 'weekly', 'monthly'], | ||
}, // Available rental durations | ||
|
||
maxRentalDuration: { | ||
type: Number, | ||
required: true, | ||
min: 1, // Minimum rental period (e.g., in days, weeks, etc.) | ||
}, | ||
maxRentalDuration: { | ||
type: Number, | ||
required: true, | ||
min: 1, // Minimum rental period (e.g., in days, weeks, etc.) | ||
}, | ||
|
||
depositAmount: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
depositAmount: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
|
||
rentalTerms: { | ||
type: String, | ||
maxlength: 500, | ||
}, | ||
rentalTerms: { | ||
type: String, | ||
maxlength: 500, | ||
}, | ||
|
||
rentedQuantity: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
rentedQuantity: { | ||
type: Number, | ||
default: 0, | ||
}, | ||
|
||
|
||
reviews: [reviewSchema], | ||
reviews: [reviewSchema], | ||
|
||
|
||
rating: { type: Number, default: 0, min: 0, max: 5 }, | ||
}, { timestamps: true }); | ||
rating: { type: Number, default: 0, min: 0, max: 5 }, | ||
}, { timestamps: true }); | ||
|
||
// Method to update product rating based on reviews | ||
rentProductSchema.methods.updateProductRating = function() { | ||
const totalRating = this.reviews.reduce((sum, review) => sum + review.rating, 0); | ||
const averageRating = this.reviews.length ? totalRating / this.reviews.length : 0; | ||
this.rating = averageRating; | ||
return this.save(); | ||
}; | ||
// Method to update product rating based on reviews | ||
rentProductSchema.methods.updateProductRating = function() { | ||
const totalRating = this.reviews.reduce((sum, review) => sum + review.rating, 0); | ||
const averageRating = this.reviews.length ? totalRating / this.reviews.length : 0; | ||
this.rating = averageRating; | ||
return this.save(); | ||
}; | ||
|
||
module.exports = mongoose.models.RentProduct || mongoose.model('RentProduct', rentProductSchema); | ||
module.exports = mongoose.models.RentProduct || mongoose.model('RentProduct', rentProductSchema); |
Oops, something went wrong.