| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- import mongoose, {
- Document,
- Schema
- } from "mongoose";
- export interface IProduct extends Document {
- categoryIDs: mongoose.Types.ObjectId[];
- userID: mongoose.Types.ObjectId;
- photos: {
- coverPhotoPath: string;
- isPrimary: boolean;
- }[];
- isAvailable: boolean;
- description: string;
- isActive: boolean;
- title: string;
- price: number;
- }
- const productSchema = new Schema<IProduct>(
- {
- categoryIDs: {
- type: [mongoose.Schema.Types.ObjectId],
- index: true,
- default: []
- },
- userID: {
- type: mongoose.Schema.Types.ObjectId,
- index: true
- },
- title: {
- type: String,
- required: true,
- trim: true
- },
- description: {
- type: String,
- default: "",
- trim: true
- },
- price: {
- type: Number,
- required: true,
- min: 0
- },
- photos: [
- {
- coverPhotoPath: {
- type: String
- },
- isPrimary: {
- type: Boolean,
- default: false
- },
- _id: false
- }
- ],
- isActive: {
- type: Boolean,
- default: true
- },
- isAvailable: {
- type: Boolean,
- default: true
- },
- },
- {
- timestamps: true,
- }
- );
- export const Product = mongoose.models.Product || mongoose.model<IProduct>("Product", productSchema);
|