-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added more details to product schema backend
Added image path, stock count, category, franchise, rating to product Created new document schema for product reviews #14
- Loading branch information
Showing
3 changed files
with
63 additions
and
10 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,18 +1,28 @@ | ||
import mongoose, { Schema, Document, ObjectId } from "mongoose"; | ||
import mongoose, { Document, ObjectId, Schema } from "mongoose"; | ||
|
||
// TypeScript interface for the User model | ||
interface Product extends Document { | ||
name: string; | ||
price: string; | ||
price: number; | ||
description: string; | ||
_id?: ObjectId; | ||
imgPath?: string; | ||
stockCount?: number; | ||
category: string; | ||
franchise: string; | ||
rating: string; | ||
} | ||
|
||
// Mongoose schema for the Product model | ||
const ProductSchema: Schema<Product> = new Schema({ | ||
name: { type: String, required: true }, | ||
price: { type: String, required: true }, | ||
price: { type: Number, required: true }, | ||
description: { type: String, required: true }, | ||
imgPath: { type: String }, | ||
stockCount: { type: Number, default: 0 }, | ||
category: { type: String, required: true }, | ||
franchise: { type: String, required: true }, | ||
rating: { type: String }, | ||
}); | ||
|
||
export default mongoose.model<Product>("Product", ProductSchema); |
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import mongoose, { ObjectId, Schema } from "mongoose"; | ||
|
||
interface Review { | ||
productId: ObjectId; | ||
review: string; | ||
reviewer: string; | ||
stars: number; | ||
_id?: ObjectId; | ||
} | ||
|
||
// Mongoose schema for the Product model | ||
const ReviewSchema: Schema<Review> = new Schema({ | ||
review: { type: String, required: true }, | ||
reviewer: { type: String, required: true }, | ||
stars: { type: Number, required: true }, | ||
}); | ||
|
||
export default mongoose.model<Review>("Product", ReviewSchema); |
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