Skip to content

Commit

Permalink
Add admin dash components
Browse files Browse the repository at this point in the history
  • Loading branch information
haseebzaki-07 committed Nov 9, 2024
1 parent 8e39dfc commit 393e744
Show file tree
Hide file tree
Showing 7 changed files with 571 additions and 325 deletions.
114 changes: 57 additions & 57 deletions backend/model/rent/rentProduct.js
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);
Loading

0 comments on commit 393e744

Please sign in to comment.